km_pg_con.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2003 August.Net Services, LLC
  5. * Copyright (C) 2008 1&1 Internet AG
  6. *
  7. * This file is part of Kamailio, a free SIP server.
  8. *
  9. * Kamailio 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. * Kamailio 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. * History
  24. * -------
  25. * 2003-04-06 initial code written (Greg Fausak/Andy Fullford)
  26. */
  27. /*! \file
  28. * \brief DB_POSTGRES :: Core
  29. * \ingroup db_postgres
  30. * Module: \ref db_mysql
  31. */
  32. #ifndef KM_PG_CON_H
  33. #define KM_PG_CON_H
  34. #include "../../lib/srdb1/db_pool.h"
  35. #include "../../lib/srdb1/db_id.h"
  36. #include <time.h>
  37. #include <libpq-fe.h>
  38. /*! Postgres specific connection data */
  39. struct pg_con {
  40. struct db_id* id; /*!< Connection identifier */
  41. unsigned int ref; /*!< Reference count */
  42. struct pool_con* next; /*!< Next connection in the pool */
  43. int connected; /*!< connection status */
  44. char *sqlurl; /*!< the url we are connected to, all connection memory parents from this */
  45. PGconn *con; /*!< this is the postgres connection */
  46. PGresult *res; /*!< this is the current result */
  47. char** row; /*!< Actual row in the result */
  48. time_t timestamp; /*!< Timestamp of last query */
  49. int affected_rows; /*!< Number of rows affected by the last statement */
  50. int transaction; /*!< indicates whether a multi-query transaction is currently open */
  51. };
  52. #define CON_SQLURL(db_con) (((struct pg_con*)((db_con)->tail))->sqlurl)
  53. #define CON_RESULT(db_con) (((struct pg_con*)((db_con)->tail))->res)
  54. #define CON_CONNECTION(db_con) (((struct pg_con*)((db_con)->tail))->con)
  55. #define CON_CONNECTED(db_con) (((struct pg_con*)((db_con)->tail))->connected)
  56. #define CON_ROW(db_con) (((struct pg_con*)((db_con)->tail))->row)
  57. #define CON_TIMESTAMP(db_con) (((struct pg_con*)((db_con)->tail))->timestamp)
  58. #define CON_ID(db_con) (((struct pg_con*)((db_con)->tail))->id)
  59. #define CON_AFFECTED(db_con) (((struct pg_con*)((db_con)->tail))->affected_rows)
  60. #define CON_TRANSACTION(db_con) (((struct pg_con*)((db_con)->tail))->transaction)
  61. /*
  62. * Create a new connection structure,
  63. * open the PostgreSQL connection and set reference count to 1
  64. */
  65. struct pg_con* db_postgres_new_connection(struct db_id* id);
  66. /*
  67. * Close the connection and release memory
  68. */
  69. void db_postgres_free_connection(struct pool_con* con);
  70. #endif /* KM_PG_CON_H */