1 #ifndef _SQLITEODBC_H 2 #define _SQLITEODBC_H 3 4 /** 5 * @mainpage 6 * @section readme README 7 * @verbinclude README 8 * @section changelog ChangeLog 9 * @verbinclude ChangeLog 10 * @section copying License Terms 11 * @verbinclude license.terms 12 */ 13 14 /** 15 * @file sqliteodbc.h 16 * Header file for SQLite ODBC driver. 17 * 18 * $Id: sqliteodbc.h,v 1.56 2011/11/12 04:35:40 chw Exp chw $ 19 * 20 * Copyright (c) 2001-2011 Christian Werner <chw@ch-werner.de> 21 * 22 * See the file "license.terms" for information on usage 23 * and redistribution of this file and for a 24 * DISCLAIMER OF ALL WARRANTIES. 25 */ 26 27 #ifdef __OS2__ 28 #define INCL_WIN 29 #define INCL_PM 30 #define INCL_DOSMODULEMGR 31 #define INCL_DOSERRORS 32 #define INCL_WINSTDFILE 33 #define ALLREADY_HAVE_OS2_TYPES 34 #define DONT_TD_VOID 35 #include <os2.h> 36 #include <stdlib.h> 37 #define ODBCVER 0x0300 38 #include "resourceos2.h" 39 #endif 40 41 #if defined(_WIN32) || defined(_WIN64) 42 #include <windows.h> 43 #if defined(HAVE_SQLITETRACE) && HAVE_SQLITETRACE 44 #include <stdio.h> 45 #endif 46 #else 47 #include <sys/time.h> 48 #include <sys/types.h> 49 #include <stdio.h> 50 #include <unistd.h> 51 #include <errno.h> 52 #endif 53 #include <stdlib.h> 54 #if defined(HAVE_LOCALECONV) || defined(_WIN32) || defined(_WIN64) 55 #include <locale.h> 56 #endif 57 #include <stdarg.h> 58 #include <stddef.h> 59 #include <string.h> 60 #include <sql.h> 61 #include <sqlext.h> 62 #include <time.h> 63 64 #include "sqlite.h" 65 #ifdef HAVE_IODBC 66 #include <iodbcinst.h> 67 #endif 68 #if defined(HAVE_UNIXODBC) || defined(_WIN32) || defined(_WIN64) 69 #include <odbcinst.h> 70 #endif 71 72 #ifndef SQL_API 73 #define SQL_API 74 #endif 75 76 #ifndef HAVE_SQLLEN 77 #define SQLLEN SQLINTEGER 78 #endif 79 80 #define SQLLEN_PTR SQLLEN * 81 82 #ifndef HAVE_SQLULEN 83 #define SQLULEN SQLUINTEGER 84 #endif 85 86 #ifndef HAVE_SQLROWCOUNT 87 #define SQLROWCOUNT SQLUINTEGER 88 #endif 89 90 #ifndef HAVE_SQLSETPOSIROW 91 #define SQLSETPOSIROW SQLUSMALLINT 92 #endif 93 94 #ifndef HAVE_SQLROWOFFSET 95 #define SQLROWOFFSET SQLLEN 96 #endif 97 98 #ifndef HAVE_SQLROWSETSIZE 99 #define SQLROWSETSIZE SQLULEN 100 #endif 101 102 struct dbc; 103 struct stmt; 104 105 /** 106 * @typedef ENV 107 * @struct ENV 108 * Driver internal structure for environment (HENV). 109 */ 110 111 typedef struct { 112 int magic; /**< Magic cookie */ 113 int ov3; /**< True for SQL_OV_ODBC3 */ 114 #if defined(_WIN32) || defined(_WIN64) 115 CRITICAL_SECTION cs; /**< For serializing most APIs */ 116 DWORD owner; /**< Current owner of CS or 0 */ 117 #endif 118 struct dbc *dbcs; /**< Pointer to first DBC */ 119 } ENV; 120 121 /** 122 * @typedef DBC 123 * @struct dbc 124 * Driver internal structure for database connection (HDBC). 125 */ 126 127 typedef struct dbc { 128 int magic; /**< Magic cookie */ 129 ENV *env; /**< Pointer to environment */ 130 struct dbc *next; /**< Pointer to next DBC */ 131 sqlite *sqlite; /**< SQLITE database handle */ 132 int version; /**< SQLITE version number */ 133 char *dbname; /**< SQLITE database name */ 134 char *dsn; /**< ODBC data source name */ 135 int timeout; /**< Lock timeout value */ 136 long t0; /**< Start time for SQLITE busy handler */ 137 int busyint; /**< Interrupt busy handler from SQLCancel() */ 138 int *ov3; /**< True for SQL_OV_ODBC3 */ 139 int ov3val; /**< True for SQL_OV_ODBC3 */ 140 int autocommit; /**< Auto commit state */ 141 int intrans; /**< True when transaction started */ 142 struct stmt *stmt; /**< STMT list of this DBC */ 143 int naterr; /**< Native error code */ 144 char sqlstate[6]; /**< SQL state for SQLError() */ 145 SQLCHAR logmsg[1024]; /**< Message for SQLError() */ 146 int nowchar; /**< Don't try to use WCHAR */ 147 int longnames; /**< Don't shorten column names */ 148 int curtype; /**< Default cursor type */ 149 int step_enable; /**< True for sqlite_compile/step/finalize */ 150 int trans_disable; /**< True for no transaction support */ 151 struct stmt *vm_stmt; /**< Current STMT executing VM */ 152 int vm_rownum; /**< Current row number */ 153 #if defined(HAVE_SQLITETRACE) && HAVE_SQLITETRACE 154 FILE *trace; /**< sqlite_trace() file pointer or NULL */ 155 #endif 156 #ifdef USE_DLOPEN_FOR_GPPS 157 void *instlib; 158 int (*gpps)(); 159 #endif 160 #if defined(_WIN32) || defined(_WIN64) 161 int xcelqrx; 162 #endif 163 } DBC; 164 165 /** 166 * @typedef COL 167 * @struct COL 168 * Internal structure to describe a column in a result set. 169 */ 170 171 typedef struct { 172 char *db; /**< Database name */ 173 char *table; /**< Table name */ 174 char *column; /**< Column name */ 175 int type; /**< Data type of column */ 176 int size; /**< Size of column */ 177 int index; /**< Index of column in result */ 178 int nosign; /**< Unsigned type */ 179 int scale; /**< Scale of column */ 180 int prec; /**< Precision of column */ 181 int autoinc; /**< AUTO_INCREMENT column */ 182 int notnull; /**< NOT NULL constraint on column */ 183 char *typename; /**< Column type name or NULL */ 184 char *label; /**< Column label or NULL */ 185 } COL; 186 187 /** 188 * @typedef BINDCOL 189 * @struct BINDCOL 190 * Internal structure for bound column (SQLBindCol). 191 */ 192 193 typedef struct { 194 SQLSMALLINT type; /**< ODBC type */ 195 SQLINTEGER max; /**< Max. size of value buffer */ 196 SQLLEN *lenp; /**< Value return, actual size of value buffer */ 197 SQLPOINTER valp; /**< Value buffer */ 198 int index; /**< Index of column in result */ 199 int offs; /**< Byte offset for SQLGetData() */ 200 } BINDCOL; 201 202 /** 203 * @typedef BINDPARM 204 * @struct BINDPARM 205 * Internal structure for bound parameter (SQLBindParameter). 206 */ 207 208 typedef struct { 209 int type, stype; /**< ODBC and SQL types */ 210 int coldef, scale; /**< from SQLBindParameter() */ 211 SQLLEN max; /**< Max. size size of parameter buffer */ 212 SQLLEN *lenp; /**< Actual size of parameter buffer */ 213 SQLLEN *lenp0; /**< Actual size of parameter buffer, initial value */ 214 void *param; /**< Parameter buffer */ 215 void *param0; /**< Parameter buffer, initial value */ 216 int inc; /**< Increment for paramset size > 1 */ 217 int need; /**< True when SQL_LEN_DATA_AT_EXEC */ 218 int bound; /**< True when SQLBindParameter() called */ 219 int offs, len; /**< Offset/length for SQLParamData()/SQLPutData() */ 220 void *parbuf; /**< Buffer for SQL_LEN_DATA_AT_EXEC etc. */ 221 char strbuf[64]; /**< String buffer for scalar data */ 222 } BINDPARM; 223 224 /** 225 * @typedef STMT 226 * @struct stmt 227 * Driver internal structure representing SQL statement (HSTMT). 228 */ 229 230 typedef struct stmt { 231 struct stmt *next; /**< Linkage for STMT list in DBC */ 232 HDBC dbc; /**< Pointer to DBC */ 233 SQLCHAR cursorname[32]; /**< Cursor name */ 234 SQLCHAR *query; /**< Current query, raw string */ 235 char **parmnames; /**< Parameter names from current query */ 236 int *ov3; /**< True for SQL_OV_ODBC3 */ 237 int isselect; /**< > 0 if query is a SELECT statement */ 238 int ncols; /**< Number of result columns */ 239 COL *cols; /**< Result column array */ 240 COL *dyncols; /**< Column array, but malloc()ed */ 241 int dcols; /**< Number of entries in dyncols */ 242 int bkmrk; /**< True when bookmarks used */ 243 BINDCOL bkmrkcol; /**< Bookmark bound column */ 244 BINDCOL *bindcols; /**< Array of bound columns */ 245 int nbindcols; /**< Number of entries in bindcols */ 246 int nbindparms; /**< Number bound parameters */ 247 BINDPARM *bindparms; /**< Array of bound parameters */ 248 int nparams; /**< Number of parameters in query */ 249 int nrows; /**< Number of result rows */ 250 int rowp; /**< Current result row */ 251 char **rows; /**< 2-dim array, result set */ 252 void (*rowfree)(); /**< Free function for rows */ 253 int naterr; /**< Native error code */ 254 char sqlstate[6]; /**< SQL state for SQLError() */ 255 SQLCHAR logmsg[1024]; /**< Message for SQLError() */ 256 int nowchar[2]; /**< Don't try to use WCHAR */ 257 int longnames; /**< Don't shorten column names */ 258 SQLULEN retr_data; /**< SQL_ATTR_RETRIEVE_DATA */ 259 SQLULEN rowset_size; /**< Size of rowset */ 260 SQLUSMALLINT *row_status; /**< Row status pointer */ 261 SQLUSMALLINT *row_status0; /**< Internal status array */ 262 SQLUSMALLINT row_status1; /**< Internal status array for 1 row rowsets */ 263 SQLULEN *row_count; /**< Row count pointer */ 264 SQLULEN row_count0; /**< Row count */ 265 SQLULEN paramset_size; /**< SQL_ATTR_PARAMSET_SIZE */ 266 SQLULEN paramset_count; /**< Internal for paramset */ 267 SQLUINTEGER paramset_nrows; /**< Row count for paramset handling */ 268 SQLULEN bind_type; /**< SQL_ATTR_ROW_BIND_TYPE */ 269 SQLULEN *bind_offs; /**< SQL_ATTR_ROW_BIND_OFFSET_PTR */ 270 /* Dummies to make ADO happy */ 271 SQLULEN *parm_bind_offs; /**< SQL_ATTR_PARAM_BIND_OFFSET_PTR */ 272 SQLUSMALLINT *parm_oper; /**< SQL_ATTR_PARAM_OPERATION_PTR */ 273 SQLUSMALLINT *parm_status; /**< SQL_ATTR_PARAMS_STATUS_PTR */ 274 SQLULEN *parm_proc; /**< SQL_ATTR_PARAMS_PROCESSED_PTR */ 275 SQLULEN parm_bind_type; /**< SQL_ATTR_PARAM_BIND_TYPE */ 276 int curtype; /**< Cursor type */ 277 sqlite_vm *vm; /**< SQLite VM or NULL */ 278 #if HAVE_ENCDEC 279 char *bincell; /**< Undecoded string */ 280 char *bincache; /**< Cached decoded binary data */ 281 int binlen; /**< Length of decoded binary data */ 282 char *hexcache; /**< Cached decoded binary in hex */ 283 #endif 284 } STMT; 285 286 #endif 287