Skip to content

Commit

Permalink
db_redis: handle DB1_UINT and DB1_UBIGINT DB APIv1 types
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Sep 28, 2018
1 parent fd023a9 commit c66bb0b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/modules/db_redis/redis_dbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,27 @@ static int db_redis_val2str(const db_val_t *v, str *_str) {
snprintf(_str->s, _str->len, "%d", VAL_INT(v));
_str->len = strlen(_str->s);
break;
case DB1_UINT:
LM_DBG("converting uint value %u to str\n", VAL_UINT(v));
_str->s = (char*)pkg_malloc(_str->len);
if (!_str->s) goto memerr;
snprintf(_str->s, _str->len, "%u", VAL_UINT(v));
_str->len = strlen(_str->s);
break;
case DB1_BIGINT:
LM_DBG("converting bigint value %lld to str\n", VAL_BIGINT(v));
_str->s = (char*)pkg_malloc(_str->len);
if (!_str->s) goto memerr;
snprintf(_str->s, _str->len, "%lld", VAL_BIGINT(v));
_str->len = strlen(_str->s);
break;
case DB1_UBIGINT:
LM_DBG("converting ubigint value %llu to str\n", VAL_UBIGINT(v));
_str->s = (char*)pkg_malloc(_str->len);
if (!_str->s) goto memerr;
snprintf(_str->s, _str->len, "%llu", VAL_UBIGINT(v));
_str->len = strlen(_str->s);
break;
case DB1_STRING:
s = VAL_STRING(v);
_str->len = strlen(s);
Expand Down
16 changes: 15 additions & 1 deletion src/modules/db_redis/redis_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ static struct str_hash_entry* db_redis_create_column(str *col, str *type) {
case 'I':
e->u.n = DB1_INT;
break;
case 'u':
case 'U':
/* uint and ubigint */
if(type->len>1 && (type->s[1]=='b' || type->s[1]=='B')) {
e->u.n = DB1_UBIGINT;
} else {
e->u.n = DB1_UINT;
}
break;
case 't':
case 'T':
e->u.n = DB1_DATETIME;
Expand All @@ -458,7 +467,12 @@ static struct str_hash_entry* db_redis_create_column(str *col, str *type) {
break;
case 'b':
case 'B':
e->u.n = DB1_BLOB;
/* blob and bigint */
if(type->len>1 && (type->s[1]=='i' || type->s[1]=='I')) {
e->u.n = DB1_BIGINT;
} else {
e->u.n = DB1_BLOB;
}
break;
default:
LM_ERR("Invalid schema column type '%.*s', expecting one of string, int, timestamp, double, blob\n",
Expand Down

0 comments on commit c66bb0b

Please sign in to comment.