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

Function bdb_update

modules/db_berkeley/db_berkeley.c:1052–1296  ·  view source on GitHub ↗

* Updates a row in table * Limitation: only knows how to update a single row * * _con: structure representing database connection * _k: key names * _op: operators * _v: values of the keys that must match * _uk: update keys; cols that need to be updated * _uv: update values; col values that need to be commited * _un: number of rows to update */

Source from the content-addressed store, hash-verified

1050 * _un: number of rows to update
1051 */
1052int bdb_update(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
1053 db_key_t* _uk, db_val_t* _uv, int _n, int _un)
1054{
1055 char *c, *t;
1056 int ret, i, qcol, len, sum;
1057 int *lkey=NULL;
1058 tbl_cache_p _tbc = NULL;
1059 table_p _tp = NULL;
1060 char kbuf[MAX_ROW_SIZE];
1061 char qbuf[MAX_ROW_SIZE];
1062 char ubuf[MAX_ROW_SIZE + 1]; /* NULL terminated */
1063 char * tmp;
1064 DBT key, qdata, udata;
1065 DB *db;
1066
1067 sum = ret = i = qcol = len = 0;
1068
1069 if (!_con || !CON_TABLE(_con) || !_uk || !_uv || _un <= 0)
1070 return -1;
1071
1072 _tbc = bdblib_get_table(BDB_CON_CONNECTION(_con), (str*)CON_TABLE(_con));
1073 if(!_tbc)
1074 { LM_ERR("table does not exist\n");
1075 return -1;
1076 }
1077
1078 _tp = _tbc->dtp;
1079 if(!_tp)
1080 { LM_ERR("table not loaded\n");
1081 return -1;
1082 }
1083
1084 db = _tp->db;
1085 if(!db)
1086 { LM_ERR("DB null ptr\n");
1087 return -1;
1088 }
1089
1090#ifdef BDB_EXTRA_DEBUG
1091 LM_DBG("UPDATE in %.*s\n", _tp->name.len, _tp->name.s);
1092 if (_op) LM_DBG("DONT-CARE : _op: operators for refining query \n");
1093#endif
1094
1095 memset(&key, 0, sizeof(DBT));
1096 memset(kbuf, 0, MAX_ROW_SIZE);
1097 memset(&qdata, 0, sizeof(DBT));
1098 memset(qbuf, 0, MAX_ROW_SIZE);
1099
1100 qdata.data = qbuf;
1101 qdata.ulen = MAX_ROW_SIZE;
1102 qdata.flags = DB_DBT_USERMEM;
1103
1104 if(_k)
1105 { lkey = bdb_get_colmap(_tbc->dtp, _k, _n);
1106 if(!lkey) return -4;
1107 }
1108 else
1109 {

Callers

nothing calls this directly

Calls 6

bdblib_get_tableFunction · 0.85
bdb_get_colmapFunction · 0.85
bdblib_valtocharFunction · 0.85
bdb_val2strFunction · 0.85
bdblib_logFunction · 0.85
bdblib_recoverFunction · 0.85

Tested by

no test coverage detected