| 968 | |
| 969 | |
| 970 | int sql_api_replace(struct db_url *url, struct sip_msg* msg, str *table, |
| 971 | cJSON *Jcols) |
| 972 | { |
| 973 | static map_t ps_map = NULL; |
| 974 | db_key_t *ukeys; |
| 975 | db_op_t *uops; |
| 976 | db_val_t *uvals; |
| 977 | int unk; |
| 978 | str *id; |
| 979 | db_ps_t *my_ps; |
| 980 | |
| 981 | /* convert JSON to COLs */ |
| 982 | unk = _json_to_filters( Jcols, &ukeys, &uops, &uvals, 1); |
| 983 | if (unk<0) { |
| 984 | LM_ERR("failed to extract cols from JSON\n"); |
| 985 | return -1; |
| 986 | } |
| 987 | |
| 988 | /* set table */ |
| 989 | if (set_table( url, table ,"API replace")!=0) |
| 990 | return -1; |
| 991 | |
| 992 | /* set the PS to be used */ |
| 993 | if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) || |
| 994 | _query_id_start(table,NULL)==NULL || |
| 995 | (id=_query_id_add_filter(ukeys,uops,unk))==NULL ) { |
| 996 | LM_DBG("not using PS\n"); |
| 997 | } else { |
| 998 | LM_DBG("PS id is <%.*s>\n",id->len,id->s); |
| 999 | if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) { |
| 1000 | if ( (my_ps=map_get( ps_map, *id ))!=NULL) { |
| 1001 | LM_DBG("using PS %p\n",*my_ps); |
| 1002 | CON_SET_CURR_PS( url->hdl, my_ps); |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | /* do the DB query */ |
| 1008 | if (url->dbf.replace( url->hdl, ukeys, uvals, unk)<0){ |
| 1009 | const str *t = url->hdl&&url->hdl->table&&url->hdl->table->s |
| 1010 | ? url->hdl->table : 0; |
| 1011 | LM_ERR("update API query failed: db%d (%.*s)\n", |
| 1012 | url->idx, t?t->len:0, t?t->s:""); |
| 1013 | return -1; |
| 1014 | } |
| 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | int db_query_print_one_result(struct sip_msg *msg, const db_res_t *db_res, |
no test coverage detected