Module: kamailio Branch: master Commit: d0ac74742f6aeb71492d2a9cab747162cdc5ddf8 URL: https://github.com/kamailio/kamailio/commit/d0ac74742f6aeb71492d2a9cab747162...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2017-07-13T09:03:54+02:00
lib/srdb1: db_table_version() can handle DB1_BIGINT and DB1_DOUBLE values
- in case of views or other database engine, the type for version value can be different that DB1_INT. If it is a number, cast it to int - extracted from GH #1186 by Emmanuel Schmidbauer emmanuel@getweave.com
---
Modified: src/lib/srdb1/db.c
---
Diff: https://github.com/kamailio/kamailio/commit/d0ac74742f6aeb71492d2a9cab747162... Patch: https://github.com/kamailio/kamailio/commit/d0ac74742f6aeb71492d2a9cab747162...
---
diff --git a/src/lib/srdb1/db.c b/src/lib/srdb1/db.c index e8ddd377a5..c3908af85d 100644 --- a/src/lib/srdb1/db.c +++ b/src/lib/srdb1/db.c @@ -374,7 +374,8 @@ int db_table_version(const db_func_t* dbf, db1_con_t* connection, const str* tab str *version = &version_table; str tmp1 = str_init(TABLENAME_COLUMN); str tmp2 = str_init(VERSION_COLUMN); - int ret; + int ret = 0; + int val_type;
if (!dbf||!connection || !table || !table->s) { LM_CRIT("invalid parameter value\n"); @@ -412,7 +413,9 @@ int db_table_version(const db_func_t* dbf, db1_con_t* connection, const str* tab }
ver = ROW_VALUES(RES_ROWS(res)); - if ( VAL_TYPE(ver)!=DB1_INT || VAL_NULL(ver) ) { + val_type = VAL_TYPE(ver); + if ( (val_type!=DB1_INT && val_type!=DB1_DOUBLE && val_type!=DB1_BIGINT) + || VAL_NULL(ver) ) { LM_ERR("invalid type (%d) or nul (%d) version " "columns for %.*s\n", VAL_TYPE(ver), VAL_NULL(ver), table->len, ZSW(table->s)); @@ -420,8 +423,16 @@ int db_table_version(const db_func_t* dbf, db1_con_t* connection, const str* tab return -1; }
- ret = VAL_INT(ver); + if (val_type == DB1_INT) { + ret = VAL_INT(ver); + } else if (val_type == DB1_BIGINT) { + ret = (int)VAL_BIGINT(ver); + } else if (val_type == DB1_DOUBLE) { + ret = (int)VAL_DOUBLE(ver); + } + dbf->free_result(connection, res); + return ret; }