php_odbc_includes.h 7.3 KB

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