Browse code

db_redis: handle DB1_UINT and DB1_UBIGINT DB APIv1 types

Daniel-Constantin Mierla authored on 28/09/2018 13:22:03
Showing 2 changed files
... ...
@@ -96,6 +96,13 @@ static int db_redis_val2str(const db_val_t *v, str *_str) {
96 96
             snprintf(_str->s, _str->len, "%d", VAL_INT(v));
97 97
             _str->len = strlen(_str->s);
98 98
             break;
99
+       case DB1_UINT:
100
+            LM_DBG("converting uint value %u to str\n", VAL_UINT(v));
101
+            _str->s = (char*)pkg_malloc(_str->len);
102
+            if (!_str->s) goto memerr;
103
+            snprintf(_str->s, _str->len, "%u", VAL_UINT(v));
104
+            _str->len = strlen(_str->s);
105
+            break;
99 106
         case DB1_BIGINT:
100 107
             LM_DBG("converting bigint value %lld to str\n", VAL_BIGINT(v));
101 108
             _str->s = (char*)pkg_malloc(_str->len);
... ...
@@ -103,6 +110,13 @@ static int db_redis_val2str(const db_val_t *v, str *_str) {
103 110
             snprintf(_str->s, _str->len, "%lld", VAL_BIGINT(v));
104 111
             _str->len = strlen(_str->s);
105 112
             break;
113
+        case DB1_UBIGINT:
114
+            LM_DBG("converting ubigint value %llu to str\n", VAL_UBIGINT(v));
115
+            _str->s = (char*)pkg_malloc(_str->len);
116
+            if (!_str->s) goto memerr;
117
+            snprintf(_str->s, _str->len, "%llu", VAL_UBIGINT(v));
118
+            _str->len = strlen(_str->s);
119
+            break;
106 120
         case DB1_STRING:
107 121
             s = VAL_STRING(v);
108 122
             _str->len = strlen(s);
... ...
@@ -448,6 +448,15 @@ static struct str_hash_entry* db_redis_create_column(str *col, str *type) {
448 448
         case 'I':
449 449
             e->u.n = DB1_INT;
450 450
             break;
451
+        case 'u':
452
+        case 'U':
453
+			/* uint and ubigint */
454
+			if(type->len>1 && (type->s[1]=='b' || type->s[1]=='B')) {
455
+				e->u.n = DB1_UBIGINT;
456
+			} else {
457
+				e->u.n = DB1_UINT;
458
+			}
459
+            break;
451 460
         case 't':
452 461
         case 'T':
453 462
             e->u.n = DB1_DATETIME;
... ...
@@ -458,7 +467,12 @@ static struct str_hash_entry* db_redis_create_column(str *col, str *type) {
458 467
             break;
459 468
         case 'b':
460 469
         case 'B':
461
-            e->u.n = DB1_BLOB;
470
+			/* blob and bigint */
471
+			if(type->len>1 && (type->s[1]=='i' || type->s[1]=='I')) {
472
+				e->u.n = DB1_BIGINT;
473
+			} else {
474
+				e->u.n = DB1_BLOB;
475
+			}
462 476
             break;
463 477
         default:
464 478
             LM_ERR("Invalid schema column type '%.*s', expecting one of string, int, timestamp, double, blob\n",