| 705 | |
| 706 | |
| 707 | int sql_api_select(struct db_url *url, struct sip_msg* msg, cJSON *Jcols, |
| 708 | str *table, cJSON *Jfilter, str * order, pvname_list_t* dest, int one_row) |
| 709 | { |
| 710 | static map_t ps_map = NULL; |
| 711 | db_res_t* db_res = NULL; |
| 712 | db_key_t *cols, *keys; |
| 713 | db_op_t *ops; |
| 714 | db_val_t *vals; |
| 715 | int nk, nc; |
| 716 | str *id; |
| 717 | db_ps_t *my_ps; |
| 718 | |
| 719 | /* convert JSON to COLs */ |
| 720 | if (Jcols) { |
| 721 | nc = _json_to_cols( Jcols, &cols); |
| 722 | if (nc<0) { |
| 723 | LM_ERR("failed to extract cols from JSON\n"); |
| 724 | return -1; |
| 725 | } |
| 726 | } else { |
| 727 | cols = NULL; |
| 728 | nc = 0; |
| 729 | } |
| 730 | |
| 731 | /* convert JSON to keys */ |
| 732 | if (Jfilter) { |
| 733 | nk = _json_to_filters( Jfilter, &keys, &ops, &vals, 0); |
| 734 | if (nk<0) { |
| 735 | LM_ERR("failed to extract filter from JSON\n"); |
| 736 | return -1; |
| 737 | } |
| 738 | } else { |
| 739 | keys = NULL; |
| 740 | ops = NULL; |
| 741 | vals = NULL; |
| 742 | nk = 0; |
| 743 | } |
| 744 | |
| 745 | /* set table */ |
| 746 | if (set_table( url, table ,"API select")!=0) |
| 747 | return -1; |
| 748 | |
| 749 | if ( !DB_CAPABILITY(url->dbf, DB_CAP_PREPARED_STMT) || |
| 750 | _query_id_start(table,order)==NULL || |
| 751 | (cols && (id=_query_id_add_cols(cols,nc))==NULL) || |
| 752 | (keys && (id=_query_id_add_filter(keys,ops,nk))==NULL) ) { |
| 753 | LM_DBG("not using PS\n"); |
| 754 | } else { |
| 755 | LM_DBG("PS id is <%.*s>\n",id->len,id->s); |
| 756 | if (ps_map!=NULL || (ps_map=map_create(0))!=NULL) { |
| 757 | if ( (my_ps=map_get( ps_map, *id ))!=NULL) { |
| 758 | LM_DBG("using PS %p\n",*my_ps); |
| 759 | CON_SET_CURR_PS( url->hdl, my_ps); |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | /* do the DB query */ |
no test coverage detected