* Used when converting result from a query */
| 175 | * Used when converting result from a query |
| 176 | */ |
| 177 | int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v, |
| 178 | char* _s, int* _len) |
| 179 | { |
| 180 | int l, ret; |
| 181 | int pgret; |
| 182 | char *tmp_s; |
| 183 | size_t tmp_len; |
| 184 | char* old_s; |
| 185 | |
| 186 | if ((!_v) || (!_s) || (!_len) || (!*_len)) { |
| 187 | LM_ERR("invalid parameter value\n"); |
| 188 | return -1; |
| 189 | } |
| 190 | |
| 191 | if (VAL_NULL(_v)) { |
| 192 | if ( *_len < (l=(int)sizeof("NULL")-1)) { |
| 193 | LM_ERR("buffer too short to print NULL\n"); |
| 194 | return -1; |
| 195 | } |
| 196 | memcpy(_s, "NULL", l); |
| 197 | *_len = l; |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | switch(VAL_TYPE(_v)) { |
| 202 | case DB_INT: |
| 203 | if (db_int2str(VAL_INT(_v), _s, _len) < 0) { |
| 204 | LM_ERR("failed to convert string to int\n"); |
| 205 | return -2; |
| 206 | } else { |
| 207 | return 0; |
| 208 | } |
| 209 | break; |
| 210 | |
| 211 | case DB_BIGINT: |
| 212 | if (db_bigint2str(VAL_BIGINT(_v), _s, _len) < 0) { |
| 213 | LM_ERR("failed to convert string to big int\n"); |
| 214 | return -2; |
| 215 | } else { |
| 216 | return 0; |
| 217 | } |
| 218 | break; |
| 219 | |
| 220 | case DB_BITMAP: |
| 221 | if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) { |
| 222 | LM_ERR("failed to convert string to int\n"); |
| 223 | return -3; |
| 224 | } else { |
| 225 | return 0; |
| 226 | } |
| 227 | break; |
| 228 | |
| 229 | case DB_DOUBLE: |
| 230 | if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) { |
| 231 | LM_ERR("failed to convert string to double\n"); |
| 232 | return -3; |
| 233 | } else { |
| 234 | return 0; |
nothing calls this directly
no test coverage detected