MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / bdb_query

Function bdb_query

modules/db_berkeley/db_berkeley.c:362–633  ·  view source on GitHub ↗

* Query table for specified rows * _con: structure representing database connection * _k: key names * _op: operators * _v: values of the keys that must match * _c: column names to return * _n: number of key=values pairs to compare * _nc: number of columns to return * _o: order by the specified column */

Source from the content-addressed store, hash-verified

360 * _o: order by the specified column
361 */
362int bdb_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
363 db_key_t* _c, int _n, int _nc, db_key_t _o, db_res_t** _r)
364{
365 tbl_cache_p _tbc = NULL;
366 table_p _tp = NULL;
367 char kbuf[MAX_ROW_SIZE];
368 char dbuf[MAX_ROW_SIZE];
369 u_int32_t i;
370 int ret;
371 int klen=MAX_ROW_SIZE;
372 int *lkey=NULL, *lres=NULL;
373 DBT key, data;
374 DB *db;
375 DBC *dbcp;
376
377 if ((!_con) || (!_r) || !CON_TABLE(_con))
378 {
379#ifdef BDB_EXTRA_DEBUG
380 LM_ERR("Invalid parameter value\n");
381#endif
382 return -1;
383 }
384 *_r = NULL;
385
386 /*check if underlying DB file has changed inode */
387 if(auto_reload)
388 bdb_check_reload(_con);
389
390 _tbc = bdblib_get_table(BDB_CON_CONNECTION(_con), (str*)CON_TABLE(_con));
391 if(!_tbc)
392 { LM_WARN("table does not exist!\n");
393 return -1;
394 }
395
396 _tp = _tbc->dtp;
397 if(!_tp)
398 { LM_WARN("table not loaded!\n");
399 return -1;
400 }
401
402#ifdef BDB_EXTRA_DEBUG
403 LM_DBG("QUERY in %.*s\n", _tp->name.len, _tp->name.s);
404
405 if (_o) LM_DBG("DONT-CARE : _o: order by the specified column \n");
406 if (_op) LM_DBG("DONT-CARE : _op: operators for refining query \n");
407#endif
408
409 db = _tp->db;
410 if(!db) return -1;
411
412 memset(&key, 0, sizeof(DBT));
413 memset(kbuf, 0, MAX_ROW_SIZE);
414 memset(&data, 0, sizeof(DBT));
415 memset(dbuf, 0, MAX_ROW_SIZE);
416
417 data.data = dbuf;
418 data.ulen = MAX_ROW_SIZE;
419 data.flags = DB_DBT_USERMEM;

Callers

nothing calls this directly

Calls 11

bdb_check_reloadFunction · 0.85
bdblib_get_tableFunction · 0.85
bdb_get_colmapFunction · 0.85
db_new_resultFunction · 0.85
bdb_get_columnsFunction · 0.85
db_allocate_rowsFunction · 0.85
bdb_append_rowFunction · 0.85
bdblib_valtocharFunction · 0.85
bdb_convert_rowFunction · 0.85
bdblib_recoverFunction · 0.85
db_free_resultFunction · 0.85

Tested by

no test coverage detected