| 911 | |
| 912 | |
| 913 | int sql_api_delete(struct db_url *url, struct sip_msg* msg, |
| 914 | str *table, cJSON *Jfilter) |
| 915 | { |
| 916 | static map_t ps_map = NULL; |
| 917 | db_key_t *keys; |
| 918 | db_op_t *ops; |
| 919 | db_val_t *vals; |
| 920 | int nk; |
| 921 | str *id; |
| 922 | db_ps_t *my_ps; |
| 923 | |
| 924 | /* convert JSON to keys */ |
| 925 | if (Jfilter) { |
| 926 | nk = _json_to_filters( Jfilter, &keys, &ops, &vals, 0); |
| 927 | if (nk<0) { |
| 928 | LM_ERR("failed to extract filter from JSON\n"); |
| 929 | return -1; |
| 930 | } |
| 931 | } else { |
| 932 | keys = NULL; |
| 933 | ops = NULL; |
| 934 | vals = NULL; |
| 935 | nk = 0; |
| 936 | } |
| 937 | |
| 938 | /* set table */ |
| 939 | if (set_table( url, table ,"API delete")!=0) |
| 940 | return -1; |
| 941 | |
| 942 | /* set the PS to be used */ |
| 943 | if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) || |
| 944 | _query_id_start(table,NULL)==NULL || |
| 945 | (keys && (id=_query_id_add_filter(keys,ops,nk))==NULL) ) { |
| 946 | LM_DBG("not using PS\n"); |
| 947 | } else { |
| 948 | LM_DBG("PS id is <%.*s>\n",id->len,id->s); |
| 949 | if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) { |
| 950 | if ( (my_ps=map_get( ps_map, *id ))!=NULL) { |
| 951 | LM_DBG("using PS %p\n",*my_ps); |
| 952 | CON_SET_CURR_PS( url->hdl, my_ps); |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | /* do the DB query */ |
| 958 | if (url->dbf.delete( url->hdl, keys, ops, vals, nk)<0){ |
| 959 | const str *t = url->hdl&&url->hdl->table&&url->hdl->table->s |
| 960 | ? url->hdl->table : 0; |
| 961 | LM_ERR("update API query failed: db%d (%.*s)\n", |
| 962 | url->idx, t?t->len:0, t?t->s:""); |
| 963 | return -1; |
| 964 | } |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | |
| 970 | int sql_api_replace(struct db_url *url, struct sip_msg* msg, str *table, |
no test coverage detected