* Used when converting result from a query */
| 199 | * Used when converting result from a query |
| 200 | */ |
| 201 | int bdb_val2str(db_val_t* _v, char* _s, int* _len) |
| 202 | { |
| 203 | int l; |
| 204 | |
| 205 | if (VAL_NULL(_v)) |
| 206 | { |
| 207 | *_len = snprintf(_s, *_len, "NULL"); |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | switch(VAL_TYPE(_v)) { |
| 212 | case DB_INT: |
| 213 | if (db_int2str(VAL_INT(_v), _s, _len) < 0) { |
| 214 | LM_ERR("Error while converting int to string\n"); |
| 215 | return -2; |
| 216 | } else { |
| 217 | LM_DBG("Converted int to string\n"); |
| 218 | return 0; |
| 219 | } |
| 220 | break; |
| 221 | |
| 222 | case DB_BIGINT: |
| 223 | if (db_bigint2str(VAL_BIGINT(_v), _s, _len) < 0) { |
| 224 | LM_ERR("Error while converting bigint to string\n"); |
| 225 | return -2; |
| 226 | } else { |
| 227 | LM_DBG("Converted bigint to string\n"); |
| 228 | return 0; |
| 229 | } |
| 230 | break; |
| 231 | |
| 232 | case DB_BITMAP: |
| 233 | if (db_int2str(VAL_INT(_v), _s, _len) < 0) { |
| 234 | LM_ERR("Error while converting bitmap to string\n"); |
| 235 | return -3; |
| 236 | } else { |
| 237 | LM_DBG("Converted bitmap to string\n"); |
| 238 | return 0; |
| 239 | } |
| 240 | break; |
| 241 | |
| 242 | case DB_DOUBLE: |
| 243 | if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) { |
| 244 | LM_ERR("Error while converting double to string\n"); |
| 245 | return -3; |
| 246 | } else { |
| 247 | LM_DBG("Converted double to string\n"); |
| 248 | return 0; |
| 249 | } |
| 250 | break; |
| 251 | |
| 252 | case DB_STRING: |
| 253 | l = strlen(VAL_STRING(_v)); |
| 254 | if (*_len < l ) |
| 255 | { LM_ERR("Destination buffer too short for string\n"); |
| 256 | return -4; |
| 257 | } |
| 258 | else |
no test coverage detected