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