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