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