xref: /php-src/ext/odbc/php_odbc_includes.h (revision 5d3fab93)
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 	HashTable results;
195 } odbc_connection;
196 
197 typedef struct odbc_link {
198 	odbc_connection *connection;
199 	zend_string *hash;
200 	bool persistent;
201 	zend_object std;
202 } odbc_link;
203 
204 typedef struct odbc_result_value {
205 	char name[256];
206 	char *value;
207 	SQLLEN vallen;
208 	SQLLEN coltype;
209 } odbc_result_value;
210 
211 typedef struct odbc_param_info {
212 	SQLSMALLINT sqltype;
213 	SQLSMALLINT scale;
214 	SQLSMALLINT nullable;
215 	SQLULEN precision;
216 } odbc_param_info;
217 
218 typedef struct odbc_result {
219 	ODBC_SQL_STMT_T stmt;
220 	odbc_result_value *values;
221 	SQLSMALLINT numcols;
222 	SQLSMALLINT numparams;
223 # ifdef HAVE_SQL_EXTENDED_FETCH
224 	int fetch_abs;
225 # endif
226 	zend_long longreadlen;
227 	int binmode;
228 	int fetched;
229 	odbc_param_info *param_info;
230 	odbc_connection *conn_ptr;
231 	uint32_t index;
232 	zend_object std;
233 } odbc_result;
234 
235 ZEND_BEGIN_MODULE_GLOBALS(odbc)
236 	bool allow_persistent;
237 	bool check_persistent;
238 	zend_long max_persistent;
239 	zend_long max_links;
240 	zend_long num_persistent;
241 	zend_long num_links;
242 	int defConn;
243     zend_long defaultlrl;
244     zend_long defaultbinmode;
245     zend_long default_cursortype;
246     char laststate[6];
247     char lasterrormsg[SQL_MAX_MESSAGE_LENGTH];
248 	/* Stores ODBC links throughout the duration of a request. The connection member may be either persistent or
249 	 * non-persistent. In the former case, it is a pointer to an item in EG(persistent_list). This solution makes it
250 	 * possible to properly free links during RSHUTDOWN (or when they are explicitly closed), while persistent
251 	 * connections themselves are going to be freed later during the shutdown process (or when they are explicitly
252 	 * closed).
253 	 */
254 	HashTable connections;
255 ZEND_END_MODULE_GLOBALS(odbc)
256 
257 int odbc_add_result(HashTable *list, odbc_result *result);
258 odbc_result *odbc_get_result(HashTable *list, int count);
259 void odbc_del_result(HashTable *list, int count);
260 int odbc_add_conn(HashTable *list, HDBC conn);
261 odbc_connection *odbc_get_conn(HashTable *list, int count);
262 void odbc_del_conn(HashTable *list, int ind);
263 void odbc_bindcols(odbc_result *result);
264 
265 #define ODBC_SQL_ERROR_PARAMS odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, char *func
266 
267 void odbc_sql_error(ODBC_SQL_ERROR_PARAMS);
268 
269 #if defined(ODBCVER) && (ODBCVER >= 0x0300)
270 #define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR || x == SQL_WLONGVARCHAR)
271 
272 #define PHP_ODBC_SQLCOLATTRIBUTE SQLColAttribute
273 #define PHP_ODBC_SQLALLOCSTMT(hdbc, phstmt) SQLAllocHandle(SQL_HANDLE_STMT, hdbc, phstmt)
274 
275 #define PHP_ODBC_SQL_DESC_NAME SQL_DESC_NAME
276 #else
277 #define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR)
278 
279 #define PHP_ODBC_SQLCOLATTRIBUTE SQLColAttributes
280 #define PHP_ODBC_SQLALLOCSTMT SQLAllocStmt
281 
282 #define PHP_ODBC_SQL_DESC_NAME SQL_COLUMN_NAME
283 #endif
284 #define IS_SQL_BINARY(x) (x == SQL_BINARY || x == SQL_VARBINARY || x == SQL_LONGVARBINARY)
285 
286 PHP_ODBC_API ZEND_EXTERN_MODULE_GLOBALS(odbc)
287 #define ODBCG(v) ZEND_MODULE_GLOBALS_ACCESSOR(odbc, v)
288 
289 #if defined(ZTS) && defined(COMPILE_DL_ODBC)
290 ZEND_TSRMLS_CACHE_EXTERN()
291 #endif
292 
293 #endif /* HAVE_UODBC */
294 #endif /* PHP_ODBC_INCLUDES_H */
295