Skip to content

Commit

Permalink
sql_cacher: handle double as str (just live avp_db_query)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovidiusas committed Feb 26, 2024
1 parent 4881b95 commit a3d83c2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions modules/sql_cacher/sql_cacher.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,13 @@ static int get_column_types(cache_entry_t *c_entry, db_val_t *values, int nr_col
switch (val_type) {
case DB_INT:
case DB_BIGINT:
case DB_DOUBLE:
c_entry->nr_ints++;
c_entry->column_types &= ~(1LL << i);
break;
case DB_STRING:
case DB_STR:
case DB_BLOB:
case DB_DOUBLE:
c_entry->nr_strs++;
c_entry->column_types |= (1LL << i);
break;
Expand Down Expand Up @@ -516,13 +516,13 @@ static int build_column_types(cache_entry_t *c_entry, db_key_t *names, db_type_t
switch (val_type) {
case DB_INT:
case DB_BIGINT:
case DB_DOUBLE:
c_entry->nr_ints++;
c_entry->column_types &= ~(1LL << i);
break;
case DB_STRING:
case DB_STR:
case DB_BLOB:
case DB_DOUBLE:
c_entry->nr_strs++;
c_entry->column_types |= (1LL << i);
break;
Expand Down Expand Up @@ -604,9 +604,6 @@ static int insert_in_cachedb(cache_entry_t *c_entry, db_handlers_t *db_hdls,
case DB_BIGINT:
int_val = (int)VAL_BIGINT(values + i);
break;
case DB_DOUBLE:
int_val = (int)VAL_DOUBLE(values + i);
break;
default: continue;
}
if (VAL_NULL(values + i))
Expand Down Expand Up @@ -637,6 +634,11 @@ static int insert_in_cachedb(cache_entry_t *c_entry, db_handlers_t *db_hdls,
case DB_BLOB:
str_val = VAL_BLOB(values + i);
break;
case DB_DOUBLE:
str_val.s = double2str(VAL_DOUBLE(values + i), &str_val.len);
cdb_val.len += str_val.len;
cdb_val.s = pkg_realloc(cdb_val.s, cdb_val.len);
break;
default: continue;
}
if (VAL_NULL(values + i))
Expand Down Expand Up @@ -1752,7 +1754,12 @@ static int on_demand_load(pv_name_fix_t *pv_name, str *str_res, int *int_res,
*int_res = (int)VAL_BIGINT(values + pv_name->col_nr);
break;
case DB_DOUBLE:
*int_res = (int)VAL_DOUBLE(values + pv_name->col_nr);
st.s = double2str(VAL_DOUBLE(values + pv_name->col_nr), &st.len);
if (pkg_str_dup(str_res, &st) != 0) {
LM_ERR("oom\n");
rc = -1;
goto out_free_res;
}
break;
default:
LM_ERR("Unsupported type for SQL column\n");
Expand Down

0 comments on commit a3d83c2

Please sign in to comment.