km_my_con.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  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. /*! \file
  24. * \brief DB_MYSQL :: Core
  25. * \ref my_con.c
  26. * \ingroup db_mysql
  27. * Module: \ref db_mysql
  28. */
  29. #ifndef KM_MY_CON_H
  30. #define KM_MY_CON_H
  31. #include "../../lib/srdb1/db_pool.h"
  32. #include "../../lib/srdb1/db_id.h"
  33. #include <time.h>
  34. #include <mysql/mysql.h>
  35. struct my_con {
  36. struct db_id* id; /*!< Connection identifier */
  37. unsigned int ref; /*!< Reference count */
  38. struct pool_con* next; /*!< Next connection in the pool */
  39. MYSQL* con; /*!< Connection representation */
  40. time_t timestamp; /*!< Timestamp of last query */
  41. int transaction; /*!< Multi-query transaction is currently open */
  42. int lockedtables; /*!< Table locks were aquired */
  43. };
  44. /*
  45. * Some convenience wrappers
  46. */
  47. #define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->con)
  48. #define CON_TIMESTAMP(db_con) (((struct my_con*)((db_con)->tail))->timestamp)
  49. #define CON_TRANSACTION(db_con) (((struct my_con*)((db_con)->tail))->transaction)
  50. #define CON_LOCKEDTABLES(db_con) (((struct my_con*)((db_con)->tail))->lockedtables)
  51. /*! \brief
  52. * Create a new connection structure,
  53. * open the MySQL connection and set reference count to 1
  54. */
  55. struct my_con* db_mysql_new_connection(const struct db_id* id);
  56. /*! \brief
  57. * Close the connection and release memory
  58. */
  59. void db_mysql_free_connection(struct pool_con* con);
  60. #endif /* KM_MY_CON_H */