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