| 166 | */ |
| 167 | |
| 168 | int dbt_query(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, |
| 169 | db_key_t* _c, int _n, int _nc, db_key_t _o, db_res_t** _r) |
| 170 | { |
| 171 | dbt_table_p _tbc = NULL; |
| 172 | dbt_row_p _drp = NULL; |
| 173 | dbt_result_p _dres = NULL; |
| 174 | |
| 175 | int *lkey=NULL, *lres=NULL; |
| 176 | |
| 177 | if ((!_h) || (!_r) || !CON_TABLE(_h)) |
| 178 | { |
| 179 | LM_ERR("invalid parameters\n"); |
| 180 | return -1; |
| 181 | } |
| 182 | *_r = NULL; |
| 183 | |
| 184 | |
| 185 | /* lock database */ |
| 186 | _tbc = dbt_db_get_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h)); |
| 187 | if(!_tbc) |
| 188 | { |
| 189 | LM_ERR("table '%.*s' does not exist!\n", CON_TABLE(_h)->len, |
| 190 | CON_TABLE(_h)->s); |
| 191 | return -1; |
| 192 | } |
| 193 | |
| 194 | if(_tbc->nrcols < _nc) |
| 195 | { |
| 196 | LM_ERR("bad columns for table '%.*s' (have %d, need %d)\n", |
| 197 | CON_TABLE(_h)->len, CON_TABLE(_h)->s, _tbc->nrcols, _nc); |
| 198 | goto error; |
| 199 | } |
| 200 | if(_k) |
| 201 | { |
| 202 | lkey = dbt_get_refs(_tbc, _k, _n); |
| 203 | if(!lkey) |
| 204 | goto error; |
| 205 | } |
| 206 | if(_c) |
| 207 | { |
| 208 | lres = dbt_get_refs(_tbc, _c, _nc); |
| 209 | if(!lres) |
| 210 | goto error; |
| 211 | } |
| 212 | |
| 213 | LM_DBG("new res with %d cols\n", _nc); |
| 214 | _dres = dbt_result_new(_tbc, lres, _nc); |
| 215 | |
| 216 | if(!_dres) |
| 217 | goto error; |
| 218 | |
| 219 | _drp = _tbc->rows; |
| 220 | while(_drp) |
| 221 | { |
| 222 | if(dbt_row_match(_tbc, _drp, lkey, _op, _v, _n)) |
| 223 | { |
| 224 | if(dbt_result_extract_fields(_tbc, _drp, lres, _dres)) |
| 225 | { |
nothing calls this directly
no test coverage detected