[sr-dev] git:master:df7773af: db_text : simple raw support for select
Luis Azedo
luis.azedo at factorlusitano.com
Thu Apr 23 09:37:27 CEST 2015
Module: kamailio
Branch: master
Commit: df7773afce1c7ea5719c5311cda799e5197feeb6
URL: https://github.com/kamailio/kamailio/commit/df7773afce1c7ea5719c5311cda799e5197feeb6
Author: lazedo <luis.azedo at factorlusitano.com>
Committer: Luis Azedo <luis.azedo at factorlusitano.com>
Date: 2015-04-22T18:04:57+01:00
db_text : simple raw support for select
---
Modified: modules/db_text/dbt_base.c
Modified: modules/db_text/dbtext.c
Modified: modules/db_text/dbtext.h
---
Diff: https://github.com/kamailio/kamailio/commit/df7773afce1c7ea5719c5311cda799e5197feeb6.diff
Patch: https://github.com/kamailio/kamailio/commit/df7773afce1c7ea5719c5311cda799e5197feeb6.patch
---
diff --git a/modules/db_text/dbt_base.c b/modules/db_text/dbt_base.c
index fc70433..3df41bb 100644
--- a/modules/db_text/dbt_base.c
+++ b/modules/db_text/dbt_base.c
@@ -322,10 +322,51 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
/*
* Raw SQL query -- is not the case to have this method
*/
-int dbt_raw_query(db1_con_t* _h, char* _s, db1_res_t** _r)
+int dbt_raw_query(db1_con_t* _h, const str* _s, db1_res_t** _r)
{
*_r = NULL;
- return -1;
+ int res = -1;
+ dbt_table_p _tbc = NULL;
+ int cols;
+ int n = 0;
+ db_key_t *result_cols = NULL;
+
+ if(!_h) {
+ LM_ERR("H INVALID\n");
+ return res;
+ }
+
+ if(!_s) {
+ LM_ERR("S INVALID\n");
+ return res;
+ }
+
+ if(dbt_use_table(_h, _s) != 0) {
+ LM_ERR("USE INVALID %.*s\n", _s->len, _s->s);
+ return res;
+ }
+
+ _tbc = dbt_db_get_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
+ if(!_tbc)
+ {
+ LM_ERR("table %.*s does not exist!\n", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+ return res;
+ }
+
+ cols = _tbc->nrcols;
+ result_cols = pkg_malloc(sizeof(db_key_t) * cols);
+ memset(result_cols, 0, sizeof(db_key_t) * cols);
+ for(n=0; n < cols; n++) {
+ result_cols[n] = &_tbc->colv[n]->name;
+ }
+
+ dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
+
+ res = dbt_query(_h, NULL, NULL, NULL, result_cols, 0, cols, NULL, _r);
+ pkg_free(result_cols);
+ return res;
+
+
}
/*
diff --git a/modules/db_text/dbtext.c b/modules/db_text/dbtext.c
index 142f1c5..4f1d4a6 100644
--- a/modules/db_text/dbtext.c
+++ b/modules/db_text/dbtext.c
@@ -126,7 +126,8 @@ int dbt_bind_api(db_func_t *dbb)
dbb->delete = (db_delete_f)dbt_delete;
dbb->update = (db_update_f)dbt_update;
dbb->affected_rows = (db_affected_rows_f) dbt_affected_rows;
- dbb->cap = DB_CAP_AFFECTED_ROWS;
+ dbb->raw_query = (db_raw_query_f) dbt_raw_query;
+ dbb->cap = DB_CAP_ALL | DB_CAP_AFFECTED_ROWS | DB_CAP_RAW_QUERY;
return 0;
}
diff --git a/modules/db_text/dbtext.h b/modules/db_text/dbtext.h
index 5517bd0..83bfcdc 100644
--- a/modules/db_text/dbtext.h
+++ b/modules/db_text/dbtext.h
@@ -60,7 +60,7 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
/*
* Raw SQL query
*/
-int dbt_raw_query(db1_con_t* _h, char* _s, db1_res_t** _r);
+int dbt_raw_query(db1_con_t* _h, const str* _s, db1_res_t** _r);
/*
More information about the sr-dev
mailing list