php_odbc_includes.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Stig Sæther Bakken <ssb@php.net> |
  14. | Andreas Karajannis <Andreas.Karajannis@gmd.de> |
  15. | Kevin N. Shallow <kshallow@tampabay.rr.com> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifndef PHP_ODBC_INCLUDES_H
  19. #define PHP_ODBC_INCLUDES_H
  20. #ifdef HAVE_UODBC
  21. /* checking in the same order as in configure.ac */
  22. #if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) || defined(HAVE_SOLID_35) /* Solid Server */
  23. #define ODBC_TYPE "Solid"
  24. #if defined(HAVE_SOLID)
  25. # include <cli0core.h>
  26. # include <cli0ext1.h>
  27. # include <cli0env.h>
  28. #elif defined(HAVE_SOLID_30)
  29. # include <cli0cli.h>
  30. # include <cli0defs.h>
  31. # include <cli0env.h>
  32. #elif defined(HAVE_SOLID_35)
  33. # include <sqlunix.h>
  34. # include <sqltypes.h>
  35. # include <sqlucode.h>
  36. # include <sqlext.h>
  37. # include <sql.h>
  38. #endif /* end: #if defined(HAVE_SOLID) */
  39. #undef HAVE_SQL_EXTENDED_FETCH
  40. PHP_FUNCTION(solid_fetch_prev);
  41. #define SQLSMALLINT SWORD
  42. #define SQLUSMALLINT UWORD
  43. #ifndef SQL_SUCCEEDED
  44. #define SQL_SUCCEEDED(rc) (((rc)&(~1))==0)
  45. #endif
  46. #elif defined(HAVE_EMPRESS) /* Empress */
  47. #define ODBC_TYPE "Empress"
  48. #include <sql.h>
  49. #include <sqlext.h>
  50. #undef HAVE_SQL_EXTENDED_FETCH
  51. #elif defined(HAVE_ADABAS) /* Adabas D */
  52. #define ODBC_TYPE "Adabas D"
  53. #include <WINDOWS.H>
  54. #include <sql.h>
  55. #include <sqlext.h>
  56. #define HAVE_SQL_EXTENDED_FETCH 1
  57. #define SQL_SUCCEEDED(rc) (((rc)&(~1))==0)
  58. #define SQLINTEGER ULONG
  59. #define SQLUSMALLINT USHORT
  60. #elif defined(HAVE_SAPDB) /* SAP DB */
  61. #define ODBC_TYPE "SAP DB"
  62. #include <WINDOWS.H>
  63. #include <sql.h>
  64. #include <sqlext.h>
  65. #define HAVE_SQL_EXTENDED_FETCH 1
  66. #define SQL_SUCCEEDED(rc) (((rc)&(~1))==0)
  67. #elif defined(HAVE_IODBC) /* iODBC library */
  68. #ifdef CHAR
  69. #undef CHAR
  70. #endif
  71. #ifdef SQLCHAR
  72. #undef SQLCHAR
  73. #endif
  74. #define ODBC_TYPE "iODBC"
  75. #include <sql.h>
  76. #include <sqlext.h>
  77. #include <iodbcext.h>
  78. #define HAVE_SQL_EXTENDED_FETCH 1
  79. #elif defined(HAVE_UNIXODBC) /* unixODBC library */
  80. #ifdef CHAR
  81. #undef CHAR
  82. #endif
  83. #ifdef SQLCHAR
  84. #undef SQLCHAR
  85. #endif
  86. #define ODBC_TYPE "unixODBC"
  87. #undef ODBCVER
  88. #include <sql.h>
  89. #include <sqlext.h>
  90. #define HAVE_SQL_EXTENDED_FETCH 1
  91. #elif defined(HAVE_ESOOB) /* Easysoft ODBC-ODBC Bridge library */
  92. #define ODBC_TYPE "ESOOB"
  93. #include <sql.h>
  94. #include <sqlext.h>
  95. #define HAVE_SQL_EXTENDED_FETCH 1
  96. #elif defined(HAVE_OPENLINK) /* OpenLink ODBC drivers */
  97. #define ODBC_TYPE "Openlink"
  98. #include <iodbc.h>
  99. #include <isql.h>
  100. #include <isqlext.h>
  101. #include <udbcext.h>
  102. #define HAVE_SQL_EXTENDED_FETCH 1
  103. #ifndef SQLSMALLINT
  104. #define SQLSMALLINT SWORD
  105. #endif
  106. #ifndef SQLUSMALLINT
  107. #define SQLUSMALLINT UWORD
  108. #endif
  109. #elif defined(HAVE_DBMAKER) /* DBMaker */
  110. #define ODBC_TYPE "DBMaker"
  111. #undef ODBCVER
  112. #define ODBCVER 0x0300
  113. #define HAVE_SQL_EXTENDED_FETCH 1
  114. #include <odbc.h>
  115. #elif defined(HAVE_CODBC) /* Custom ODBC */
  116. #define ODBC_TYPE "Custom ODBC"
  117. #define HAVE_SQL_EXTENDED_FETCH 1
  118. #include <odbc.h>
  119. #elif defined(HAVE_IBMDB2) /* DB2 CLI */
  120. #define ODBC_TYPE "IBM DB2 CLI"
  121. #define HAVE_SQL_EXTENDED_FETCH 1
  122. #include <sqlcli1.h>
  123. #ifdef DB268K
  124. /* Need to include ASLM for 68K applications */
  125. #include <LibraryManager.h>
  126. #endif
  127. #else /* MS ODBC */
  128. #define HAVE_SQL_EXTENDED_FETCH 1
  129. #include <WINDOWS.H>
  130. #include <sql.h>
  131. #include <sqlext.h>
  132. #endif
  133. /* Common defines */
  134. #if defined( HAVE_IBMDB2 ) || defined( HAVE_UNIXODBC ) || defined (HAVE_IODBC)
  135. #define ODBC_SQL_ENV_T SQLHANDLE
  136. #define ODBC_SQL_CONN_T SQLHANDLE
  137. #define ODBC_SQL_STMT_T SQLHANDLE
  138. #elif defined( HAVE_SOLID_35 ) || defined( HAVE_SAPDB ) || defined ( HAVE_EMPRESS )
  139. #define ODBC_SQL_ENV_T SQLHENV
  140. #define ODBC_SQL_CONN_T SQLHDBC
  141. #define ODBC_SQL_STMT_T SQLHSTMT
  142. #else
  143. #define ODBC_SQL_ENV_T HENV
  144. #define ODBC_SQL_CONN_T HDBC
  145. #define ODBC_SQL_STMT_T HSTMT
  146. #endif
  147. typedef struct odbc_connection {
  148. ODBC_SQL_ENV_T henv;
  149. ODBC_SQL_CONN_T hdbc;
  150. char laststate[6];
  151. char lasterrormsg[SQL_MAX_MESSAGE_LENGTH];
  152. zend_resource *res;
  153. int persistent;
  154. } odbc_connection;
  155. typedef struct odbc_result_value {
  156. char name[256];
  157. char *value;
  158. SQLLEN vallen;
  159. SQLLEN coltype;
  160. } odbc_result_value;
  161. typedef struct odbc_param_info {
  162. SQLSMALLINT sqltype;
  163. SQLSMALLINT scale;
  164. SQLSMALLINT nullable;
  165. SQLULEN precision;
  166. } odbc_param_info;
  167. typedef struct odbc_result {
  168. ODBC_SQL_STMT_T stmt;
  169. odbc_result_value *values;
  170. SQLSMALLINT numcols;
  171. SQLSMALLINT numparams;
  172. # if HAVE_SQL_EXTENDED_FETCH
  173. int fetch_abs;
  174. # endif
  175. zend_long longreadlen;
  176. int binmode;
  177. int fetched;
  178. odbc_param_info * param_info;
  179. odbc_connection *conn_ptr;
  180. } odbc_result;
  181. ZEND_BEGIN_MODULE_GLOBALS(odbc)
  182. char *defDB;
  183. char *defUser;
  184. char *defPW;
  185. zend_long allow_persistent;
  186. zend_long check_persistent;
  187. zend_long max_persistent;
  188. zend_long max_links;
  189. zend_long num_persistent;
  190. zend_long num_links;
  191. int defConn;
  192. zend_long defaultlrl;
  193. zend_long defaultbinmode;
  194. zend_long default_cursortype;
  195. char laststate[6];
  196. char lasterrormsg[SQL_MAX_MESSAGE_LENGTH];
  197. HashTable *resource_list;
  198. HashTable *resource_plist;
  199. ZEND_END_MODULE_GLOBALS(odbc)
  200. int odbc_add_result(HashTable *list, odbc_result *result);
  201. odbc_result *odbc_get_result(HashTable *list, int count);
  202. void odbc_del_result(HashTable *list, int count);
  203. int odbc_add_conn(HashTable *list, HDBC conn);
  204. odbc_connection *odbc_get_conn(HashTable *list, int count);
  205. void odbc_del_conn(HashTable *list, int ind);
  206. int odbc_bindcols(odbc_result *result);
  207. #define ODBC_SQL_ERROR_PARAMS odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, char *func
  208. void odbc_sql_error(ODBC_SQL_ERROR_PARAMS);
  209. #if defined(ODBCVER) && (ODBCVER >= 0x0300)
  210. #define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR || x == SQL_WLONGVARCHAR)
  211. #define PHP_ODBC_SQLCOLATTRIBUTE SQLColAttribute
  212. #define PHP_ODBC_SQLALLOCSTMT(hdbc, phstmt) SQLAllocHandle(SQL_HANDLE_STMT, hdbc, phstmt)
  213. #define PHP_ODBC_SQL_DESC_NAME SQL_DESC_NAME
  214. #else
  215. #define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR)
  216. #define PHP_ODBC_SQLCOLATTRIBUTE SQLColAttributes
  217. #define PHP_ODBC_SQLALLOCSTMT SQLAllocStmt
  218. #define PHP_ODBC_SQL_DESC_NAME SQL_COLUMN_NAME
  219. #endif
  220. #define IS_SQL_BINARY(x) (x == SQL_BINARY || x == SQL_VARBINARY || x == SQL_LONGVARBINARY)
  221. PHP_ODBC_API ZEND_EXTERN_MODULE_GLOBALS(odbc)
  222. #define ODBCG(v) ZEND_MODULE_GLOBALS_ACCESSOR(odbc, v)
  223. #if defined(ZTS) && defined(COMPILE_DL_ODBC)
  224. ZEND_TSRMLS_CACHE_EXTERN()
  225. #endif
  226. #endif /* HAVE_UODBC */
  227. #endif /* PHP_ODBC_INCLUDES_H */