connection.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 "../../lib/srdb1/db_val.h"
  35. #include <time.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <sql.h>
  39. #include <sqlext.h>
  40. #include <sqlucode.h>
  41. #define STRN_LEN 1024
  42. typedef struct strn
  43. {
  44. unsigned int buflen;
  45. char *s;
  46. } strn;
  47. struct my_con
  48. {
  49. struct db_id* id; /*!< Connection identifier */
  50. unsigned int ref; /*!< Reference count */
  51. struct pool_con* next; /*!< Next connection in the pool */
  52. SQLHENV env; /*!< Environment handle */
  53. SQLHSTMT stmt_handle; /*!< Actual result */
  54. SQLHDBC dbc; /*!< Connection representation */
  55. char** row; /*!< Actual row in the result */
  56. time_t timestamp; /*!< Timestamp of last query */
  57. };
  58. /*
  59. * Some convenience wrappers
  60. */
  61. #define CON_RESULT(db_con) (((struct my_con*)((db_con)->tail))->stmt_handle)
  62. #define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->dbc)
  63. #define CON_ROW(db_con) (((struct my_con*)((db_con)->tail))->row)
  64. #define CON_TIMESTAMP(db_con) (((struct my_con*)((db_con)->tail))->timestamp)
  65. #define CON_ID(db_con) (((struct my_con*)((db_con)->tail))->id)
  66. #define CON_ENV(db_con) (((struct my_con*)((db_con)->tail))->env)
  67. #define MAX_CONN_STR_LEN 2048
  68. /*
  69. * Create a new connection structure,
  70. * open the UNIXODBC connection and set reference count to 1
  71. */
  72. struct my_con* db_unixodbc_new_connection(struct db_id* id);
  73. /*
  74. * Close the connection and release memory
  75. */
  76. void db_unixodbc_free_connection(struct my_con* con);
  77. char *db_unixodbc_build_conn_str(const struct db_id* id, char *buf);
  78. void db_unixodbc_extract_error(const char *fn, const SQLHANDLE handle, const SQLSMALLINT type, char* stret);
  79. /*
  80. * Allocate a new row of cells, without any data
  81. */
  82. strn * db_unixodbc_new_cellrow(size_t ncols);
  83. /*
  84. * Free row of cells and all associated memory
  85. */
  86. void db_unixodbc_free_cellrow(size_t ncols, strn * row);
  87. /*
  88. * Load ODBC cell data into a single cell
  89. */
  90. int db_unixodbc_load_cell(const db1_con_t* _h, int colindex, strn * cell, const db_type_t _t);
  91. #endif /* MY_CON_H */