Module: kamailio Branch: master Commit: 6ef943d5ee1376527e7ce173c1bba0fcf1dd4e90 URL: https://github.com/kamailio/kamailio/commit/6ef943d5ee1376527e7ce173c1bba0fc...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2015-04-23T09:37:24+02:00
Merge pull request #136 from lazedo/db_text_simple_raw
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/6ef943d5ee1376527e7ce173c1bba0fc... Patch: https://github.com/kamailio/kamailio/commit/6ef943d5ee1376527e7ce173c1bba0fc...
---
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);
/*