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

Function db_sqlite_query

modules/db_sqlite/dbase.c:148–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148int db_sqlite_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
149 const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc,
150 const db_key_t _o, db_res_t** _r)
151{
152 int ret=-1;
153#ifdef SQLITE_BIND
154 db_ps_t ps;
155
156 CON_SET_CURR_PS(_h, &ps);
157#else
158 CON_RESET_CURR_PS(_h);
159#endif
160 CON_RAW_QUERY(_h) = 0;
161
162 ret = db_do_query(_h, _k, _op, _v, _c, _n, _nc, _o, NULL,
163 db_sqlite_val2str, db_sqlite_submit_dummy_query, NULL);
164 if (ret != 0) {
165 if (_r)
166 *_r = NULL;
167 return ret;
168 }
169
170 if (db_copy_rest_of_count(&query_holder, &count_str)) {
171 LM_ERR("failed to build row counter query\n");
172 return -1;
173 }
174
175
176 ret=sqlite3_prepare_v2(CON_CONNECTION(_h),
177 query_holder.s, query_holder.len, &CON_SQLITE_PS(_h), NULL);
178
179 if (ret!=SQLITE_OK)
180 LM_ERR("failed to prepare: (%s)\n", sqlite3_errmsg(CON_CONNECTION(_h)));
181
182#ifdef SQLITE_BIND
183 if (db_sqlite_bind_values(CON_SQLITE_PS(_h), _v, _n) != SQLITE_OK) {
184 LM_ERR("failed to bind values\n");
185 sqlite3_finalize(CON_SQLITE_PS(_h));
186 CON_SQLITE_PS(_h) = NULL;
187 return -1;
188 }
189#endif
190
191 if (_r) {
192 ret = db_sqlite_store_result(_h, _r, _v, _n);
193 } else {
194 /* need to fetch now the total number of rows in query
195 * because later won't have the query string */
196 ret = db_sqlite_get_query_rows(_h, &count_str, _v, _n);
197 if (ret >= 0) {
198 CON_PS_ROWS(_h) = ret;
199 ret = 0;
200 }
201 }
202 if( ret < 0 ) {
203 if (_r) {
204 db_sqlite_free_result_internal(_h,*_r);
205 } else if (CON_SQLITE_PS(_h)) {

Callers

nothing calls this directly

Calls 6

db_do_queryFunction · 0.85
db_copy_rest_of_countFunction · 0.85
db_sqlite_bind_valuesFunction · 0.85
db_sqlite_store_resultFunction · 0.85
db_sqlite_get_query_rowsFunction · 0.85

Tested by

no test coverage detected