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

Function db_query_print_results

modules/sqlops/sqlops_db.c:1108–1227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1106
1107
1108int db_query_print_results(struct sip_msg *msg, const db_res_t *db_res,
1109 pvname_list_t *dest)
1110{
1111 int_str avp_val;
1112 int_str avp_name;
1113 unsigned short avp_type;
1114 int i, j;
1115 pvname_list_t* crt;
1116
1117 LM_DBG("rows [%d]\n", RES_ROW_N(db_res));
1118 /* reverse order of rows so that first row get's in front of avp list */
1119 for(i = RES_ROW_N(db_res)-1; i >= 0; i--)
1120 {
1121 LM_DBG("row [%d]\n", i);
1122 crt = dest;
1123 for(j = 0; j < RES_COL_N(db_res); j++)
1124 {
1125 avp_type = 0;
1126 if(crt==NULL)
1127 {
1128 avp_name.s.s = int2str(j+1, &avp_name.s.len);
1129 avp_name.n = get_avp_id(&avp_name.s);
1130 if (avp_name.n < 0) {
1131 LM_ERR("cannot convert avp %d\n", j+1);
1132 goto next_avp;
1133 }
1134 } else {
1135 if(pv_get_avp_name(msg, &crt->sname.pvp, &avp_name.n,
1136 &avp_type)!=0)
1137 {
1138 LM_ERR("cant get avp name [%d/%d]\n", i, j);
1139 goto next_avp;
1140 }
1141 }
1142 if(RES_ROWS(db_res)[i].values[j].nul) {
1143 avp_type |= AVP_VAL_STR;
1144 /* keep the NULL value in sync with str_null as
1145 * defined in pvar.c !! */
1146 avp_val.s.s = "<null>";
1147 avp_val.s.len = 6;
1148 } else {
1149 switch(RES_ROWS(db_res)[i].values[j].type) {
1150 case DB_STRING:
1151 avp_type |= AVP_VAL_STR;
1152 avp_val.s.s=
1153 (char*)RES_ROWS(db_res)[i].values[j].val.string_val;
1154 avp_val.s.len=strlen(avp_val.s.s);
1155 if(avp_val.s.len<0)
1156 goto next_avp;
1157 break;
1158 case DB_STR:
1159 avp_type |= AVP_VAL_STR;
1160 avp_val.s.len=
1161 RES_ROWS(db_res)[i].values[j].val.str_val.len;
1162 avp_val.s.s=
1163 (char*)RES_ROWS(db_res)[i].values[j].val.str_val.s;
1164 if(avp_val.s.len<0)
1165 goto next_avp;

Callers 3

sql_queryFunction · 0.85
sql_api_selectFunction · 0.85
resume_async_sqlqueryFunction · 0.85

Calls 6

int2strFunction · 0.85
get_avp_idFunction · 0.85
pv_get_avp_nameFunction · 0.85
bigint2strFunction · 0.85
double2strFunction · 0.85
add_avpFunction · 0.85

Tested by

no test coverage detected