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

Function db_table_version

db/db.c:396–462  ·  view source on GitHub ↗

* Get version of a table * If there is no row for the given table, return version 0 */

Source from the content-addressed store, hash-verified

394 * If there is no row for the given table, return version 0
395 */
396int db_table_version(const db_func_t* dbf, db_con_t* connection, const str* table)
397{
398 db_key_t key[1], col[1];
399 db_val_t val[1];
400 db_res_t* res = NULL;
401 db_val_t* ver = 0;
402 str version;
403 int ret;
404
405
406 if (!dbf||!connection || !table || !table->s) {
407 LM_CRIT("invalid parameter value\n");
408 return -1;
409 }
410
411 version.s = db_version_table;
412 version.len = strlen(version.s);
413
414 if (dbf->use_table(connection, &version) < 0) {
415 LM_ERR("error while changing table\n");
416 return -1;
417 }
418 str tmp1 = str_init(TABLENAME_COLUMN);
419 key[0] = &tmp1;
420
421 VAL_TYPE(val) = DB_STR;
422 VAL_NULL(val) = 0;
423 VAL_STR(val) = *table;
424
425 str tmp2 = str_init(VERSION_COLUMN);
426 col[0] = &tmp2;
427
428 if (dbf->query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
429 LM_ERR("error in db_query\n");
430 return -1;
431 }
432
433 if (RES_ROW_N(res) == 0) {
434 LM_DBG("no row for table %.*s found\n",
435 table->len, ZSW(table->s));
436 return -2;
437 }
438
439 if (RES_ROW_N(res) != 1) {
440 LM_ERR("invalid number of rows received:"
441 " %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
442 dbf->free_result(connection, res);
443 return -1;
444 }
445
446 ver = ROW_VALUES(RES_ROWS(res));
447 if ((VAL_TYPE(ver)!=DB_INT && VAL_TYPE(ver)!=DB_BIGINT) || VAL_NULL(ver)) {
448 LM_ERR("invalid type (%d) or nul (%d) version "
449 "columns for %.*s\n", VAL_TYPE(ver), VAL_NULL(ver),
450 table->len, ZSW(table->s));
451 dbf->free_result(connection, res);
452 return -1;
453 }

Callers 3

frd_init_dbFunction · 0.85
domainpolicy_db_verFunction · 0.85
db_check_table_versionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected