pg_con.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #ifndef _PG_CON_H
  31. #define _PG_CON_H
  32. /** \addtogroup postgres
  33. * @{
  34. */
  35. /** \file
  36. * Implementation of PostgreSQL connection related data structures and functions.
  37. */
  38. #include "pg_oid.h"
  39. #include "../../lib/srdb2/db_pool.h"
  40. #include "../../lib/srdb2/db_con.h"
  41. #include "../../lib/srdb2/db_uri.h"
  42. #include <time.h>
  43. #include <libpq-fe.h>
  44. /**
  45. * Per-connection flags for PostgreSQL connections.
  46. */
  47. enum pg_con_flags {
  48. PG_CONNECTED = (1 << 0), /**< The connection has been connected successfully */
  49. PG_INT8_TIMESTAMP = (1 << 1) /**< The server uses 8-byte integer format for timestamps */
  50. };
  51. /** A structure representing a connection to PostgreSQL server.
  52. * This structure represents connections to PostgreSQL servers. It contains
  53. * PostgreSQL specific data, such as PostgreSQL connection handle, connection
  54. * flags, and an array with data types supported by the server.
  55. */
  56. typedef struct pg_con {
  57. db_pool_entry_t gen; /**< Generic part of the structure */
  58. PGconn* con; /**< Postgres connection handle */
  59. unsigned int flags; /**< Flags (currently only binary data format) */
  60. pg_type_t* oid; /**< Data types and their Oids obtained from the server */
  61. } pg_con_t;
  62. /** Create a new pg_con structure.
  63. * This function creates a new pg_con structure and attachs the structure to
  64. * the generic db_con structure in the parameter.
  65. * @param con A generic db_con structure to be extended with PostgreSQL
  66. * payload
  67. * @retval 0 on success
  68. * @retval A negative number on error
  69. */
  70. int pg_con(db_con_t* con);
  71. /** Establish a new connection to server.
  72. * This function is called when a SER module calls db_connect to establish a
  73. * new connection to the database server. After the connection is established
  74. * the function sends an SQL query to the server to determine the format of
  75. * timestamp fields and also obtains the list of supported field types.
  76. * @param con A structure representing database connection.
  77. * @retval 0 on success.
  78. * @retval A negative number on error.
  79. */
  80. int pg_con_connect(db_con_t* con);
  81. /** Disconnected from PostgreSQL server.
  82. * Disconnects a previously connected connection to PostgreSQL server.
  83. * @param con A structure representing the connection to be disconnected.
  84. */
  85. void pg_con_disconnect(db_con_t* con);
  86. /** @} */
  87. #endif /* _PG_CON_H */