src/modules/db_postgres/pg_res.c
7c1f066c
 /* 
9b411f76
  * PostgreSQL Database Driver for Kamailio
7c1f066c
  *
  * Portions Copyright (C) 2001-2003 FhG FOKUS
  * Copyright (C) 2003 August.Net Services, LLC
  * Portions Copyright (C) 2005-2008 iptelorg GmbH
  *
9b411f76
  * This file is part of Kamailio, a free SIP server.
7c1f066c
  *
9b411f76
  * Kamailio is free software; you can redistribute it and/or modify it under the
7c1f066c
  * terms of the GNU General Public License as published by the Free Software
  * Foundation; either version 2 of the License, or (at your option) any later
  * version
  *
9b411f76
  * Kamailio is distributed in the hope that it will be useful, but WITHOUT ANY
7c1f066c
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  * details.
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc., 59
  * Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 /** \addtogroup postgres
  * @{ 
  */
 
 /** \file
  * Functions working with result structures received from PostgreSQL servers.
  */
 
 #include "pg_res.h"
 #include "pg_cmd.h"
 
cf83221d
 #include "../../core/mem/mem.h"
 #include "../../core/dprint.h"
b372a105
 #include "../../lib/srdb2/db_gen.h"
7c1f066c
 
 
60f177bf
 static void pg_res_free(db_res_t *res, struct pg_res *payload)
7c1f066c
 {
 	db_drv_free(&payload->gen);
60f177bf
 	if(payload->res)
 		PQclear(payload->res);
7c1f066c
 	pkg_free(payload);
 }
 
 
60f177bf
 int pg_res(db_res_t *res)
7c1f066c
 {
60f177bf
 	struct pg_res *pres;
7c1f066c
 
60f177bf
 	pres = (struct pg_res *)pkg_malloc(sizeof(struct pg_res));
 	if(pres == NULL) {
b79423f9
 		PKG_MEM_ERROR;
7c1f066c
 		return -1;
 	}
60f177bf
 	if(db_drv_init(&pres->gen, pg_res_free) < 0)
 		goto error;
7c1f066c
 	DB_SET_PAYLOAD(res, pres);
 	return 0;
60f177bf
 
 error:
 	if(pres) {
7c1f066c
 		db_drv_free(&pres->gen);
 		pkg_free(pres);
 	}
 	return -1;
 }
 
 /** @} */