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

Function _bdb_delete_cursor

modules/db_berkeley/db_berkeley.c:912–1038  ·  view source on GitHub ↗

_bdb_delete_cursor -- called from bdb_delete when the query involves operators other than equal '='. Adds support for queries like this: DELETE from SomeTable WHERE _k[0] < _v[0] In this case, the keys _k are not the actually schema keys, so we need to iterate via cursor to perform this operation. */

Source from the content-addressed store, hash-verified

910 iterate via cursor to perform this operation.
911*/
912int _bdb_delete_cursor(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n)
913{
914 tbl_cache_p _tbc = NULL;
915 table_p _tp = NULL;
916 db_res_t* _r = NULL;
917 char kbuf[MAX_ROW_SIZE];
918 char dbuf[MAX_ROW_SIZE];
919 int ret, klen=MAX_ROW_SIZE;
920 DBT key, data;
921 DB *db;
922 DBC *dbcp = NULL;
923 int *lkey=NULL;
924
925 ret = 0;
926
927 if ((!_h) || !CON_TABLE(_h))
928 return -1;
929
930 _tbc = bdblib_get_table(BDB_CON_CONNECTION(_h), (str*)CON_TABLE(_h));
931 if(!_tbc)
932 { LM_WARN("table does not exist!\n");
933 return -3;
934 }
935
936 _tp = _tbc->dtp;
937 if(!_tp)
938 { LM_WARN("table not loaded!\n");
939 return -4;
940 }
941
942#ifdef BDB_EXTRA_DEBUG
943 LM_DBG("DELETE by cursor in %.*s\n", _tp->name.len, _tp->name.s );
944#endif
945
946 if(_k)
947 { lkey = bdb_get_colmap(_tp, _k, _n);
948 if(!lkey)
949 { ret = -1;
950 goto error;
951 }
952 }
953
954 /* create an empty db_res_t which gets returned even if no result */
955 _r = db_new_result();
956 if (!_r)
957 { LM_ERR("no memory for result \n");
958 }
959
960 RES_ROW_N(_r) = 0;
961
962 /* fill in the col part of db_res_t */
963 if ((ret = bdb_get_columns(_tp, _r, 0, 0)) != 0)
964 { LM_ERR("Error while getting column names\n");
965 goto error;
966 }
967
968 db = _tp->db;
969 memset(&key, 0, sizeof(DBT));

Callers 1

bdb_deleteFunction · 0.85

Calls 10

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_convert_rowFunction · 0.85
bdb_row_matchFunction · 0.85
bdblib_recoverFunction · 0.85
db_free_rowsFunction · 0.85
db_free_resultFunction · 0.85

Tested by

no test coverage detected