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

Function dbrow2avp

modules/sqlops/sqlops_impl.c:92–211  ·  view source on GitHub ↗

value 0 - attr value * value 1 - attr name * value 2 - attr type */

Source from the content-addressed store, hash-verified

90 * value 2 - attr type
91 */
92static int dbrow2avp(struct db_row *row, struct db_param *dbp, int attr,
93 int attr_type, int just_val_flags, str *prefix)
94{
95 unsigned int uint;
96 int db_flags;
97 str atmp;
98 str vtmp;
99 int avp_attr;
100 int_str avp_val;
101 int flags;
102
103 flags = dbp->a.opd;
104
105 if (just_val_flags==-1)
106 {
107 /* check for null fields into the row */
108 if (row->values[0].nul || row->values[1].nul || row->values[2].nul )
109 {
110 LM_ERR("dbrow contains NULL fields\n");
111 return -1;
112 }
113
114 /* check the value types */
115 if ( (row->values[0].type!=DB_STRING && row->values[0].type!=DB_STR)
116 || (row->values[1].type!=DB_STRING && row->values[1].type!=DB_STR)
117 || row->values[2].type!=DB_INT )
118 {
119 LM_ERR("wrong field types in dbrow\n");
120 return -1;
121 }
122
123 /* check the content of flag field */
124 uint = (unsigned int)row->values[2].val.int_val;
125 db_flags = ((uint&SQLOPS_DB_NAME_INT)?0:AVP_NAME_STR) |
126 ((uint&SQLOPS_DB_VAL_INT)?0:AVP_VAL_STR);
127 } else {
128 /* check the validity of value column */
129 if (row->values[0].nul || (row->values[0].type!=DB_STRING &&
130 row->values[0].type!=DB_STR && row->values[0].type!=DB_INT) )
131 {
132 LM_ERR("empty or wrong type for 'value' using scheme\n");
133 return -1;
134 }
135 db_flags = just_val_flags;
136 }
137
138 /* is the avp name already known? */
139 if ( (flags&SQLOPS_VAL_NONE)==0 )
140 {
141 /* use the name */
142 avp_attr = attr;
143 db_flags |= attr_type;
144 } else {
145 /* take the name from db response */
146 if (row->values[1].type==DB_STRING)
147 {
148 atmp.s = (char*)row->values[1].val.string_val;
149 atmp.len = strlen(atmp.s);

Callers 1

ops_sql_avp_loadFunction · 0.85

Calls 4

get_avp_idFunction · 0.85
int2strFunction · 0.85
str2intFunction · 0.85
add_avpFunction · 0.85

Tested by

no test coverage detected