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

Function db_sqlite_realloc_rows

modules/db_sqlite/res.c:296–339  ·  view source on GitHub ↗

* realloc function * used when entries added to the db since count(*) query */

Source from the content-addressed store, hash-verified

294 * used when entries added to the db since count(*) query
295 */
296int db_sqlite_realloc_rows(db_res_t* res, const unsigned int rows)
297{
298 unsigned int i, start;
299 struct db_row* res_rows;
300 db_val_t *prev_values;
301
302 if (RES_ROW_N(res) >= rows)
303 return 0;
304
305 res_rows = res->rows = pkg_realloc(RES_ROWS(res),rows * sizeof *res_rows);
306 if (!res_rows) {
307 LM_ERR("no memory left\n");
308 return -1;
309 }
310
311 memset(res_rows + RES_ROW_N(res), 0 ,
312 (rows - RES_ROW_N(res)) * sizeof *res_rows);
313
314 prev_values = res_rows[0].values;
315
316 res_rows[0].values =
317 pkg_realloc(res_rows[0].values, rows * sizeof(db_val_t) * RES_COL_N(res));
318 if (! res_rows[0].values) {
319 LM_ERR("no memory left\n");
320 res_rows[0].values = prev_values;
321 return -1;
322 }
323
324 memset( res_rows[0].values + RES_COL_N(res)*RES_ROW_N(res),
325 0, (rows - RES_ROW_N(res)) * sizeof(db_val_t) * RES_COL_N(res));
326
327 /* if the values was relocated, we need to re-point all values to the new block,
328 * otherwise only fix the new ones */
329 start = (res_rows[0].values == prev_values?RES_ROW_N(res):0);
330
331 for( i=start ; i<rows ; i++ ) {
332 /* the values of the row i */
333 res_rows[i].values = res_rows[0].values + RES_COL_N(res)*i;
334 res_rows[i].n = RES_COL_N(res);
335 }
336
337 return 0;
338
339}
340
341/**
342 * Convert rows from sqlite to db API representation

Callers 2

db_sqlite_convert_rowsFunction · 0.85
db_sqlite_fetch_resultFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected