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