km_pg_con.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * $Id$
  3. *
  4. * POSTGRES module, portions of this code were templated using
  5. * the mysql module, thus it's similarity.
  6. *
  7. * Copyright (C) 2003 August.Net Services, LLC
  8. *
  9. * This file is part of openser, a free SIP server.
  10. *
  11. * openser is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version
  15. *
  16. * openser is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. * ---
  26. *
  27. * History
  28. * -------
  29. * 2003-04-06 initial code written (Greg Fausak/Andy Fullford)
  30. *
  31. */
  32. #ifndef PG_CON_H
  33. #define PG_CON_H
  34. #include "../../db/db_pool.h"
  35. #include "../../db/db_id.h"
  36. #include <time.h>
  37. #include <libpq-fe.h>
  38. /*
  39. * Postgres specific connection data
  40. */
  41. struct pg_con {
  42. struct db_id* id; /* Connection identifier */
  43. unsigned int ref; /* Reference count */
  44. struct pool_con* next; /* Next connection in the pool */
  45. int connected;
  46. char *sqlurl; /* the url we are connected to, all connection memory parents from this */
  47. PGconn *con; /* this is the postgres connection */
  48. PGresult *res; /* this is the current result */
  49. char** row; /* Actual row in the result */
  50. time_t timestamp; /* Timestamp of last query */
  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. /*
  60. * Create a new connection structure,
  61. * open the PostgreSQL connection and set reference count to 1
  62. */
  63. struct pg_con* db_postgres_new_connection(struct db_id* id);
  64. /*
  65. * Close the connection and release memory
  66. */
  67. void db_postgres_free_connection(struct pool_con* con);
  68. #endif /* PG_CON_H */