xref: /php-src/ext/pdo_odbc/php_pdo_odbc_int.h (revision 63ae7635)
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 /* }}} */
95 
96 /* {{{ Figure out the type for handles */
97 #if !defined(HENV) && !defined(SQLHENV) && defined(SQLHANDLE)
98 # define PDO_ODBC_HENV		SQLHANDLE
99 # define PDO_ODBC_HDBC		SQLHANDLE
100 # define PDO_ODBC_HSTMT		SQLHANDLE
101 #elif !defined(HENV) && (defined(SQLHENV) || defined(DB2CLI_VER))
102 # define PDO_ODBC_HENV		SQLHENV
103 # define PDO_ODBC_HDBC		SQLHDBC
104 # define PDO_ODBC_HSTMT		SQLHSTMT
105 #else
106 # define PDO_ODBC_HENV		HENV
107 # define PDO_ODBC_HDBC		HDBC
108 # define PDO_ODBC_HSTMT		HSTMT
109 #endif
110 /* }}} */
111 
112 typedef struct {
113 	char last_state[6];
114 	char last_err_msg[SQL_MAX_MESSAGE_LENGTH];
115 	SDWORD last_error;
116 	const char *file, *what;
117 	int line;
118 } pdo_odbc_errinfo;
119 
120 typedef struct {
121 	PDO_ODBC_HENV	env;
122 	PDO_ODBC_HDBC	dbc;
123 	pdo_odbc_errinfo einfo;
124 	unsigned assume_utf8:1;
125 	unsigned _spare:31;
126 } pdo_odbc_db_handle;
127 
128 typedef struct {
129 	char *data;
130 	zend_ulong datalen;
131 	SQLLEN fetched_len;
132 	SWORD	coltype;
133 	char colname[128];
134 	unsigned is_long;
135 	unsigned is_unicode:1;
136 	unsigned _spare:31;
137 } pdo_odbc_column;
138 
139 typedef struct {
140 	PDO_ODBC_HSTMT	stmt;
141 	pdo_odbc_column *cols;
142 	pdo_odbc_db_handle *H;
143 	pdo_odbc_errinfo einfo;
144 	char *convbuf;
145 	zend_ulong convbufsize;
146 	unsigned going_long:1;
147 	unsigned assume_utf8:1;
148 	signed col_count:16;
149 	unsigned _spare:14;
150 } pdo_odbc_stmt;
151 
152 typedef struct {
153 	SQLLEN len;
154 	SQLSMALLINT paramtype;
155 	char *outbuf;
156 	unsigned is_unicode:1;
157 	unsigned _spare:31;
158 } pdo_odbc_param;
159 
160 extern const pdo_driver_t pdo_odbc_driver;
161 extern const struct pdo_stmt_methods odbc_stmt_methods;
162 
163 void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, char *what, const char *file, int line);
164 #define pdo_odbc_drv_error(what)	pdo_odbc_error(dbh, NULL, SQL_NULL_HSTMT, what, __FILE__, __LINE__)
165 #define pdo_odbc_stmt_error(what)	pdo_odbc_error(stmt->dbh, stmt, SQL_NULL_HSTMT, what, __FILE__, __LINE__)
166 #define pdo_odbc_doer_error(what)	pdo_odbc_error(dbh, NULL, stmt, what, __FILE__, __LINE__)
167 
168 void pdo_odbc_init_error_table(void);
169 void pdo_odbc_fini_error_table(void);
170 
171 #ifdef SQL_ATTR_CONNECTION_POOLING
172 extern zend_ulong pdo_odbc_pool_on;
173 extern zend_ulong pdo_odbc_pool_mode;
174 #endif
175 
176 enum {
177 	PDO_ODBC_ATTR_USE_CURSOR_LIBRARY = PDO_ATTR_DRIVER_SPECIFIC,
178 	PDO_ODBC_ATTR_ASSUME_UTF8 /* assume that input strings are UTF-8 when feeding data to unicode columns */
179 };
180