Skip to content

Commit

Permalink
[sqlops] improve the prepared statements support II
Browse files Browse the repository at this point in the history
Use the new DB_CAP_PREPARED_STMT capability to test if the backend support statements and build the query ID only if so.
  • Loading branch information
bogdan-iancu committed Apr 18, 2024
1 parent 6b2dbbc commit d79c463
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions modules/sqlops/sqlops_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,11 @@ int sql_api_select(struct db_url *url, struct sip_msg* msg, cJSON *Jcols,
if (set_table( url, table ,"API select")!=0)
return -1;

if ( _query_id_start(table,order)==NULL ||
if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) ||
_query_id_start(table,order)==NULL ||
(cols && (id=_query_id_add_cols(cols,nc))==NULL) ||
(keys && (id=_query_id_add_filter(keys,ops,nk))==NULL) ) {
LM_ERR("failed to build PS id\n");
LM_DBG("not using PS\n");
} else {
LM_DBG("PS id is <%.*s>\n",id->len,id->s);
if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) {
Expand Down Expand Up @@ -828,10 +829,11 @@ int sql_api_update(struct db_url *url, struct sip_msg* msg, cJSON *Jcols,
if (set_table( url, table ,"API update")!=0)
return -1;

if ( _query_id_start(table,NULL)==NULL ||
if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) ||
_query_id_start(table,NULL)==NULL ||
(id=_query_id_add_filter(ukeys,uops,unk))==NULL ||
(keys && (id=_query_id_add_filter(keys,ops,nk))==NULL) ) {
LM_ERR("failed to build PS id\n");
LM_DBG("not using PS\n");
} else {
LM_DBG("PS id is <%.*s>\n",id->len,id->s);
if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) {
Expand Down Expand Up @@ -878,9 +880,10 @@ int sql_api_insert(struct db_url *url, struct sip_msg* msg, str *table,
return -1;

/* set the PS to be used */
if ( _query_id_start(table,NULL)==NULL ||
if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) ||
_query_id_start(table,NULL)==NULL ||
(id=_query_id_add_filter(ukeys,uops,unk))==NULL ) {
LM_ERR("failed to build PS id\n");
LM_DBG("not using PS\n");
} else {
LM_DBG("PS id is <%.*s>\n",id->len,id->s);
if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) {
Expand Down Expand Up @@ -934,9 +937,10 @@ int sql_api_delete(struct db_url *url, struct sip_msg* msg,
return -1;

/* set the PS to be used */
if ( _query_id_start(table,NULL)==NULL ||
if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) ||
_query_id_start(table,NULL)==NULL ||
(keys && (id=_query_id_add_filter(keys,ops,nk))==NULL) ) {
LM_ERR("failed to build PS id\n");
LM_DBG("not using PS\n");
} else {
LM_DBG("PS id is <%.*s>\n",id->len,id->s);
if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) {
Expand Down Expand Up @@ -983,9 +987,10 @@ int sql_api_replace(struct db_url *url, struct sip_msg* msg, str *table,
return -1;

/* set the PS to be used */
if ( _query_id_start(table,NULL)==NULL ||
if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) ||
_query_id_start(table,NULL)==NULL ||
(id=_query_id_add_filter(ukeys,uops,unk))==NULL ) {
LM_ERR("failed to build PS id\n");
LM_DBG("not using PS\n");
} else {
LM_DBG("PS id is <%.*s>\n",id->len,id->s);
if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) {
Expand Down

0 comments on commit d79c463

Please sign in to comment.