pg_res.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * $Id$
  3. *
  4. * PostgreSQL Database Driver for SER
  5. *
  6. * Portions Copyright (C) 2001-2003 FhG FOKUS
  7. * Copyright (C) 2003 August.Net Services, LLC
  8. * Portions Copyright (C) 2005-2008 iptelorg GmbH
  9. *
  10. * This file is part of SER, a free SIP server.
  11. *
  12. * SER is free software; you can redistribute it and/or modify it under the
  13. * terms of the GNU General Public License as published by the Free Software
  14. * Foundation; either version 2 of the License, or (at your option) any later
  15. * version
  16. *
  17. * For a license to use the ser software under conditions other than those
  18. * described here, or to purchase support for this software, please contact
  19. * iptel.org by e-mail at the following addresses: [email protected]
  20. *
  21. * SER is distributed in the hope that it will be useful, but WITHOUT ANY
  22. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  23. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  24. * details.
  25. *
  26. * You should have received a copy of the GNU General Public License along
  27. * with this program; if not, write to the Free Software Foundation, Inc., 59
  28. * Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. /** \addtogroup postgres
  31. * @{
  32. */
  33. /** \file
  34. * Functions working with result structures received from PostgreSQL servers.
  35. */
  36. #include "pg_res.h"
  37. #include "pg_cmd.h"
  38. #include "../../mem/mem.h"
  39. #include "../../dprint.h"
  40. #include "../../lib/srdb2/db_gen.h"
  41. static void pg_res_free(db_res_t* res, struct pg_res* payload)
  42. {
  43. db_drv_free(&payload->gen);
  44. if (payload->res) PQclear(payload->res);
  45. pkg_free(payload);
  46. }
  47. int pg_res(db_res_t* res)
  48. {
  49. struct pg_res* pres;
  50. pres = (struct pg_res*)pkg_malloc(sizeof(struct pg_res));
  51. if (pres == NULL) {
  52. ERR("postgres: No memory left\n");
  53. return -1;
  54. }
  55. if (db_drv_init(&pres->gen, pg_res_free) < 0) goto error;
  56. DB_SET_PAYLOAD(res, pres);
  57. return 0;
  58. error:
  59. if (pres) {
  60. db_drv_free(&pres->gen);
  61. pkg_free(pres);
  62. }
  63. return -1;
  64. }
  65. /** @} */