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