On Mon, 29 Oct 2012 16:07:56 +0200 Timo Teras <timo.te...@iki.fi> wrote:
> I guess we should first try decltype if available and fall back to > first row column type. However, this will fail too if the first row > has NULL value for the column. > > The fundamental problem is that Kamailio DB API expects the driver to > return stored type - which on sqlite is not fixed. > > Will try to get something sketched up soonish. Can you try the attached patch if it fixes it? I compile tested it only, but I believe this is the proper thing to do. Thanks, Timo
diff --git a/modules_k/db_sqlite/dbase.c b/modules_k/db_sqlite/dbase.c index c1d3b71..c4df4ce 100644 --- a/modules_k/db_sqlite/dbase.c +++ b/modules_k/db_sqlite/dbase.c @@ -288,6 +288,24 @@ static int decltype_to_dbtype(const char *decltype) return DB1_INT; } +static int type_to_dbtype(int type) +{ + switch (type) { + case SQLITE_INTEGER: + return DB1_INT; + case SQLITE_FLOAT: + return DB1_DOUBLE; + case SQLITE_TEXT: + return DB1_STR; + case SQLITE_BLOB: + return DB1_BLOB; + default: + /* Unknown, or NULL column value. Assume this is a + * string. */ + return DB1_STR; + } +} + static str* str_dup(const char *_s) { str *s; @@ -348,10 +366,18 @@ int db_sqlite_store_result(const db1_con_t* _h, db1_res_t** _r) RES_COL_N(res) = rc; for (i = 0; i < RES_COL_N(res); i++) { + const char *decltype; + int dbtype; + RES_NAMES(res)[i] = str_dup(sqlite3_column_name(conn->stmt, i)); if (RES_NAMES(res)[i] == NULL) goto no_mem; - RES_TYPES(res)[i] = decltype_to_dbtype(sqlite3_column_decltype(conn->stmt, i)); + decltype = sqlite3_column_decltype(conn->stmt, i); + if (decltype != NULL) + dbtype = decltype_to_dbtype(decltype); + else + dbtype = type_to_dbtype(sqlite3_column_type(conn->stmt, i)); + RES_TYPES(res)[i] = dbtype; } } if (num_rows >= num_alloc) {
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users