xref: /PHP-7.4/ext/pdo_odbc/php_pdo_odbc_int.h (revision 08073b06)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) The PHP Group                                          |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.0 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_0.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   | Author: Wez Furlong <wez@php.net>                                    |
16   +----------------------------------------------------------------------+
17 */
18 
19 #ifdef PHP_WIN32
20 # define PDO_ODBC_TYPE	"Win32"
21 #endif
22 
23 #ifndef PDO_ODBC_TYPE
24 # warning Please fix configure to give your ODBC libraries a name
25 # define PDO_ODBC_TYPE	"Unknown"
26 #endif
27 
28 /* {{{ Roll a dice, pick a header at random... */
29 #if HAVE_SQLCLI1_H
30 # include <sqlcli1.h>
31 # if defined(DB268K) && HAVE_LIBRARYMANAGER_H
32 #  include <LibraryManager.h>
33 # endif
34 #endif
35 
36 #if HAVE_ODBC_H
37 # include <odbc.h>
38 #endif
39 
40 #if HAVE_IODBC_H
41 # include <iodbc.h>
42 #endif
43 
44 #if HAVE_SQLUNIX_H && !defined(PHP_WIN32)
45 # include <sqlunix.h>
46 #endif
47 
48 #if HAVE_SQLTYPES_H
49 # include <sqltypes.h>
50 #endif
51 
52 #if HAVE_SQLUCODE_H
53 # include <sqlucode.h>
54 #endif
55 
56 #if HAVE_SQL_H
57 # include <sql.h>
58 #endif
59 
60 #if HAVE_ISQL_H
61 # include <isql.h>
62 #endif
63 
64 #if HAVE_SQLEXT_H
65 # include <sqlext.h>
66 #endif
67 
68 #if HAVE_ISQLEXT_H
69 # include <isqlext.h>
70 #endif
71 
72 #if HAVE_UDBCEXT_H
73 # include <udbcext.h>
74 #endif
75 
76 #if HAVE_CLI0CORE_H
77 # include <cli0core.h>
78 #endif
79 
80 #if HAVE_CLI0EXT1_H
81 # include <cli0ext.h>
82 #endif
83 
84 #if HAVE_CLI0CLI_H
85 # include <cli0cli.h>
86 #endif
87 
88 #if HAVE_CLI0DEFS_H
89 # include <cli0defs.h>
90 #endif
91 
92 #if HAVE_CLI0ENV_H
93 # include <cli0env.h>
94 #endif
95 
96 #if HAVE_ODBCSDK_H
97 # include <odbcsdk.h>
98 #endif
99 
100 /* }}} */
101 
102 /* {{{ Figure out the type for handles */
103 #if !defined(HENV) && !defined(SQLHENV) && defined(SQLHANDLE)
104 # define PDO_ODBC_HENV		SQLHANDLE
105 # define PDO_ODBC_HDBC		SQLHANDLE
106 # define PDO_ODBC_HSTMT		SQLHANDLE
107 #elif !defined(HENV) && (defined(SQLHENV) || defined(DB2CLI_VER))
108 # define PDO_ODBC_HENV		SQLHENV
109 # define PDO_ODBC_HDBC		SQLHDBC
110 # define PDO_ODBC_HSTMT		SQLHSTMT
111 #else
112 # define PDO_ODBC_HENV		HENV
113 # define PDO_ODBC_HDBC		HDBC
114 # define PDO_ODBC_HSTMT		HSTMT
115 #endif
116 /* }}} */
117 
118 typedef struct {
119 	char last_state[6];
120 	char last_err_msg[SQL_MAX_MESSAGE_LENGTH];
121 	SDWORD last_error;
122 	const char *file, *what;
123 	int line;
124 } pdo_odbc_errinfo;
125 
126 typedef struct {
127 	PDO_ODBC_HENV	env;
128 	PDO_ODBC_HDBC	dbc;
129 	pdo_odbc_errinfo einfo;
130 	unsigned assume_utf8:1;
131 	unsigned _spare:31;
132 } pdo_odbc_db_handle;
133 
134 typedef struct {
135 	char *data;
136 	zend_ulong datalen;
137 	SQLLEN fetched_len;
138 	SWORD	coltype;
139 	char colname[128];
140 	unsigned is_long;
141 	unsigned is_unicode:1;
142 	unsigned _spare:31;
143 } pdo_odbc_column;
144 
145 typedef struct {
146 	PDO_ODBC_HSTMT	stmt;
147 	pdo_odbc_column *cols;
148 	pdo_odbc_db_handle *H;
149 	pdo_odbc_errinfo einfo;
150 	char *convbuf;
151 	zend_ulong convbufsize;
152 	unsigned going_long:1;
153 	unsigned assume_utf8:1;
154 	signed col_count:16;
155 	unsigned _spare:14;
156 } pdo_odbc_stmt;
157 
158 typedef struct {
159 	SQLLEN len;
160 	SQLSMALLINT paramtype;
161 	char *outbuf;
162 	unsigned is_unicode:1;
163 	unsigned _spare:31;
164 } pdo_odbc_param;
165 
166 extern const pdo_driver_t pdo_odbc_driver;
167 extern const struct pdo_stmt_methods odbc_stmt_methods;
168 
169 void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, char *what, const char *file, int line);
170 #define pdo_odbc_drv_error(what)	pdo_odbc_error(dbh, NULL, SQL_NULL_HSTMT, what, __FILE__, __LINE__)
171 #define pdo_odbc_stmt_error(what)	pdo_odbc_error(stmt->dbh, stmt, SQL_NULL_HSTMT, what, __FILE__, __LINE__)
172 #define pdo_odbc_doer_error(what)	pdo_odbc_error(dbh, NULL, stmt, what, __FILE__, __LINE__)
173 
174 void pdo_odbc_init_error_table(void);
175 void pdo_odbc_fini_error_table(void);
176 
177 #ifdef SQL_ATTR_CONNECTION_POOLING
178 extern zend_ulong pdo_odbc_pool_on;
179 extern zend_ulong pdo_odbc_pool_mode;
180 #endif
181 
182 enum {
183 	PDO_ODBC_ATTR_USE_CURSOR_LIBRARY = PDO_ATTR_DRIVER_SPECIFIC,
184 	PDO_ODBC_ATTR_ASSUME_UTF8 /* assume that input strings are UTF-8 when feeding data to unicode columns */
185 };
186