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

Function db_postgres_fetch_result

modules/db_postgres/dbase.c:312–423  ·  view source on GitHub ↗

* * pg_fetch_result: Gets a partial result set. * */

Source from the content-addressed store, hash-verified

310 *
311 */
312int db_postgres_fetch_result(const db_con_t* _con, db_res_t** _res, const int nrows)
313{
314 int rows;
315 ExecStatusType pqresult;
316
317 if (!_con || !_res || nrows < 0) {
318 LM_ERR("invalid parameter value\n");
319 return -1;
320 }
321
322 /* exit if the fetch count is zero */
323 if (nrows == 0) {
324 if (*_res)
325 db_free_result(*_res);
326
327 *_res = 0;
328 return 0;
329 }
330
331 if (*_res == NULL) {
332 /* Allocate a new result structure */
333 *_res = db_new_result();
334
335 pqresult = PQresultStatus(CON_RESULT(_con));
336 LM_DBG("%p PQresultStatus(%s) PQgetResult(%p)\n", _con,
337 PQresStatus(pqresult), CON_RESULT(_con));
338
339 switch(pqresult) {
340 case PGRES_COMMAND_OK:
341 /* Successful completion of a command returning no data
342 * (such as INSERT or UPDATE). */
343 return 0;
344
345 case PGRES_TUPLES_OK:
346 /* Successful completion of a command returning data
347 * (such as a SELECT or SHOW). */
348 if (db_postgres_get_columns(_con, *_res) < 0) {
349 LM_ERR("failed to get column names\n");
350 return -2;
351 }
352 break;
353
354 case PGRES_FATAL_ERROR:
355 LM_ERR("%p - invalid query, execution aborted\n", _con);
356 LM_ERR("%p - PQresultStatus(%s)\n",_con,PQresStatus(pqresult));
357 LM_ERR("%p: %s\n",_con,PQresultErrorMessage(CON_RESULT(_con)));
358 if (*_res) {
359 db_free_result(*_res);
360 *_res = 0;
361 }
362 return -3;
363
364 case PGRES_EMPTY_QUERY:
365 /* notice or warning */
366 case PGRES_NONFATAL_ERROR:
367 /* status for COPY command, not used */
368 case PGRES_COPY_OUT:
369 case PGRES_COPY_IN:

Callers

nothing calls this directly

Calls 5

db_free_resultFunction · 0.85
db_new_resultFunction · 0.85
db_postgres_get_columnsFunction · 0.85
db_free_rowsFunction · 0.85
db_postgres_convert_rowsFunction · 0.85

Tested by

no test coverage detected