MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / sql_api_insert

Function sql_api_insert

modules/sqlops/sqlops_db.c:863–910  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

861
862
863int sql_api_insert(struct db_url *url, struct sip_msg* msg, str *table,
864 cJSON *Jcols)
865{
866 static map_t ps_map = NULL;
867 db_key_t *ukeys;
868 db_op_t *uops;
869 db_val_t *uvals;
870 int unk;
871 str *id;
872 db_ps_t *my_ps;
873
874 /* convert JSON to COLs */
875 unk = _json_to_filters( Jcols, &ukeys, &uops, &uvals, 1);
876 if (unk<0) {
877 LM_ERR("failed to extract cols from JSON\n");
878 return -1;
879 }
880
881 /* set table */
882 if (set_table( url, table ,"API insert")!=0)
883 return -1;
884
885 /* set the PS to be used */
886 if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) ||
887 _query_id_start(table,NULL)==NULL ||
888 (id=_query_id_add_filter(ukeys,uops,unk))==NULL ) {
889 LM_DBG("not using PS\n");
890 } else {
891 LM_DBG("PS id is <%.*s>\n",id->len,id->s);
892 if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) {
893 if ( (my_ps=map_get( ps_map, *id ))!=NULL) {
894 LM_DBG("using PS %p\n",*my_ps);
895 CON_SET_CURR_PS( url->hdl, my_ps);
896 }
897 }
898 }
899
900 /* do the DB query */
901 if (url->dbf.insert( url->hdl, ukeys, uvals, unk)<0){
902 const str *t = url->hdl&&url->hdl->table&&url->hdl->table->s
903 ? url->hdl->table : 0;
904 LM_ERR("update API query failed: db%d (%.*s)\n",
905 url->idx, t?t->len:0, t?t->s:"");
906 return -1;
907 }
908
909 return 0;
910}
911
912
913int sql_api_delete(struct db_url *url, struct sip_msg* msg,

Callers 1

ops_sql_api_insertFunction · 0.85

Calls 6

_json_to_filtersFunction · 0.85
set_tableFunction · 0.85
_query_id_startFunction · 0.85
_query_id_add_filterFunction · 0.85
map_createFunction · 0.85
map_getFunction · 0.85

Tested by

no test coverage detected