MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / db_sqlite_val2str

Function db_sqlite_val2str

modules/db_sqlite/val.c:38–166  ·  view source on GitHub ↗

* Used when converting values to be used in a DB query */

Source from the content-addressed store, hash-verified

36 * Used when converting values to be used in a DB query
37 */
38int db_sqlite_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
39{
40 int l;
41
42 if (!_c || !_v || !_s || !_len || !*_len) {
43 LM_ERR("invalid parameter value\n");
44 return -1;
45 }
46
47 if (VAL_NULL(_v)) {
48 if (*_len < sizeof("NULL")) {
49 LM_ERR("buffer too small\n");
50 return -1;
51 }
52 *_len = snprintf(_s, *_len, "NULL");
53 return 0;
54 }
55
56 switch(VAL_TYPE(_v)) {
57 case DB_INT:
58 if (db_int2str(VAL_INT(_v), _s, _len) < 0) {
59 LM_ERR("error while converting string to int\n");
60 return -2;
61 } else {
62 return 0;
63 }
64 break;
65
66 case DB_BIGINT:
67 if (db_bigint2str(VAL_BIGINT(_v), _s, _len) < 0) {
68 LM_ERR("error while converting bigint to string\n");
69 return -2;
70 } else {
71 return 0;
72 }
73 break;
74
75
76 case DB_BITMAP:
77 if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) {
78 LM_ERR("error while converting string to int\n");
79 return -3;
80 } else {
81 return 0;
82 }
83 break;
84
85 case DB_DOUBLE:
86 if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
87 LM_ERR("error while converting string to double\n");
88 return -4;
89 } else {
90 return 0;
91 }
92 break;
93
94 case DB_STRING:
95 l = strlen(VAL_STRING(_v));

Callers

nothing calls this directly

Calls 5

db_int2strFunction · 0.85
db_bigint2strFunction · 0.85
db_double2strFunction · 0.85
db_time2strFunction · 0.85
string2hexFunction · 0.85

Tested by

no test coverage detected