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