bdb_res.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. * Copyright (C) 2006-2007 iptelorg GmbH
  6. *
  7. * This file is part of SIP-router, a free SIP server.
  8. *
  9. * SIP-router is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * SIP-router is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*! \file
  24. * Berkeley DB :
  25. *
  26. * \ingroup database
  27. */
  28. #include <db.h>
  29. #include "bdb_res.h"
  30. #include "bdb_cmd.h"
  31. #include "bdb_crs_compat.h"
  32. #include "../../mem/mem.h"
  33. #include "../../dprint.h"
  34. #include "../../lib/srdb2/db_gen.h"
  35. void bdb_res_free(db_res_t* res, bdb_res_t *payload)
  36. {
  37. bdb_cmd_t *bcmd;
  38. bcmd = DB_GET_PAYLOAD(res->cmd);
  39. /* free bdb result */
  40. if(bcmd->dbcp!=NULL)
  41. {
  42. bcmd->dbcp->CLOSE_CURSOR(bcmd->dbcp);
  43. bcmd->dbcp = NULL;
  44. }
  45. db_drv_free(&payload->gen);
  46. pkg_free(payload);
  47. }
  48. /*
  49. * Attach bdb specific structure to db_res, this structure contains a pointer
  50. * to bdb_res_free which releases the result stored in the oracle statement
  51. * and if there is a cursor open in the statement then it will be closed as well
  52. */
  53. int bdb_res(db_res_t* res)
  54. {
  55. bdb_res_t *br;
  56. br = (bdb_res_t*)pkg_malloc(sizeof(bdb_res_t));
  57. if (br == NULL) {
  58. ERR("bdb: No memory left\n");
  59. return -1;
  60. }
  61. if (db_drv_init(&br->gen, bdb_res_free) < 0) goto error;
  62. DB_SET_PAYLOAD(res, br);
  63. return 0;
  64. error:
  65. if (br) {
  66. db_drv_free(&br->gen);
  67. pkg_free(br);
  68. }
  69. return -1;
  70. }