xref: /php-src/ext/odbc/php_odbc_includes.h (revision 365e2118)
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 
19 #ifndef PHP_ODBC_INCLUDES_H
20 #define PHP_ODBC_INCLUDES_H
21 
22 #ifdef HAVE_UODBC
23 
24 /* checking in the same order as in configure.ac */
25 
26 #if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) || defined(HAVE_SOLID_35) /* Solid Server */
27 
28 #define ODBC_TYPE "Solid"
29 #if defined(HAVE_SOLID)
30 # include <cli0core.h>
31 # include <cli0ext1.h>
32 # include <cli0env.h>
33 #elif defined(HAVE_SOLID_30)
34 # include <cli0cli.h>
35 # include <cli0defs.h>
36 # include <cli0env.h>
37 #elif defined(HAVE_SOLID_35)
38 # include <sqlunix.h>
39 # include <sqltypes.h>
40 # include <sqlucode.h>
41 # include <sqlext.h>
42 # include <sql.h>
43 #endif	/* end: #if defined(HAVE_SOLID) */
44 #undef HAVE_SQL_EXTENDED_FETCH
45 #define SQLSMALLINT SWORD
46 #define SQLUSMALLINT UWORD
47 #ifndef SQL_SUCCEEDED
48 #define SQL_SUCCEEDED(rc) (((rc)&(~1))==0)
49 #endif
50 
51 #elif defined(HAVE_EMPRESS) /* Empress */
52 
53 #define ODBC_TYPE "Empress"
54 #include <sql.h>
55 #include <sqlext.h>
56 #undef HAVE_SQL_EXTENDED_FETCH
57 
58 #elif defined(HAVE_ADABAS) /* Adabas D */
59 
60 #define ODBC_TYPE "Adabas D"
61 #include <WINDOWS.H>
62 #include <sql.h>
63 #include <sqlext.h>
64 #define HAVE_SQL_EXTENDED_FETCH 1
65 #define SQL_SUCCEEDED(rc) (((rc)&(~1))==0)
66 #define SQLINTEGER ULONG
67 #define SQLUSMALLINT USHORT
68 
69 #elif defined(HAVE_SAPDB) /* SAP DB */
70 
71 #define ODBC_TYPE "SAP DB"
72 #include <WINDOWS.H>
73 #include <sql.h>
74 #include <sqlext.h>
75 #define HAVE_SQL_EXTENDED_FETCH 1
76 #define SQL_SUCCEEDED(rc) (((rc)&(~1))==0)
77 
78 #elif defined(HAVE_IODBC) /* iODBC library */
79 
80 #ifdef CHAR
81 #undef CHAR
82 #endif
83 
84 #ifdef SQLCHAR
85 #undef SQLCHAR
86 #endif
87 
88 #define ODBC_TYPE "iODBC"
89 #include <sql.h>
90 #include <sqlext.h>
91 #include <iodbcext.h>
92 #define HAVE_SQL_EXTENDED_FETCH 1
93 
94 #elif defined(HAVE_UNIXODBC) /* unixODBC library */
95 
96 #ifdef CHAR
97 #undef CHAR
98 #endif
99 
100 #ifdef SQLCHAR
101 #undef SQLCHAR
102 #endif
103 
104 #define ODBC_TYPE "unixODBC"
105 #undef ODBCVER
106 #include <sql.h>
107 #include <sqlext.h>
108 #define HAVE_SQL_EXTENDED_FETCH 1
109 
110 #elif defined(HAVE_ESOOB) /* Easysoft ODBC-ODBC Bridge library */
111 
112 #define ODBC_TYPE "ESOOB"
113 #include <sql.h>
114 #include <sqlext.h>
115 #define HAVE_SQL_EXTENDED_FETCH 1
116 
117 #elif defined(HAVE_OPENLINK) /* OpenLink ODBC drivers */
118 
119 #define ODBC_TYPE "Openlink"
120 #include <iodbc.h>
121 #include <isql.h>
122 #include <isqlext.h>
123 #include <udbcext.h>
124 #define HAVE_SQL_EXTENDED_FETCH 1
125 #ifndef SQLSMALLINT
126 #define SQLSMALLINT SWORD
127 #endif
128 #ifndef SQLUSMALLINT
129 #define SQLUSMALLINT UWORD
130 #endif
131 
132 #elif defined(HAVE_DBMAKER) /* DBMaker */
133 
134 #define ODBC_TYPE "DBMaker"
135 #undef ODBCVER
136 #define ODBCVER 0x0300
137 #define HAVE_SQL_EXTENDED_FETCH 1
138 #include <odbc.h>
139 
140 
141 #elif defined(HAVE_CODBC) /* Custom ODBC */
142 
143 #define ODBC_TYPE "Custom ODBC"
144 #define HAVE_SQL_EXTENDED_FETCH 1
145 #include <odbc.h>
146 
147 #elif defined(HAVE_IBMDB2) /* DB2 CLI */
148 
149 #define ODBC_TYPE "IBM DB2 CLI"
150 #define HAVE_SQL_EXTENDED_FETCH 1
151 #include <sqlcli1.h>
152 #ifdef DB268K
153 /* Need to include ASLM for 68K applications */
154 #include <LibraryManager.h>
155 #endif
156 
157 #else /* MS ODBC */
158 
159 #define HAVE_SQL_EXTENDED_FETCH 1
160 #include <WINDOWS.H>
161 #include <sql.h>
162 #include <sqlext.h>
163 #endif
164 
165 #ifdef PHP_WIN32
166 #include <winsock2.h>
167 
168 #define ODBC_TYPE "Win32"
169 #define PHP_ODBC_TYPE ODBC_TYPE
170 
171 #endif
172 
173 /* Common defines */
174 
175 #if defined( HAVE_IBMDB2 ) || defined( HAVE_UNIXODBC ) || defined (HAVE_IODBC)
176 #define ODBC_SQL_ENV_T SQLHANDLE
177 #define ODBC_SQL_CONN_T SQLHANDLE
178 #define ODBC_SQL_STMT_T SQLHANDLE
179 #elif defined( HAVE_SOLID_35 ) || defined( HAVE_SAPDB ) || defined ( HAVE_EMPRESS )
180 #define ODBC_SQL_ENV_T SQLHENV
181 #define ODBC_SQL_CONN_T SQLHDBC
182 #define ODBC_SQL_STMT_T SQLHSTMT
183 #else
184 #define ODBC_SQL_ENV_T HENV
185 #define ODBC_SQL_CONN_T HDBC
186 #define ODBC_SQL_STMT_T HSTMT
187 #endif
188 
189 typedef struct odbc_connection {
190     ODBC_SQL_ENV_T henv;
191     ODBC_SQL_CONN_T hdbc;
192     char laststate[6];
193     char lasterrormsg[SQL_MAX_MESSAGE_LENGTH];
194 	zend_resource *res;
195 	int persistent;
196 } odbc_connection;
197 
198 typedef struct odbc_result_value {
199 	char name[256];
200 	char *value;
201 	SQLLEN vallen;
202 	SQLLEN coltype;
203 } odbc_result_value;
204 
205 typedef struct odbc_param_info {
206 	SQLSMALLINT sqltype;
207 	SQLSMALLINT scale;
208 	SQLSMALLINT nullable;
209 	SQLULEN precision;
210 } odbc_param_info;
211 
212 typedef struct odbc_result {
213 	ODBC_SQL_STMT_T stmt;
214 	odbc_result_value *values;
215 	SQLSMALLINT numcols;
216 	SQLSMALLINT numparams;
217 # if HAVE_SQL_EXTENDED_FETCH
218 	int fetch_abs;
219 # endif
220 	zend_long longreadlen;
221 	int binmode;
222 	int fetched;
223 	odbc_param_info * param_info;
224 	odbc_connection *conn_ptr;
225 } odbc_result;
226 
227 ZEND_BEGIN_MODULE_GLOBALS(odbc)
228 	char *defDB;
229 	char *defUser;
230 	char *defPW;
231 	bool allow_persistent;
232 	bool check_persistent;
233 	zend_long max_persistent;
234 	zend_long max_links;
235 	zend_long num_persistent;
236 	zend_long num_links;
237 	int defConn;
238     zend_long defaultlrl;
239     zend_long defaultbinmode;
240     zend_long default_cursortype;
241     char laststate[6];
242     char lasterrormsg[SQL_MAX_MESSAGE_LENGTH];
243 	HashTable *resource_list;
244 	HashTable *resource_plist;
245 ZEND_END_MODULE_GLOBALS(odbc)
246 
247 int odbc_add_result(HashTable *list, odbc_result *result);
248 odbc_result *odbc_get_result(HashTable *list, int count);
249 void odbc_del_result(HashTable *list, int count);
250 int odbc_add_conn(HashTable *list, HDBC conn);
251 odbc_connection *odbc_get_conn(HashTable *list, int count);
252 void odbc_del_conn(HashTable *list, int ind);
253 void odbc_bindcols(odbc_result *result);
254 
255 #define ODBC_SQL_ERROR_PARAMS odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, char *func
256 
257 void odbc_sql_error(ODBC_SQL_ERROR_PARAMS);
258 
259 #if defined(ODBCVER) && (ODBCVER >= 0x0300)
260 #define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR || x == SQL_WLONGVARCHAR)
261 
262 #define PHP_ODBC_SQLCOLATTRIBUTE SQLColAttribute
263 #define PHP_ODBC_SQLALLOCSTMT(hdbc, phstmt) SQLAllocHandle(SQL_HANDLE_STMT, hdbc, phstmt)
264 
265 #define PHP_ODBC_SQL_DESC_NAME SQL_DESC_NAME
266 #else
267 #define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR)
268 
269 #define PHP_ODBC_SQLCOLATTRIBUTE SQLColAttributes
270 #define PHP_ODBC_SQLALLOCSTMT SQLAllocStmt
271 
272 #define PHP_ODBC_SQL_DESC_NAME SQL_COLUMN_NAME
273 #endif
274 #define IS_SQL_BINARY(x) (x == SQL_BINARY || x == SQL_VARBINARY || x == SQL_LONGVARBINARY)
275 
276 PHP_ODBC_API ZEND_EXTERN_MODULE_GLOBALS(odbc)
277 #define ODBCG(v) ZEND_MODULE_GLOBALS_ACCESSOR(odbc, v)
278 
279 #if defined(ZTS) && defined(COMPILE_DL_ODBC)
280 ZEND_TSRMLS_CACHE_EXTERN()
281 #endif
282 
283 #endif /* HAVE_UODBC */
284 #endif /* PHP_ODBC_INCLUDES_H */
285