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

Function db_sqlite_fetch_result

modules/db_sqlite/dbase.c:221–329  ·  view source on GitHub ↗

* Gets a partial result set. * \param _h structure representing the database connection * \param _r pointer to a structure representing the result * \param nrows number of fetched rows * \return zero on success, negative value on failure */

Source from the content-addressed store, hash-verified

219 * \return zero on success, negative value on failure
220 */
221int db_sqlite_fetch_result(const db_con_t* _h, db_res_t** _r, const int nrows)
222{
223
224 int ret;
225 int rows, i;
226 sqlite3_stmt* stmt;
227
228 if (!_r) {
229 LM_ERR("null result!\n");
230 return -1;
231 }
232
233 if (!_h || nrows < 0) {
234 LM_ERR("Invalid parameter value\n");
235 db_sqlite_free_result_internal(_h,*_r);
236 return -1;
237 }
238
239 /* exit if the fetch count is zero */
240 if (nrows == 0) {
241 db_sqlite_free_result_internal(_h,*_r);
242 *_r = 0;
243 return 0;
244 }
245
246 if(*_r==0) {
247 /* Allocate a new result structure */
248 *_r = db_new_result();
249 if (*_r == 0) {
250 LM_ERR("no memory left\n");
251 return -2;
252 }
253
254 if (db_sqlite_get_columns(_h, *_r) < 0) {
255 LM_ERR("error while getting column names\n");
256 db_sqlite_free_result_internal(_h,*_r);
257 return -4;
258 }
259
260 RES_NUM_ROWS(*_r) = CON_PS_ROWS(_h);
261
262 if (!RES_NUM_ROWS(*_r)) {
263 LM_DBG("no rows returned from the query\n");
264 RES_ROWS(*_r) = 0;
265 return 0;
266 }
267 } else {
268 /* free old rows */
269 db_sqlite_free_result_rows(*_r);
270 }
271
272 /* determine the number of rows remaining to be processed */
273 rows = RES_NUM_ROWS(*_r) - RES_LAST_ROW(*_r);
274
275 /* If there aren't any more rows left to process, exit */
276 if(rows<=0)
277 return 0;
278

Callers

nothing calls this directly

Calls 7

db_new_resultFunction · 0.85
db_sqlite_get_columnsFunction · 0.85
db_sqlite_allocate_rowsFunction · 0.85
db_sqlite_realloc_rowsFunction · 0.85
db_sqlite_convert_rowFunction · 0.85

Tested by

no test coverage detected