xref: /PHP-5.5/ext/odbc/php_odbc_includes.h (revision e09febb2)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 5                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2015 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 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 	int id;
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_result {
237 	ODBC_SQL_STMT_T stmt;
238 	odbc_result_value *values;
239 	SQLSMALLINT numcols;
240 	SQLSMALLINT numparams;
241 # if HAVE_SQL_EXTENDED_FETCH
242 	int fetch_abs;
243 # endif
244 	long longreadlen;
245 	int binmode;
246 	int fetched;
247 	odbc_connection *conn_ptr;
248 } odbc_result;
249 
250 ZEND_BEGIN_MODULE_GLOBALS(odbc)
251 	char *defDB;
252 	char *defUser;
253 	char *defPW;
254 	long allow_persistent;
255 	long check_persistent;
256 	long max_persistent;
257 	long max_links;
258 	long num_persistent;
259 	long num_links;
260 	int defConn;
261     long defaultlrl;
262     long defaultbinmode;
263     long default_cursortype;
264     char laststate[6];
265     char lasterrormsg[SQL_MAX_MESSAGE_LENGTH];
266 	HashTable *resource_list;
267 	HashTable *resource_plist;
268 ZEND_END_MODULE_GLOBALS(odbc)
269 
270 int odbc_add_result(HashTable *list, odbc_result *result);
271 odbc_result *odbc_get_result(HashTable *list, int count);
272 void odbc_del_result(HashTable *list, int count);
273 int odbc_add_conn(HashTable *list, HDBC conn);
274 odbc_connection *odbc_get_conn(HashTable *list, int count);
275 void odbc_del_conn(HashTable *list, int ind);
276 int odbc_bindcols(odbc_result *result TSRMLS_DC);
277 
278 #define ODBC_SQL_ERROR_PARAMS odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, char *func
279 
280 void odbc_sql_error(ODBC_SQL_ERROR_PARAMS);
281 
282 #if defined(ODBCVER) && (ODBCVER >= 0x0300)
283 #define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR || x == SQL_WLONGVARCHAR)
284 
285 #define PHP_ODBC_SQLCOLATTRIBUTE SQLColAttribute
286 #define PHP_ODBC_SQLALLOCSTMT(hdbc, phstmt) SQLAllocHandle(SQL_HANDLE_STMT, hdbc, phstmt)
287 
288 #define PHP_ODBC_SQL_DESC_NAME SQL_DESC_NAME
289 #else
290 #define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR)
291 
292 #define PHP_ODBC_SQLCOLATTRIBUTE SQLColAttributes
293 #define PHP_ODBC_SQLALLOCSTMT SQLAllocStmt
294 
295 #define PHP_ODBC_SQL_DESC_NAME SQL_COLUMN_NAME
296 #endif
297 #define IS_SQL_BINARY(x) (x == SQL_BINARY || x == SQL_VARBINARY || x == SQL_LONGVARBINARY)
298 
299 #ifdef ZTS
300 # define ODBCG(v) TSRMG(odbc_globals_id, zend_odbc_globals *, v)
301 #else
302 # define ODBCG(v) (odbc_globals.v)
303 extern ZEND_API zend_odbc_globals odbc_globals;
304 #endif
305 
306 #endif /* HAVE_UODBC */
307 #endif /* PHP_ODBC_INCLUDES_H */
308 
309 /*
310  * Local variables:
311  * tab-width: 4
312  * c-basic-offset: 4
313  * End:
314  */
315