* Get and convert columns from a result */
| 43 | * Get and convert columns from a result |
| 44 | */ |
| 45 | static int dbt_get_columns(db_con_t* _h, db_res_t* _r) |
| 46 | { |
| 47 | int col; |
| 48 | |
| 49 | if (!_h || !_r) { |
| 50 | LM_ERR("invalid parameter\n"); |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | RES_COL_N(_r) = DBT_CON_RESULT(_h)->nrcols; |
| 55 | if (!RES_COL_N(_r)) { |
| 56 | LM_ERR("no columns\n"); |
| 57 | return -2; |
| 58 | } |
| 59 | if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) { |
| 60 | LM_ERR("could not allocate columns\n"); |
| 61 | return -3; |
| 62 | } |
| 63 | |
| 64 | for(col = 0; col < RES_COL_N(_r); col++) { |
| 65 | |
| 66 | RES_NAMES(_r)[col]->s = DBT_CON_RESULT(_h)->colv[col].name.s; |
| 67 | RES_NAMES(_r)[col]->len = DBT_CON_RESULT(_h)->colv[col].name.len; |
| 68 | |
| 69 | switch(DBT_CON_RESULT(_h)->colv[col].type) |
| 70 | { |
| 71 | case DB_STR: |
| 72 | case DB_STRING: |
| 73 | case DB_BLOB: |
| 74 | case DB_INT: |
| 75 | case DB_BIGINT: |
| 76 | case DB_DATETIME: |
| 77 | case DB_DOUBLE: |
| 78 | RES_TYPES(_r)[col] = DBT_CON_RESULT(_h)->colv[col].type; |
| 79 | break; |
| 80 | default: |
| 81 | LM_WARN("unhandled data type column (%.*s) type id (%d), " |
| 82 | "use STR as default\n", RES_NAMES(_r)[col]->len, |
| 83 | RES_NAMES(_r)[col]->s, DBT_CON_RESULT(_h)->colv[col].type); |
| 84 | RES_TYPES(_r)[col] = DB_STR; |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Convert a row from result into db API representation |
no test coverage detected