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

Function db_postgres_str2val

modules/db_postgres/val.c:54–171  ·  view source on GitHub ↗

* Convert a str to a db value, does not copy strings * The postgresql module uses a custom escape function for BLOBs. * If the _s is linked in the db_val result, it will be returned zero */

Source from the content-addressed store, hash-verified

52 * If the _s is linked in the db_val result, it will be returned zero
53 */
54int db_postgres_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l)
55{
56 static str dummy_string = {"", 0};
57 char *x;
58
59 if (!_v) {
60 LM_ERR("invalid parameter value\n");
61 return -1;
62 }
63
64 if (!_s) {
65 memset(_v, 0, sizeof(db_val_t));
66 /* Initialize the string pointers to a dummy empty
67 * string so that we do not crash when the NULL flag
68 * is set but the module does not check it properly
69 */
70 VAL_STR(_v) = dummy_string;
71 VAL_TYPE(_v) = _t;
72 VAL_NULL(_v) = 1;
73 return 0;
74 }
75 VAL_NULL(_v) = 0;
76
77 switch(_t) {
78 case DB_INT:
79 LM_DBG("converting INT [%s]\n", _s);
80 if (db_str2int(_s, &VAL_INT(_v)) < 0) {
81 LM_ERR("failed to convert INT value from string\n");
82 return -2;
83 } else {
84 VAL_TYPE(_v) = DB_INT;
85 return 0;
86 }
87 break;
88
89 case DB_BIGINT:
90 LM_DBG("converting BIGINT [%s]\n", _s);
91 if (db_str2bigint(_s, &VAL_BIGINT(_v)) < 0) {
92 LM_ERR("failed to convert BIGINT value from string\n");
93 return -2;
94 } else {
95 VAL_TYPE(_v) = DB_BIGINT;
96 return 0;
97 }
98 break;
99
100 case DB_BITMAP:
101 LM_DBG("converting BITMAP [%s]\n", _s);
102 if (db_str2int(_s, &VAL_INT(_v)) < 0) {
103 LM_ERR("failed to convert BITMAP value from string\n");
104 return -3;
105 } else {
106 VAL_TYPE(_v) = DB_BITMAP;
107 return 0;
108 }
109 break;
110
111 case DB_DOUBLE:

Callers 1

db_postgres_convert_rowFunction · 0.85

Calls 4

db_str2intFunction · 0.85
db_str2bigintFunction · 0.85
db_str2doubleFunction · 0.85
db_str2timeFunction · 0.85

Tested by

no test coverage detected