2
0

con.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * $Id$
  3. *
  4. * UNIXODBC module
  5. *
  6. * Copyright (C) 2005-2006 Marco Lorrai
  7. * Copyright (C) 2008 1&1 Internet AG
  8. *
  9. * This file is part of Kamailio, a free SIP server.
  10. *
  11. * Kamailio 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. * Kamailio 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. * History:
  27. * --------
  28. * 2005-12-01 initial commit (chgen)
  29. */
  30. #ifndef MY_CON_H
  31. #define MY_CON_H
  32. #include "../../lib/srdb1/db_pool.h"
  33. #include "../../lib/srdb1/db_id.h"
  34. #include <time.h>
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <sql.h>
  38. #include <sqlext.h>
  39. #include <sqlucode.h>
  40. #define STRN_LEN 1024
  41. typedef struct strn
  42. {
  43. char s[STRN_LEN];
  44. } strn;
  45. struct my_con
  46. {
  47. struct db_id* id; /*!< Connection identifier */
  48. unsigned int ref; /*!< Reference count */
  49. struct pool_con* next; /*!< Next connection in the pool */
  50. SQLHENV env; /*!< Environment handle */
  51. SQLHSTMT stmt_handle; /*!< Actual result */
  52. SQLHDBC dbc; /*!< Connection representation */
  53. char** row; /*!< Actual row in the result */
  54. time_t timestamp; /*!< Timestamp of last query */
  55. };
  56. /*
  57. * Some convenience wrappers
  58. */
  59. #define CON_RESULT(db_con) (((struct my_con*)((db_con)->tail))->stmt_handle)
  60. #define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->dbc)
  61. #define CON_ROW(db_con) (((struct my_con*)((db_con)->tail))->row)
  62. #define CON_TIMESTAMP(db_con) (((struct my_con*)((db_con)->tail))->timestamp)
  63. #define CON_ID(db_con) (((struct my_con*)((db_con)->tail))->id)
  64. #define CON_ENV(db_con) (((struct my_con*)((db_con)->tail))->env)
  65. #define MAX_CONN_STR_LEN 2048
  66. /*
  67. * Create a new connection structure,
  68. * open the UNIXODBC connection and set reference count to 1
  69. */
  70. struct my_con* db_unixodbc_new_connection(struct db_id* id);
  71. /*
  72. * Close the connection and release memory
  73. */
  74. void db_unixodbc_free_connection(struct my_con* con);
  75. char *db_unixodbc_build_conn_str(const struct db_id* id, char *buf);
  76. void db_unixodbc_extract_error(const char *fn, const SQLHANDLE handle, const SQLSMALLINT type, char* stret);
  77. #endif /* MY_CON_H */