Browse code

db_text : simple raw support for select

lazedo authored on 13/04/2015 16:13:12
Showing 3 changed files
... ...
@@ -322,10 +322,51 @@ clean:
322 322
 /*
323 323
  * Raw SQL query -- is not the case to have this method
324 324
  */
325
-int dbt_raw_query(db1_con_t* _h, char* _s, db1_res_t** _r)
325
+int dbt_raw_query(db1_con_t* _h, const str* _s, db1_res_t** _r)
326 326
 {
327 327
 	*_r = NULL;
328
-    return -1;
328
+    int res = -1;
329
+	dbt_table_p _tbc = NULL;
330
+	int cols;
331
+	int n = 0;
332
+	db_key_t *result_cols = NULL;
333
+
334
+	if(!_h) {
335
+		LM_ERR("H INVALID\n");
336
+		return res;
337
+	}
338
+
339
+	if(!_s) {
340
+		LM_ERR("S INVALID\n");
341
+		return res;
342
+	}
343
+
344
+	if(dbt_use_table(_h, _s) != 0) {
345
+		LM_ERR("USE INVALID %.*s\n", _s->len, _s->s);
346
+		return res;
347
+	}
348
+
349
+	_tbc = dbt_db_get_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
350
+	if(!_tbc)
351
+	{
352
+		LM_ERR("table %.*s does not exist!\n", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
353
+		return res;
354
+	}
355
+
356
+	cols = _tbc->nrcols;
357
+	result_cols = pkg_malloc(sizeof(db_key_t) * cols);
358
+	memset(result_cols, 0, sizeof(db_key_t) * cols);
359
+	for(n=0; n < cols; n++) {
360
+		result_cols[n] = &_tbc->colv[n]->name;
361
+	}
362
+
363
+	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
364
+
365
+	res = dbt_query(_h, NULL, NULL, NULL, result_cols, 0, cols, NULL, _r);
366
+	pkg_free(result_cols);
367
+	return res;
368
+
369
+
329 370
 }
330 371
 
331 372
 /*
... ...
@@ -126,7 +126,8 @@ int dbt_bind_api(db_func_t *dbb)
126 126
 	dbb->delete      = (db_delete_f)dbt_delete; 
127 127
 	dbb->update      = (db_update_f)dbt_update;
128 128
 	dbb->affected_rows = (db_affected_rows_f) dbt_affected_rows;
129
-	dbb->cap         = DB_CAP_AFFECTED_ROWS;
129
+	dbb->raw_query   = (db_raw_query_f) dbt_raw_query;
130
+	dbb->cap         = DB_CAP_ALL | DB_CAP_AFFECTED_ROWS | DB_CAP_RAW_QUERY;
130 131
 
131 132
 	return 0;
132 133
 }
... ...
@@ -60,7 +60,7 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
60 60
 /*
61 61
  * Raw SQL query
62 62
  */
63
-int dbt_raw_query(db1_con_t* _h, char* _s, db1_res_t** _r);
63
+int dbt_raw_query(db1_con_t* _h, const str* _s, db1_res_t** _r);
64 64
 
65 65
 
66 66
 /*