zeoslib  UNKNOWN
 All Files
ZPlainSqLiteDriver.pas
Go to the documentation of this file.
1 {*********************************************************}
2 { }
3 { Zeos Database Objects }
4 { Native Plain Drivers for SQLite }
5 { }
6 { Originally written by Sergey Seroukhov }
7 { }
8 {*********************************************************}
9 
10 {@********************************************************}
11 { Copyright (c) 1999-2012 Zeos Development Group }
12 { }
13 { License Agreement: }
14 { }
15 { This library is distributed in the hope that it will be }
16 { useful, but WITHOUT ANY WARRANTY; without even the }
17 { implied warranty of MERCHANTABILITY or FITNESS FOR }
18 { A PARTICULAR PURPOSE. See the GNU Lesser General }
19 { Public License for more details. }
20 { }
21 { The source code of the ZEOS Libraries and packages are }
22 { distributed under the Library GNU General Public }
23 { License (see the file COPYING / COPYING.ZEOS) }
24 { with the following modification: }
25 { As a special exception, the copyright holders of this }
26 { library give you permission to link this library with }
27 { independent modules to produce an executable, }
28 { regardless of the license terms of these independent }
29 { modules, and to copy and distribute the resulting }
30 { executable under terms of your choice, provided that }
31 { you also meet, for each linked independent module, }
32 { the terms and conditions of the license of that module. }
33 { An independent module is a module which is not derived }
34 { from or based on this library. If you modify this }
35 { library, you may extend this exception to your version }
36 { of the library, but you are not obligated to do so. }
37 { If you do not wish to do so, delete this exception }
38 { statement from your version. }
39 { }
40 { }
41 { The project web site is located on: }
42 { http://zeos.firmos.at (FORUM) }
43 { http://sourceforge.net/p/zeoslib/tickets/ (BUGTRACKER)}
44 { svn://svn.code.sf.net/p/zeoslib/code-0/trunk (SVN) }
45 { }
46 { http://www.sourceforge.net/projects/zeoslib. }
47 { }
48 { }
49 { Zeos Development Group. }
50 {********************************************************@}
51 
52 unit ZPlainSqLiteDriver;
53 
54 interface
55 
56 {$I ZPlain.inc}
57 
58 uses SysUtils, Classes, {$IFDEF MSEgui}mclasses,{$ENDIF} Types,
59  ZClasses, ZCompatibility, ZPlainDriver;
60 
61 const
62  WINDOWS_DLL_LOCATION = 'sqlite.dll';
63  WINDOWS_DLL3_LOCATION = 'sqlite3.dll';
64  LINUX_DLL_LOCATION = 'libsqlite'+SharedSuffix;
65  LINUX_DLL3_LOCATION = 'libsqlite3'+SharedSuffix;
66 
67  SQLITE_ISO8859 = 1;
68  MASTER_NAME = 'sqlite_master';
69  TEMP_MASTER_NAME = 'sqlite_temp_master';
70 
71  { Return values for sqlite_exec() and sqlite_step() }
72  SQLITE_OK = 0; // Successful result
73  SQLITE_ERROR = 1; // SQL error or missing database
74  SQLITE_INTERNAL = 2; // An internal logic error in SQLite
75  SQLITE_PERM = 3; // Access permission denied
76  SQLITE_ABORT = 4; // Callback routine requested an abort
77  SQLITE_BUSY = 5; // The database file is locked
78  SQLITE_LOCKED = 6; // A table in the database is locked
79  SQLITE_NOMEM = 7; // A malloc() failed
80  SQLITE_READONLY = 8; // Attempt to write a readonly database
81  _SQLITE_INTERRUPT = 9; // Operation terminated by sqlite_interrupt()
82  SQLITE_IOERR = 10; // Some kind of disk I/O error occurred
83  SQLITE_CORRUPT = 11; // The database disk image is malformed
84  SQLITE_NOTFOUND = 12; // (Internal Only) Table or record not found
85  SQLITE_FULL = 13; // Insertion failed because database is full
86  SQLITE_CANTOPEN = 14; // Unable to open the database file
87  SQLITE_PROTOCOL = 15; // Database lock protocol error
88  SQLITE_EMPTY = 16; // (Internal Only) Database table is empty
89  SQLITE_SCHEMA = 17; // The database schema changed
90  SQLITE_TOOBIG = 18; // Too much data for one row of a table
91  SQLITE_CONSTRAINT = 19; // Abort due to contraint violation
92  SQLITE_MISMATCH = 20; // Data type mismatch
93  SQLITE_MISUSE = 21; // Library used incorrectly
94  SQLITE_NOLFS = 22; // Uses OS features not supported on host
95  SQLITE_AUTH = 23; // Authorization denied
96  SQLITE_FORMAT = 24; // Auxiliary database format error
97  SQLITE_RANGE = 25; // 2nd parameter to sqlite_bind out of range
98  SQLITE_NOTADB = 26; // File opened that is not a database file
99  SQLITE_ROW = 100; // sqlite_step() has another row ready
100  SQLITE_DONE = 101; // sqlite_step() has finished executing
101 
102  SQLITE_NUMERIC = -1;
103  SQLITE_TEXT = -2;
104  SQLITE_ARGS = -3;
105 
106  {
107  The second parameter to the access authorization function above will
108  be one of the values below. These values signify what kind of operation
109  is to be authorized. The 3rd and 4th parameters to the authorization
110  function will be parameters or NULL depending on which of the following
111  codes is used as the second parameter. The 5th parameter is the name
112  of the database ("main", "temp", etc.) if applicable. The 6th parameter
113  is the name of the inner-most trigger or view that is responsible for
114  the access attempt or NULL if this access attempt is directly from
115  input SQL code.
116 
117  Arg-3 Arg-4
118  }
119  SQLITE_COPY = 0; // Table Name File Name
120  SQLITE_CREATE_INDEX = 1; // Index Name Table Name
121  SQLITE_CREATE_TABLE = 2; // Table Name NULL
122  SQLITE_CREATE_TEMP_INDEX = 3; // Index Name Table Name
123  SQLITE_CREATE_TEMP_TABLE = 4; // Table Name NULL
124  SQLITE_CREATE_TEMP_TRIGGER = 5; // Trigger Name Table Name
125  SQLITE_CREATE_TEMP_VIEW = 6; // View Name NULL
126  SQLITE_CREATE_TRIGGER = 7; // Trigger Name Table Name
127  SQLITE_CREATE_VIEW = 8; // View Name NULL
128  SQLITE_DELETE = 9; // Table Name NULL
129  SQLITE_DROP_INDEX = 10; // Index Name Table Name
130  SQLITE_DROP_TABLE = 11; // Table Name NULL
131  SQLITE_DROP_TEMP_INDEX = 12; // Index Name Table Name
132  SQLITE_DROP_TEMP_TABLE = 13; // Table Name NULL
133  SQLITE_DROP_TEMP_TRIGGER = 14; // Trigger Name Table Name
134  SQLITE_DROP_TEMP_VIEW = 15; // View Name NULL
135  SQLITE_DROP_TRIGGER = 16; // Trigger Name Table Name
136  SQLITE_DROP_VIEW = 17; // View Name NULL
137  SQLITE_INSERT = 18; // Table Name NULL
138  SQLITE_PRAGMA = 19; // Pragma Name 1st arg or NULL
139  SQLITE_READ = 20; // Table Name Column Name
140  SQLITE_SELECT = 21; // NULL NULL
141  SQLITE_TRANSACTION = 22; // NULL NULL
142  SQLITE_UPDATE = 23; // Table Name Column Name
143  SQLITE_ATTACH = 24; // Filename NULL
144  SQLITE_DETACH = 25; // Database Name NULL
145 
146  { The return value of the authorization function should be one of the
147  following constants: }
148  SQLITE_DENY = 1; // Abort the SQL statement with an error
149  SQLITE_IGNORE = 2; // Don't allow access, but don't generate an error
150 
151  SQLITE_INTEGER = 1;
152  SQLITE_FLOAT = 2;
153  SQLITE3_TEXT = 3;
154  SQLITE_BLOB = 4;
155  SQLITE_NULL = 5;
156 
157 type
158  Psqlite = Pointer;
159  Psqlite_func = Pointer;
160  Psqlite_vm = Pointer;
161  Psqlite3_stmt = Pointer;
162  Psqlite3_value = Pointer;
163 
164  Tsqlite3_destructor_type = procedure(user: pointer); cdecl;
165 
166 
167  SQLITE_STATIC = procedure(User: Pointer = Nil); cdecl;
168  SQLITE_TRANSIENT = procedure(User: pointer = Pointer(-1)); cdecl;
169 
170 type
171 { ************** Plain API Function types definition ************* }
172 
173  Tsqlite_callback = function(p1: Pointer; p2: Integer; var p3: PAnsiChar;
174  var p4: PAnsiChar): Integer; cdecl;
175  Tsqlite_simple_callback = function(p1: Pointer): Integer; cdecl;
176  Tsqlite_simple_callback0 = function(p1: Pointer): Pointer; cdecl;
177  Tsqlite_busy_callback = function(p1: Pointer; const p2: PAnsiChar;
178  p3: Integer): Integer; cdecl;
179 
180  Tsqlite_function_callback = procedure(p1: Psqlite_func; p2: Integer;
181  const p3: PPAnsiChar); cdecl;
182  Tsqlite_finalize_callback = procedure(p1: Psqlite_func); cdecl;
183  Tsqlite_auth_callback = function(p1: Pointer; p2: Integer; const p3: PAnsiChar;
184  const p4: PAnsiChar; const p5: PAnsiChar; const p6: PAnsiChar): Integer; cdecl;
185  Tsqlite_trace_callback = procedure(p1: Pointer; const p2: PAnsiChar); cdecl;
186 
187  Tsqlite_open = function(const filename: PAnsiChar;var Qsqlite: Psqlite): Integer; cdecl;
188  Tsqlite_close = function(db: Psqlite): Integer; cdecl;
189 
190  { prepared statment api}
191  Tsqlite3_prepare = function(
192  db: Psqlite; // Database handle
193  const zSql: PAnsiChar; // SQL statement, UTF-8 encoded
194  nBytes: Integer; // Maximum length of zSql in bytes. -1 = null terminated
195  out ppStmt: Psqlite3_stmt; // OUT: Statement handle
196  out pzTail: PPAnsichar // OUT: Pointer to unused portion of zSql
197  ): Integer; cdecl;
198  Tsqlite3_prepare_v2 = function(
199  db: Psqlite; // Database handle
200  const zSql: PAnsiChar; // SQL statement, UTF-8 encoded
201  nBytes: Integer; // Maximum length of zSql in bytes. -1 = null terminated
202  out ppStmt: Psqlite3_stmt; // OUT: Statement handle
203  out pzTail: PPAnsichar // OUT: Pointer to unused portion of zSql
204  ): Integer; cdecl;
205  Tsqlite3_prepare16 = function(
206  db: Psqlite; // Database handle
207  const zSql: PWideChar; // SQL statement, UTF-16 encoded
208  nBytes: Integer; // Maximum length of zSql in bytes. -1 = null terminated
209  out ppStmt: Psqlite3_stmt; // OUT: Statement handle
210  out pzTail: ZPPWideChar // OUT: Pointer to unused portion of zSql
211  ): Integer; cdecl;
212  Tsqlite3_prepare16_v2 = function(
213  db: Psqlite; // Database handle
214  const zSql: PWideChar; // SQL statement, UTF-16 encoded
215  nBytes: Integer; // Maximum length of zSql in bytes. -1 = null terminated
216  out ppStmt: Psqlite3_stmt; // OUT: Statement handle
217  out pzTail: ZPPWideChar // OUT: Pointer to unused portion of zSql
218  ): Integer; cdecl;
219 
220  Tsqlite3_bind_parameter_count = function(pStmt: Psqlite3_stmt): Integer; cdecl;
221  Tsqlite3_bind_parameter_name = function(pStmt: Psqlite3_stmt; ParamIndex: Integer): PAnsichar; cdecl;
222  Tsqlite3_bind_parameter_index = function(pStmt: Psqlite3_stmt; const zName: PAnsiChar): Integer; cdecl;
223 
224  Tsqlite3_clear_bindings = function(pStmt: Psqlite3_stmt): Integer; cdecl;
225  Tsqlite3_column_count = function(pStmt: Psqlite3_stmt): Integer; cdecl;
226  Tsqlite3_column_name = function(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar; cdecl;
227  Tsqlite3_column_name16 = function(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar; cdecl;
228 
229  Tsqlite3_column_database_name = function(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar; cdecl;
230  Tsqlite3_column_database_name16 = function(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar; cdecl;
231  Tsqlite3_column_table_name = function(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar; cdecl;
232  Tsqlite3_column_table_name16 = function(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar; cdecl;
233  Tsqlite3_column_origin_name = function(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar; cdecl;
234  Tsqlite3_column_origin_name16 = function(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar; cdecl;
235 
236  Tsqlite3_column_decltype = function(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar; cdecl;
237  Tsqlite3_column_decltype16 = function(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar; cdecl;
238 
239  Tsqlite3_step = function(pStmt: Psqlite3_stmt): Integer; cdecl;
240  Tsqlite3_data_count = function (pStmt: Psqlite3_stmt): Integer; cdecl;
241 
242  Tsqlite3_bind_blob = function(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Buffer: Pointer; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer; cdecl;
243  Tsqlite3_bind_double = function(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Double): Integer; cdecl;
244  Tsqlite3_bind_int = function(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Integer): Integer; cdecl;
245  Tsqlite3_bind_int64 = function(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Int64): Integer; cdecl;
246  Tsqlite3_bind_null = function(pStmt: Psqlite3_stmt; ParamIndex: Integer): Integer; cdecl;
247  Tsqlite3_bind_text = function(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Text: PAnsiChar; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer; cdecl;
248  Tsqlite3_bind_text16 = function(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Text: PWideChar; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer; cdecl;
249  Tsqlite3_bind_value = function(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Value: Psqlite3_value): Integer; cdecl;
250  Tsqlite3_bind_zeroblob = function(pStmt: Psqlite3_stmt; ParamIndex: Integer; N: Integer): Integer; cdecl;
251 
252  Tsqlite3_finalize = function(pStmt: Psqlite3_stmt): Integer; cdecl;
253  Tsqlite3_reset = function(pStmt: Psqlite3_stmt): Integer; cdecl;
254 
255  Tsqlite3_column_blob = function(Stmt: Psqlite3_stmt; iCol:integer): Pointer; cdecl;
256  Tsqlite3_column_bytes = function(Stmt: Psqlite3_stmt; iCol: Integer): integer; cdecl;
257  Tsqlite3_column_bytes16 = function(Stmt: Psqlite3_stmt; iCol: Integer): integer; cdecl;
258  Tsqlite3_column_double = function(Stmt: Psqlite3_stmt; iCol: Integer): Double; cdecl;
259  Tsqlite3_column_int = function(Stmt: Psqlite3_stmt; iCol: Integer): Integer; cdecl;
260  Tsqlite3_column_int64 = function(Stmt: Psqlite3_stmt; iCol: Integer): Int64; cdecl;
261  Tsqlite3_column_text = function(Stmt: Psqlite3_stmt; iCol: Integer): PAnsiChar; cdecl;
262  Tsqlite3_column_text16 = function(Stmt: Psqlite3_stmt; iCol: Integer): PWideChar; cdecl;
263  Tsqlite3_column_type = function(Stmt: Psqlite3_stmt; iCol: Integer): Integer; cdecl;
264  Tsqlite3_column_value = function(Stmt: Psqlite3_stmt; iCol: Integer): Psqlite3_value; cdecl;
265  Tsqlite3_last_insert_rowid = function(db: Psqlite): Int64; cdecl;
266 
267  //gets the column type
268  Tsqlite_column_type = function(db:PSqlite;iCol:integer):Integer; cdecl;
269 
270  Tsqlite_exec = function(db: Psqlite; const sql: PAnsiChar;
271  sqlite_callback: Tsqlite_callback; arg: Pointer;
272  var errmsg: PAnsiChar): Integer; cdecl;
273  Tsqlite_errmsg = function(db: Psqlite): PAnsiChar; cdecl;
274  Tsqlite_errstr = function(code: Integer): PAnsiChar; cdecl;
275  //Tsqlite_last_insert_rowid = function(db: Psqlite): Integer; cdecl;
276  Tsqlite_changes = function(db: Psqlite): Integer; cdecl;
277  Tsqlite_last_statement_changes = function(db: Psqlite): Integer; cdecl;
278  Tsqlite_interrupt = procedure(db: Psqlite); cdecl;
279  Tsqlite_complete = function(const sql: PAnsiChar): Integer; cdecl;
280  Tsqlite_busy_handler = procedure(db: Psqlite;
281  callback: Tsqlite_busy_callback; ptr: Pointer); cdecl;
282  Tsqlite_busy_timeout = procedure(db: Psqlite; ms: Integer); cdecl;
283  Tsqlite_get_table = function(db: Psqlite; const sql: PAnsiChar;
284  var resultp: PPAnsiChar; var nrow: Integer; var ncolumn: Integer;
285  var errmsg: PAnsiChar): Integer; cdecl;
286  Tsqlite_free_table = procedure(var result: PAnsiChar); cdecl;
287  Tsqlite_freemem = procedure(ptr: Pointer); cdecl;
288  Tsqlite_libversion = function: PAnsiChar; cdecl;
289  Tsqlite_libencoding = function: PAnsiChar; cdecl;
290 
291  Tsqlite_create_function = function(db: Psqlite; const zName: PAnsiChar;
292  nArg: Integer; callback: Tsqlite_function_callback;
293  pUserData: Pointer): Integer; cdecl;
294  Tsqlite_create_aggregate = function(db: Psqlite; const zName: PAnsiChar;
295  nArg: Integer; callback: Tsqlite_function_callback;
296  finalize: Tsqlite_finalize_callback; pUserData: Pointer): Integer; cdecl;
297  Tsqlite_function_type = function(db: Psqlite; const zName: PAnsiChar;
298  datatype: Integer): Integer; cdecl;
299 
300  Tsqlite_set_result_string = function(func: Psqlite_func; const arg: PAnsiChar;
301  len: Integer; UN: Tsqlite_simple_callback): PAnsiChar; cdecl;
302 
303  Tsqlite_set_result_int = procedure(func: Psqlite_func; arg: Integer); cdecl;
304  Tsqlite_set_result_double = procedure(func: Psqlite_func; arg: Double); cdecl;
305  Tsqlite_set_result_error = procedure(func: Psqlite_func; const arg: PAnsiChar;
306  len: Integer); cdecl;
307  Tsqlite_user_data = function(func: Psqlite_func): Pointer; cdecl;
308  Tsqlite_aggregate_context = function(func: Psqlite_func;
309  nBytes: Integer): Pointer; cdecl;
310  Tsqlite_aggregate_count = function(func: Psqlite_func): Integer; cdecl;
311 
312  Tsqlite_set_authorizer = function(db: Psqlite;
313  callback: Tsqlite_auth_callback; pUserData: Pointer): Integer; cdecl;
314  Tsqlite_trace = function(db: Psqlite; callback: Tsqlite_trace_callback;
315  ptr: Pointer): Pointer; cdecl;
316 
317  Tsqlite_progress_handler = procedure(db: Psqlite; p1: Integer;
318  callback: Tsqlite_simple_callback; ptr: Pointer); cdecl;
319  Tsqlite_commit_hook = function(db: Psqlite; callback: Tsqlite_simple_callback;
320  ptr: Pointer): Pointer; cdecl;
321 
322  Tsqlite_open_encrypted = function(const zFilename: PAnsiChar;
323  const pKey: PAnsiChar; nKey: Integer; var pErrcode: Integer;
324  var pzErrmsg: PAnsiChar): Psqlite; cdecl;
325  Tsqlite_rekey = function(db: Psqlite; const pKey: Pointer;
326  nKey: Integer): Integer; cdecl;
327  Tsqlite_key = function(db: Psqlite; const pKey: Pointer;
328  nKey: Integer): Integer; cdecl;
329 
330 { ************* Plain API Function variables definition ************ }
331 TZSQLite_API = record
332  sqlite_open: Tsqlite_open;
333  sqlite_close: Tsqlite_close;
334 
335  { prepared statement api }
336  sqlite_prepare: Tsqlite3_prepare;
337  sqlite_prepare_v2: Tsqlite3_prepare_v2;
338  sqlite_prepare16: Tsqlite3_prepare16;
339  sqlite_prepare16_v2: Tsqlite3_prepare16_v2;
340 
341  sqlite_bind_parameter_count: Tsqlite3_bind_parameter_count;
342  sqlite_bind_parameter_name: Tsqlite3_bind_parameter_name;
343  sqlite_bind_parameter_index: Tsqlite3_bind_parameter_index;
344 
345  sqlite_clear_bindings: Tsqlite3_clear_bindings;
346  sqlite_column_count: Tsqlite3_column_count;
347  sqlite_column_name: Tsqlite3_column_name;
348  sqlite_column_name16: Tsqlite3_column_name16;
349 
350  sqlite_column_database_name: Tsqlite3_column_database_name;
351  sqlite_column_database_name16: Tsqlite3_column_database_name16;
352  sqlite_column_table_name: Tsqlite3_column_table_name;
353  sqlite_column_table_name16: Tsqlite3_column_table_name16;
354  sqlite_column_origin_name: Tsqlite3_column_origin_name;
355  sqlite_column_origin_name16: Tsqlite3_column_origin_name16;
356 
357  sqlite_column_decltype: Tsqlite3_column_decltype;
358  sqlite_column_decltype16: Tsqlite3_column_decltype16;
359 
360  sqlite_step: Tsqlite3_step;
361  sqlite_data_count: Tsqlite3_data_count;
362 
363  sqlite_bind_blob: Tsqlite3_bind_blob;
364  sqlite_bind_double: Tsqlite3_bind_double;
365  sqlite_bind_int: Tsqlite3_bind_int;
366  sqlite_bind_int64: Tsqlite3_bind_int64;
367  sqlite_bind_null: Tsqlite3_bind_null;
368  sqlite_bind_text: Tsqlite3_bind_text;
369  sqlite_bind_text16: Tsqlite3_bind_text16;
370  sqlite_bind_value: Tsqlite3_bind_value;
371  sqlite_bind_zeroblob: Tsqlite3_bind_zeroblob;
372 
373  sqlite_finalize: Tsqlite3_finalize;
374  sqlite_reset: Tsqlite3_reset;
375 
376  sqlite_column_blob: Tsqlite3_column_blob;
377  sqlite_column_bytes: Tsqlite3_column_bytes;
378  sqlite_column_bytes16: Tsqlite3_column_bytes16;
379  sqlite_column_double: Tsqlite3_column_double;
380  sqlite_column_int: Tsqlite3_column_int;
381  sqlite_column_int64: Tsqlite3_column_int64;
382  sqlite_column_text: Tsqlite3_column_text;
383  sqlite_column_text16: Tsqlite3_column_text16;
384  sqlite_column_type: Tsqlite3_column_type;
385  sqlite_column_value: Tsqlite3_column_value;
386 
387  sqlite_exec: Tsqlite_exec;
388  sqlite_errmsg: Tsqlite_errmsg;
389  sqlite_errstr: Tsqlite_errstr;
390  sqlite_last_insert_rowid: Tsqlite3_last_insert_rowid;
391  sqlite_changes: Tsqlite_changes;
392  sqlite_last_statement_changes: Tsqlite_last_statement_changes;
393  sqlite_interrupt: Tsqlite_interrupt;
394  sqlite_complete: Tsqlite_complete;
395  sqlite_busy_handler: Tsqlite_busy_handler;
396  sqlite_busy_timeout: Tsqlite_busy_timeout;
397  sqlite_get_table: Tsqlite_get_table;
398  sqlite_free_table: Tsqlite_free_table;
399  sqlite_freemem: Tsqlite_freemem;
400  sqlite_libversion: Tsqlite_libversion;
401  sqlite_libencoding: Tsqlite_libencoding;
402  sqlite_create_function: Tsqlite_create_function;
403  sqlite_create_aggregate: Tsqlite_create_aggregate;
404  sqlite_function_type: Tsqlite_function_type;
405  sqlite_set_result_string: Tsqlite_set_result_string;
406  sqlite_set_result_int: Tsqlite_set_result_int;
407  sqlite_set_result_double: Tsqlite_set_result_double;
408  sqlite_set_result_error: Tsqlite_set_result_error;
409  sqlite_user_data: Tsqlite_user_data;
410  sqlite_aggregate_context: Tsqlite_aggregate_context;
411  sqlite_aggregate_count: Tsqlite_aggregate_count;
412  sqlite_set_authorizer: Tsqlite_set_authorizer;
413  sqlite_trace: Tsqlite_trace;
414  sqlite_progress_handler: Tsqlite_progress_handler;
415  sqlite_commit_hook: Tsqlite_commit_hook;
416  sqlite_open_encrypted: Tsqlite_open_encrypted;
417  sqlite_rekey: Tsqlite_rekey;
418  sqlite_key: Tsqlite_key;
419 end;
420 
421 type
422 
423  {** Represents a generic interface to SQLite native API. }
424  IZSQLitePlainDriver = interface (IZPlainDriver)
425  ['{B931C952-3076-4ECB-9630-D900E8DB9869}']
426 
427  function Open(const filename: PAnsiChar; mode: Integer;
428  var errmsg: PAnsiChar): Psqlite;
429  function Close(db: Psqlite): Integer;
430  function Execute(db: Psqlite; const sql: PAnsiChar;
431  sqlite_callback: Tsqlite_callback; arg: Pointer;
432  var errmsg: PAnsiChar): Integer;
433  function LastInsertRowId(db: Psqlite): Int64;
434  function Changes(db: Psqlite): Integer;
435  function LastStatementChanges(db: Psqlite): Integer;
436  function ErrorString(db: Psqlite; code: Integer): String;
437  procedure Interrupt(db: Psqlite);
438  function Complete(const sql: PAnsiChar): Integer;
439 
440  procedure BusyHandler(db: Psqlite; callback: Tsqlite_busy_callback;
441  ptr: Pointer);
442  procedure BusyTimeout(db: Psqlite; ms: Integer);
443 
444  function GetTable(db: Psqlite; const sql: PAnsiChar; var resultp: PPAnsiChar;
445  var nrow: Integer; var ncolumn: Integer; var errmsg: PAnsiChar): Integer;
446  procedure FreeTable(var result: PAnsiChar);
447  procedure FreeMem(ptr: Pointer);
448  function LibVersion: PAnsiChar;
449  function LibEncoding: PAnsiChar;
450 
451  function CreateFunction(db: Psqlite; const zName: PAnsiChar;
452  nArg: Integer; callback: Tsqlite_function_callback;
453  pUserData: Pointer): Integer;
454  function CreateAggregate(db: Psqlite; const zName: PAnsiChar;
455  nArg: Integer; callback: Tsqlite_function_callback;
456  finalize: Tsqlite_finalize_callback; pUserData: Pointer): Integer;
457  function FunctionType(db: Psqlite; const zName: PAnsiChar;
458  datatype: Integer): Integer;
459  function SetResultString(func: Psqlite_func; const arg: PAnsiChar;
460  len: Integer): PAnsiChar;
461  procedure SetResultInt(func: Psqlite_func; arg: Integer);
462  procedure SetResultDouble(func: Psqlite_func; arg: Double);
463  procedure SetResultError(func: Psqlite_func; const arg: PAnsiChar; len: Integer);
464  function UserData(func: Psqlite_func): Pointer;
465  function AggregateContext(func: Psqlite_func; nBytes: Integer): Pointer;
466  function AggregateCount(func: Psqlite_func): Integer;
467 
468  function SetAuthorizer(db: Psqlite; callback: Tsqlite_auth_callback;
469  pUserData: Pointer): Integer;
470  function Trace(db: Psqlite; callback: Tsqlite_trace_callback;
471  ptr: Pointer): Pointer;
472 
473  { Prepared statmenet api }
474  function Prepare(db: Psqlite; const zSql: PAnsiChar; nBytes: Integer;
475  out ppStmt: Psqlite3_stmt; pzTail: PPAnsichar): Integer;
476  function Prepare_v2(db: Psqlite; const zSql: PAnsiChar; nBytes: Integer;
477  out ppStmt: Psqlite3_stmt; pzTail: PPAnsichar): Integer;
478  function Prepare16(db: Psqlite; const zSql: PWideChar; nBytes: Integer;
479  out ppStmt: Psqlite3_stmt; pzTail: ZPPWideChar): Integer;
480  function Prepare16_v2(db: Psqlite; const zSql: PWideChar; nBytes: Integer;
481  out ppStmt: Psqlite3_stmt; pzTail: ZPPWideChar): Integer;
482 
483  function bind_parameter_count(pStmt: Psqlite3_stmt): Integer;
484  function bind_parameter_name(pStmt: Psqlite3_stmt; ParamIndex: Integer): PAnsichar;
485  function bind_parameter_index(pStmt: Psqlite3_stmt; const zName: PAnsiChar): Integer;
486 
487  function clear_bindings(pStmt: Psqlite3_stmt): Integer;
488  function column_count(pStmt: Psqlite3_stmt): Integer;
489  function column_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
490  function column_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
491 
492  function column_database_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
493  function column_database_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
494  function column_table_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
495  function column_table_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
496  function column_origin_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
497  function column_origin_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
498 
499  function column_decltype(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
500  function column_decltype16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
501 
502  function Step(Stmt: Psqlite3_stmt; var pN: Integer;
503  var pazValue, pazColName: PPAnsiChar): Integer; overload;
504  function Step(Stmt: Psqlite3_stmt): Integer; overload;
505  function data_count(pStmt: Psqlite3_stmt): Integer;
506 
507  function bind_blob(pStmt: Psqlite3_stmt; ParamIndex: Integer;
508  const Buffer: Pointer; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer;
509  function bind_double(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Double): Integer;
510  function bind_int(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Integer): Integer;
511  function bind_int64(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Int64): Integer;
512  function bind_null(pStmt: Psqlite3_stmt; ParamIndex: Integer): Integer;
513  function bind_text(pStmt: Psqlite3_stmt; ParamIndex: Integer;
514  const Text: PAnsiChar; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer;
515  function bind_text16(pStmt: Psqlite3_stmt; ParamIndex: Integer;
516  const Text: PWideChar; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer;
517  function bind_value(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Value: Psqlite3_value): Integer;
518  function bind_zeroblob(pStmt: Psqlite3_stmt; ParamIndex: Integer; N: Integer): Integer;
519 
520  function finalize(pStmt: Psqlite3_stmt): Integer;
521  function reset(pStmt: Psqlite3_stmt): Integer;
522 
523  function column_blob(Stmt: Psqlite3_stmt; iCol:integer): TStream;
524  function column_bytes(Stmt: Psqlite3_stmt; iCol: Integer): integer;
525  function column_bytes16(Stmt: Psqlite3_stmt; iCol: Integer): integer;
526  function column_double(Stmt: Psqlite3_stmt; iCol: Integer): Double;
527  function column_int(Stmt: Psqlite3_stmt; iCol: Integer): Integer;
528  function column_int64(Stmt: Psqlite3_stmt; iCol: Integer): Int64;
529  function column_text(Stmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
530  function column_text16(Stmt: Psqlite3_stmt; iCol: Integer): PWideChar;
531  function column_type(Stmt: Psqlite3_stmt; iCol: Integer): String;
532  function column_value(Stmt: Psqlite3_stmt; iCol: Integer): Psqlite3_value;
533 
534  procedure ProgressHandler(db: Psqlite; p1: Integer;
535  callback: Tsqlite_simple_callback; ptr: Pointer);
536  function CommitHook(db: Psqlite; callback: Tsqlite_simple_callback;
537  ptr: Pointer): Pointer;
538 
539  function OpenEncrypted(const zFilename: PAnsiChar; const pKey: PAnsiChar;
540  nKey: Integer; var pErrcode: Integer; var pzErrmsg: PAnsiChar): Psqlite;
541  function ReKey(db: Psqlite; const pKey: Pointer; nKey: Integer): Integer;
542  function Key(db: Psqlite; const pKey: Pointer; nKey: Integer): Integer;
543  end;
544 
545  {** Implements a base driver for SQLite}
546  TZSQLiteBaseDriver = class (TZAbstractPlainDriver, IZPlainDriver, IZSQLitePlainDriver)
547  protected
548  SQLite_API : TZSQLite_API;
549  // procedure LoadApi; override; ->completely done in version dependent child classes
550  function GetUnicodeCodePageName: String; override;
551  procedure LoadCodePages; override;
552  public
553  constructor Create;
554 
555  function Open(const filename: PAnsiChar; mode: Integer;
556  var errmsg: PAnsiChar): Psqlite;
557  function Close(db: Psqlite): Integer;
558  function Execute(db: Psqlite; const sql: PAnsiChar;
559  sqlite_callback: Tsqlite_callback; arg: Pointer;
560  var errmsg: PAnsiChar): Integer;
561  function LastInsertRowId(db: Psqlite): Int64;
562  function Changes(db: Psqlite): Integer;
563  function LastStatementChanges(db: Psqlite): Integer;
564  function ErrorString(db: Psqlite; code: Integer): String;
565  procedure Interrupt(db: Psqlite);
566  function Complete(const sql: PAnsiChar): Integer;
567 
568  procedure BusyHandler(db: Psqlite; callback: Tsqlite_busy_callback;
569  ptr: Pointer);
570  procedure BusyTimeout(db: Psqlite; ms: Integer);
571 
572  function GetTable(db: Psqlite; const sql: PAnsiChar; var resultp: PPAnsiChar;
573  var nrow: Integer; var ncolumn: Integer; var errmsg: PAnsiChar): Integer;
574  procedure FreeTable(var result: PAnsiChar);
575  procedure FreeMem(ptr: Pointer);
576  function LibVersion: PAnsiChar;
577  function LibEncoding: PAnsiChar;
578 
579  function CreateFunction(db: Psqlite; const zName: PAnsiChar;
580  nArg: Integer; callback: Tsqlite_function_callback;
581  pUserData: Pointer): Integer; virtual;
582  function CreateAggregate(db: Psqlite; const zName: PAnsiChar;
583  nArg: Integer; callback: Tsqlite_function_callback;
584  finalize: Tsqlite_finalize_callback; pUserData: Pointer): Integer;
585  function FunctionType(db: Psqlite; const zName: PAnsiChar;
586  datatype: Integer): Integer;
587  function SetResultString(func: Psqlite_func; const arg: PAnsiChar;
588  len: Integer): PAnsiChar;
589  procedure SetResultInt(func: Psqlite_func; arg: Integer);
590  procedure SetResultDouble(func: Psqlite_func; arg: Double);
591  procedure SetResultError(func: Psqlite_func; const arg: PAnsiChar; len: Integer);
592  function UserData(func: Psqlite_func): Pointer;
593  function AggregateContext(func: Psqlite_func; nBytes: Integer): Pointer;
594  function AggregateCount(func: Psqlite_func): Integer;
595 
596  function SetAuthorizer(db: Psqlite; callback: Tsqlite_auth_callback;
597  pUserData: Pointer): Integer;
598  function Trace(db: Psqlite; callback: Tsqlite_trace_callback;
599  ptr: Pointer): Pointer;
600 
601  { Prepared statmenet api }
602  function Prepare(db: Psqlite; const zSql: PAnsiChar; nBytes: Integer;
603  out ppStmt: Psqlite3_stmt; pzTail: PPAnsichar): Integer;
604  function Prepare_v2(db: Psqlite; const zSql: PAnsiChar; nBytes: Integer;
605  out ppStmt: Psqlite3_stmt; pzTail: PPAnsichar): Integer;
606  function Prepare16(db: Psqlite; const zSql: PWideChar; nBytes: Integer;
607  out ppStmt: Psqlite3_stmt; pzTail: ZPPWideChar): Integer;
608  function Prepare16_v2(db: Psqlite; const zSql: PWideChar; nBytes: Integer;
609  out ppStmt: Psqlite3_stmt; pzTail: ZPPWideChar): Integer;
610 
611  function bind_parameter_count(pStmt: Psqlite3_stmt): Integer;
612  function bind_parameter_name(pStmt: Psqlite3_stmt; ParamIndex: Integer): PAnsichar;
613  function bind_parameter_index(pStmt: Psqlite3_stmt; const zName: PAnsiChar): Integer;
614 
615  function clear_bindings(pStmt: Psqlite3_stmt): Integer;
616  function column_count(pStmt: Psqlite3_stmt): Integer;
617  function column_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
618  function column_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
619 
620  function column_database_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
621  function column_database_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
622  function column_table_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
623  function column_table_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
624  function column_origin_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
625  function column_origin_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
626 
627  function column_decltype(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
628  function column_decltype16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
629 
630  function Step(Stmt: Psqlite3_stmt; var pN: Integer;
631  var pazValue, pazColName: PPAnsiChar): Integer; overload;
632  function Step(Stmt: Psqlite3_stmt): Integer; overload;
633  function data_count(pStmt: Psqlite3_stmt): Integer;
634 
635  function bind_blob(pStmt: Psqlite3_stmt; ParamIndex: Integer;
636  const Buffer: Pointer; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer;
637  function bind_double(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Double): Integer;
638  function bind_int(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Integer): Integer;
639  function bind_int64(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Int64): Integer;
640  function bind_null(pStmt: Psqlite3_stmt; ParamIndex: Integer): Integer;
641  function bind_text(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Text: PAnsiChar; N: Integer;
642  ValDestructor: Tsqlite3_destructor_type): Integer;
643  function bind_text16(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Text: PWideChar; N: Integer;
644  ValDestructor: Tsqlite3_destructor_type): Integer;
645  function bind_value(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Value: Psqlite3_value): Integer;
646  function bind_zeroblob(pStmt: Psqlite3_stmt; ParamIndex: Integer; N: Integer): Integer;
647 
648  function finalize(pStmt: Psqlite3_stmt): Integer;
649  function reset(pStmt: Psqlite3_stmt): Integer;
650 
651  function column_blob(Stmt: Psqlite3_stmt; iCol:integer): TStream;
652  function column_bytes(Stmt: Psqlite3_stmt; iCol: Integer): integer;
653  function column_bytes16(Stmt: Psqlite3_stmt; iCol: Integer): integer;
654  function column_double(Stmt: Psqlite3_stmt; iCol: Integer): Double;
655  function column_int(Stmt: Psqlite3_stmt; iCol: Integer): Integer;
656  function column_int64(Stmt: Psqlite3_stmt; iCol: Integer): Int64;
657  function column_text(Stmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
658  function column_text16(Stmt: Psqlite3_stmt; iCol: Integer): PWideChar;
659  function column_type(Stmt: Psqlite3_stmt; iCol: Integer): String;
660  function column_value(Stmt: Psqlite3_stmt; iCol: Integer): Psqlite3_value;
661 
662  procedure ProgressHandler(db: Psqlite; p1: Integer;
663  callback: Tsqlite_simple_callback; ptr: Pointer);
664  function CommitHook(db: Psqlite; callback: Tsqlite_simple_callback;
665  ptr: Pointer): Pointer;
666 
667  function OpenEncrypted(const zFilename: PAnsiChar; const pKey: PAnsiChar;
668  nKey: Integer; var pErrcode: Integer; var pzErrmsg: PAnsiChar): Psqlite;
669  function ReKey(db: Psqlite; const pKey: Pointer; nKey: Integer): Integer;
670  function Key(db: Psqlite; const pKey: Pointer; nKey: Integer): Integer;
671 
672  end;
673 
674  {** Implements a driver for SQLite 3 }
675  TZSQLite3PlainDriver = class (TZSQLiteBaseDriver, IZPlainDriver, IZSQLitePlainDriver)
676  protected
677  function Clone: IZPlainDriver; override;
678  procedure LoadApi; override;
679  public
680  constructor Create;
681  function GetProtocol: string; override;
682  function GetDescription: string; override;
683  end;
684 
685 implementation
686 
687 uses ZPlainLoader, ZEncoding;
688 
689 { TZSQLiteBaseDriver }
690 
691 function TZSQLiteBaseDriver.GetUnicodeCodePageName: String;
692 begin
693  Result := 'UTF-8'
694 end;
695 
696 procedure TZSQLiteBaseDriver.LoadCodePages; //Egonhugeist
697 begin
698  { MultiByte }
699  AddCodePage('UTF-8', 1, ceUTF8, zCP_UTF8);
700  AddCodePage('UTF-16le', 2, ceUTF16, zCP_UTF16, 'UTF-8'); //Setting this will be ignored by actual Excute of Plaindriver
701  AddCodePage('UTF-16be', 3, ceUTF16, zCP_UTF16BE, 'UTF-8'); //Setting this will be ignored by actual Excute of Plaindriver
702  AddCodePage('UTF-16', 4, ceUTF16, zCP_UTF16, 'UTF-8'); //Setting this will be ignored by actual Excute of Plaindriver
703 end;
704 
705 constructor TZSQLiteBaseDriver.Create;
706 begin
707  inherited create;
708  FLoader := TZNativeLibraryLoader.Create([]);
709  {$IFNDEF UNIX}
710  FLoader.AddLocation(WINDOWS_DLL_LOCATION);
711  {$ELSE}
712  FLoader.AddLocation(LINUX_DLL_LOCATION);
713  FLoader.AddLocation(LINUX_DLL_LOCATION+'.0');
714  {$ENDIF}
715 end;
716 
717 function TZSQLiteBaseDriver.AggregateContext(func: Psqlite_func;
718  nBytes: Integer): Pointer;
719 begin
720  Result := SQLite_API.sqlite_aggregate_context(func, nBytes);
721 end;
722 
723 function TZSQLiteBaseDriver.AggregateCount(func: Psqlite_func): Integer;
724 begin
725  Result := SQLite_API.sqlite_aggregate_count(func);
726 end;
727 
728 procedure TZSQLiteBaseDriver.BusyHandler(db: Psqlite;
729  callback: Tsqlite_busy_callback; ptr: Pointer);
730 begin
731  SQLite_API.sqlite_busy_handler(db, callback, ptr);
732 end;
733 
734 procedure TZSQLiteBaseDriver.BusyTimeout(db: Psqlite; ms: Integer);
735 begin
736  SQLite_API.sqlite_busy_timeout(db, ms);
737 end;
738 
739 function TZSQLiteBaseDriver.Changes(db: Psqlite): Integer;
740 begin
741  Result := SQLite_API.sqlite_changes(db);
742 end;
743 
744 function TZSQLiteBaseDriver.CommitHook(db: Psqlite;
745  callback: Tsqlite_simple_callback; ptr: Pointer): Pointer;
746 begin
747  Result := SQLite_API.sqlite_commit_hook(db, callback, ptr);
748 end;
749 
750 function TZSQLiteBaseDriver.Complete(const sql: PAnsiChar): Integer;
751 begin
752  Result := SQLite_API.sqlite_complete(sql);
753 end;
754 
755 function TZSQLiteBaseDriver.CreateAggregate(db: Psqlite;
756  const zName: PAnsiChar; nArg: Integer; callback: Tsqlite_function_callback;
757  finalize: Tsqlite_finalize_callback; pUserData: Pointer): Integer;
758 begin
759  Result := SQLITE_MISUSE;
760 end;
761 
762 function TZSQLiteBaseDriver.CreateFunction(db: Psqlite;
763  const zName: PAnsiChar; nArg: Integer; callback: Tsqlite_function_callback;
764  pUserData: Pointer): Integer;
765 begin
766  Result := SQLITE_MISUSE;
767 end;
768 
769 function TZSQLiteBaseDriver.ErrorString(db: Psqlite; code: Integer): String;
770 var
771  ErrorMessagePointer: PAnsiChar;
772  ErrorMessage: String;
773  ErrorString: String;
774 begin
775  if code = SQLITE_OK then
776  begin
777  Result := 'not an error';
778  Exit;
779  end;
780 
781  if code = SQLITE_NOMEM then
782  begin
783  Result := 'out of memory';
784  Exit;
785  end;
786 
787  if ( db = nil ) or ( @SQLite_API.sqlite_errstr = nil ) then
788  begin
789  case code of
790  SQLITE_OK: Result := 'not an error';
791  SQLITE_ERROR: Result := 'SQL logic error or missing database';
792  SQLITE_INTERNAL: Result := 'internal SQLite implementation flaw';
793  SQLITE_PERM: Result := 'access permission denied';
794  SQLITE_ABORT: Result := 'callback requested query abort';
795  SQLITE_BUSY: Result := 'database is locked';
796  SQLITE_LOCKED: Result := 'database table is locked';
797  SQLITE_NOMEM: Result := 'out of memory';
798  SQLITE_READONLY: Result := 'attempt to write a readonly database';
799  _SQLITE_INTERRUPT: Result := 'interrupted';
800  SQLITE_IOERR: Result := 'disk I/O error';
801  SQLITE_CORRUPT: Result := 'database disk image is malformed';
802  SQLITE_NOTFOUND: Result := 'table or record not found';
803  SQLITE_FULL: Result := 'database is full';
804  SQLITE_CANTOPEN: Result := 'unable to open database file';
805  SQLITE_PROTOCOL: Result := 'database locking protocol failure';
806  SQLITE_EMPTY: Result := 'table contains no data';
807  SQLITE_SCHEMA: Result := 'database schema has changed';
808  SQLITE_TOOBIG: Result := 'too much data for one table row';
809  SQLITE_CONSTRAINT: Result := 'constraint failed';
810  SQLITE_MISMATCH: Result := 'datatype mismatch';
811  SQLITE_MISUSE: Result := 'library routine called out of sequence';
812  SQLITE_NOLFS: Result := 'kernel lacks large file support';
813  SQLITE_AUTH: Result := 'authorization denied';
814  SQLITE_FORMAT: Result := 'auxiliary database format error';
815  SQLITE_RANGE: Result := 'bind index out of range';
816  SQLITE_NOTADB: Result := 'file is encrypted or is not a database';
817  else
818  Result := 'unknown error';
819  end;
820 
821  exit;
822  end
823  else
824  begin
825  ErrorMessagePointer := Self.SQLite_API.sqlite_errstr(code);
826  {$IFDEF UNICODE}
827  ErrorString := Trim(UTF8ToUnicodeString(ErrorMessagePointer));
828  {$ELSE}
829  {$IFNDEF FPC}
830  ErrorString := Trim(UTF8ToAnsi(StrPas(ErrorMessagePointer)));
831  {$ELSE}
832  ErrorString := Trim(ErrorMessagePointer);
833  {$ENDIF}
834  {$ENDIF}
835 
836  ErrorMessagePointer := Self.SQLite_API.sqlite_errmsg(db);
837  {$IFDEF UNICODE}
838  ErrorMessage := Trim(UTF8ToUnicodeString(ErrorMessagePointer));
839  {$ELSE}
840  {$IFNDEF FPC}
841  ErrorMessage := Trim(UTF8ToAnsi(ErrorMessagePointer));
842  {$ELSE}
843  ErrorMessage := Trim(ErrorMessagePointer);
844  {$ENDIF}
845  {$ENDIF}
846 
847  Result := ErrorString + ': ' + ErrorMessage;
848  end;
849 end;
850 
851 function TZSQLiteBaseDriver.Execute(db: Psqlite; const sql: PAnsiChar;
852  sqlite_callback: Tsqlite_callback; arg: Pointer;
853  var errmsg: PAnsiChar): Integer;
854 begin
855  errmsg:= nil;
856  Result := SQLite_API.sqlite_exec(db, sql, sqlite_callback, arg, errmsg);
857 end;
858 
859 procedure TZSQLiteBaseDriver.FreeMem(ptr: Pointer);
860 begin
861  SQLite_API.sqlite_freemem(ptr);
862 end;
863 
864 procedure TZSQLiteBaseDriver.FreeTable(var result: PAnsiChar);
865 begin
866  SQLite_API.sqlite_free_table(result);
867 end;
868 
869 function TZSQLiteBaseDriver.FunctionType(db: Psqlite;
870  const zName: PAnsiChar; datatype: Integer): Integer;
871 begin
872  Result := SQLITE_MISUSE;
873 end;
874 
875 function TZSQLiteBaseDriver.GetTable(db: Psqlite; const sql: PAnsiChar;
876  var resultp: PPAnsiChar; var nrow, ncolumn: Integer;
877  var errmsg: PAnsiChar): Integer;
878 begin
879  Result := SQLite_API.sqlite_get_table(db, sql, resultp, nrow, ncolumn,
880  errmsg);
881 end;
882 
883 procedure TZSQLiteBaseDriver.Interrupt(db: Psqlite);
884 begin
885  SQLite_API.sqlite_interrupt(db);
886 end;
887 
888 function TZSQLiteBaseDriver.LastInsertRowId(db: Psqlite): Int64;
889 begin
890  Result := SQLite_API.sqlite_last_insert_rowid(db);
891 end;
892 
893 function TZSQLiteBaseDriver.LastStatementChanges(db: Psqlite): Integer;
894 begin
895  Result := SQLITE_MISUSE;
896 end;
897 
898 function TZSQLiteBaseDriver.LibEncoding: PAnsiChar;
899 begin
900  Result := nil;
901 end;
902 
903 function TZSQLiteBaseDriver.LibVersion: PAnsiChar;
904 begin
905  Result := SQLite_API.sqlite_libversion;
906 end;
907 
908 function TZSQLiteBaseDriver.Open(const filename: PAnsiChar; mode: Integer;
909  var errmsg: PAnsiChar): Psqlite;
910 var
911  Result0: Psqlite;
912 {$IFNDEF UNICODE}
913  Version: string;
914  FileNameString: String;
915 {$ENDIF}
916 begin
917  Result0:= nil;
918  (*Note to Windows users: The encoding used for the filename argument of
919  sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever codepage
920  is currently defined. Filenames containing international characters must
921  be converted to UTF-8 prior to passing them into sqlite3_open() or
922  sqlite3_open_v2(). *)
923 
924 {$IFDEF UNICODE}
925  SQLite_API.sqlite_open(filename, Result0);
926 {$ELSE}
927  Version := LibVersion;
928  FileNameString := filename;
929  if (Version > '3.2.5') then
930  {$IFDEF FPC}
931  SQLite_API.sqlite_open(PAnsiChar(FileNameString), Result0)
932  {$ELSE}
933  SQLite_API.sqlite_open(PAnsiChar(AnsiToUTF8(FileNameString)), Result0)
934  {$ENDIF}
935  else
936  SQLite_API.sqlite_open(filename, Result0);
937 {$ENDIF}
938  Result := Result0;
939 end;
940 
941 function TZSQLiteBaseDriver.OpenEncrypted(const zFilename, pKey: PAnsiChar;
942  nKey: Integer; var pErrcode: Integer; var pzErrmsg: PAnsiChar): Psqlite;
943 begin
944  pErrcode := SQLITE_MISUSE;
945  pzErrmsg := 'function is not used in the current version of the library';
946  Result:= nil;
947 end;
948 
949 procedure TZSQLiteBaseDriver.ProgressHandler(db: Psqlite; p1: Integer;
950  callback: Tsqlite_simple_callback; ptr: Pointer);
951 begin
952  SQLite_API.sqlite_progress_handler(db, p1, callback, ptr);
953 end;
954 
955 function TZSQLiteBaseDriver.ReKey(db: Psqlite; const pKey: Pointer;
956  nKey: Integer): Integer;
957 begin
958  if @SQLite_API.sqlite_rekey = nil then
959  begin
960  Result := SQLITE_OK;
961  end
962  else
963  begin
964  Result := SQLite_API.sqlite_rekey(db, pKey, nKey);
965  end;
966 end;
967 
968 function TZSQLiteBaseDriver.Key(db: Psqlite; const pKey: Pointer;
969  nKey: Integer): Integer;
970 begin
971  if @SQLite_API.sqlite_key = nil then
972  begin
973  Result := SQLITE_OK;
974  end
975  else
976  begin
977  Result := SQLite_API.sqlite_key(db, pKey, nKey);
978  end;
979 end;
980 
981 function TZSQLiteBaseDriver.SetAuthorizer(db: Psqlite;
982  callback: Tsqlite_auth_callback; pUserData: Pointer): Integer;
983 begin
984  Result := SQLite_API.sqlite_set_authorizer(db, callback, pUserData);
985 end;
986 
987 procedure TZSQLiteBaseDriver.SetResultDouble(func: Psqlite_func;
988  arg: Double);
989 begin
990  SQLite_API.sqlite_set_result_double(func, arg);
991 end;
992 
993 procedure TZSQLiteBaseDriver.SetResultError(func: Psqlite_func;
994  const arg: PAnsiChar; len: Integer);
995 begin
996  SQLite_API.sqlite_set_result_error(func, arg, len);
997 end;
998 
999 procedure TZSQLiteBaseDriver.SetResultInt(func: Psqlite_func;
1000  arg: Integer);
1001 begin
1002  SQLite_API.sqlite_set_result_int(func, arg);
1003 end;
1004 
1005 function TZSQLiteBaseDriver.SetResultString(func: Psqlite_func;
1006  const arg: PAnsiChar; len: Integer): PAnsiChar;
1007 begin
1008  Result := SQLite_API.sqlite_set_result_string(func, arg, len, nil);
1009 end;
1010 
1011 { Prepared statmenet api }
1012 function TZSQLiteBaseDriver.Prepare(db: Psqlite; const zSql: PAnsiChar; nBytes: Integer;
1013  out ppStmt: Psqlite3_stmt; pzTail: PPAnsichar): Integer;
1014 begin
1015  Result := SQLite_API.sqlite_prepare(db, zSql, nBytes, ppStmt, pzTail);
1016 end;
1017 
1018 function TZSQLiteBaseDriver.Prepare_v2(db: Psqlite; const zSql: PAnsiChar; nBytes: Integer;
1019  out ppStmt: Psqlite3_stmt; pzTail: PPAnsichar): Integer;
1020 begin
1021  Result := SQLite_API.sqlite_prepare_v2(db, zSql, nBytes, ppStmt, pzTail);
1022 end;
1023 
1024 function TZSQLiteBaseDriver.Prepare16(db: Psqlite; const zSql: PWideChar; nBytes: Integer;
1025  out ppStmt: Psqlite3_stmt; pzTail: ZPPWideChar): Integer;
1026 begin
1027  Result := SQLite_API.sqlite_prepare16(db, zSql, nBytes, ppStmt, pzTail);
1028 end;
1029 
1030 function TZSQLiteBaseDriver.Prepare16_v2(db: Psqlite; const zSql: PWideChar; nBytes: Integer;
1031  out ppStmt: Psqlite3_stmt; pzTail: ZPPWideChar): Integer;
1032 begin
1033  Result := SQLite_API.sqlite_prepare16_v2(db, zSql, nBytes, ppStmt, pzTail);
1034 end;
1035 
1036 function TZSQLiteBaseDriver.bind_parameter_count(pStmt: Psqlite3_stmt): Integer;
1037 begin
1038  Result := SQLite_API.sqlite_bind_parameter_count(pStmt);
1039 end;
1040 
1041 function TZSQLiteBaseDriver.bind_parameter_name(pStmt: Psqlite3_stmt; ParamIndex: Integer): PAnsichar;
1042 begin
1043  Result := SQLite_API.sqlite_bind_parameter_name(pStmt, ParamIndex);
1044 end;
1045 
1046 function TZSQLiteBaseDriver.bind_parameter_index(pStmt: Psqlite3_stmt; const zName: PAnsiChar): Integer;
1047 begin
1048  Result := SQLite_API.sqlite_bind_parameter_index(pStmt, ZName);
1049 end;
1050 
1051 function TZSQLiteBaseDriver.clear_bindings(pStmt: Psqlite3_stmt): Integer;
1052 begin
1053  Result := SQLite_API.sqlite_clear_bindings(pStmt);
1054 end;
1055 
1056 function TZSQLiteBaseDriver.column_count(pStmt: Psqlite3_stmt): Integer;
1057 begin
1058  Result := SQLite_API.sqlite_column_count(pStmt);
1059 end;
1060 
1061 function TZSQLiteBaseDriver.column_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
1062 begin
1063  Result := SQLite_API.sqlite_column_name(pStmt, iCol);
1064 end;
1065 
1066 function TZSQLiteBaseDriver.column_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
1067 begin
1068  Result := SQLite_API.sqlite_column_name16(pStmt, iCol);
1069 end;
1070 
1071 function TZSQLiteBaseDriver.column_database_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
1072 begin
1073  Result := SQLite_API.sqlite_column_database_name(pStmt, iCol);
1074 end;
1075 
1076 function TZSQLiteBaseDriver.column_database_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
1077 begin
1078  Result := SQLite_API.sqlite_column_database_name16(pStmt, iCol);
1079 end;
1080 
1081 function TZSQLiteBaseDriver.column_table_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
1082 begin
1083  Result := SQLite_API.sqlite_column_table_name(pStmt, iCol);
1084 end;
1085 
1086 function TZSQLiteBaseDriver.column_table_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
1087 begin
1088  Result := SQLite_API.sqlite_column_table_name16(pStmt, iCol);
1089 end;
1090 
1091 function TZSQLiteBaseDriver.column_origin_name(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
1092 begin
1093  Result := SQLite_API.sqlite_column_origin_name(pStmt, iCol);
1094 end;
1095 
1096 function TZSQLiteBaseDriver.column_origin_name16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
1097 begin
1098  Result := SQLite_API.sqlite_column_origin_name16(pStmt, iCol);
1099 end;
1100 
1101 function TZSQLiteBaseDriver.column_decltype(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
1102 begin
1103  Result := SQLite_API.sqlite_column_decltype(pStmt, iCol);
1104 end;
1105 
1106 function TZSQLiteBaseDriver.column_decltype16(pStmt: Psqlite3_stmt; iCol: Integer): PWideChar;
1107 begin
1108  Result := SQLite_API.sqlite_column_decltype16(pStmt, iCol);
1109 end;
1110 
1111 function TZSQLiteBaseDriver.Step(Stmt: Psqlite3_stmt; var pN: Integer;
1112  var pazValue, pazColName: PPAnsiChar): Integer;
1113 var
1114  i: Integer;
1115  val, cname,ctype: PAnsiChar;
1116  pazValue0, pazColName0, pazColType: PPAnsiChar;
1117 begin
1118  pazValue0 := nil; // satisfy compiler
1119  Result := SQLite_API.sqlite_step(Stmt);
1120  if (Result = SQLITE_ROW) or (Result = SQLITE_DONE) then
1121  begin
1122  pN:= SQLite_API.sqlite_column_count(Stmt);
1123  if Result = SQLITE_ROW then
1124  begin
1125  pazValue:= AllocMem(SizeOf(PPAnsiChar)*(pN+1));
1126  pazValue0:= pazValue;
1127  end;
1128  pazColName:= AllocMem(SizeOf(PPAnsiChar)*(pN+1)*2);
1129  pazColName0:= pazColName;
1130  pazColType:= pazColName;
1131 
1132  Inc(pazColType, pN);
1133  for i := 0 to pN - 1 do
1134  begin
1135  if Result = SQLITE_ROW then
1136  begin
1137  cname:= SQLite_API.sqlite_column_name(Stmt, i);
1138  ctype:= SQLite_API.sqlite_column_decltype(Stmt, i);
1139  val := SQLite_API.sqlite_column_text(Stmt, i);
1140  pazValue0^ := val;
1141  inc(pazValue0);
1142  end
1143  else
1144  begin
1145  cname:= SQLite_API.sqlite_column_name(Stmt, i);
1146  ctype:= SQLite_API.sqlite_column_decltype(Stmt, i);
1147  end;
1148  pazColName0^:= cname;
1149  pazColType^ := ctype;
1150  inc(pazColName0);
1151  inc(pazColType);
1152  end;
1153  if Result = SQLITE_ROW then
1154  pazValue0^ := nil;
1155  pazColType^:= nil;
1156  if Result = SQLITE_DONE then
1157  pazValue := nil;
1158  end;
1159 end;
1160 
1161 function TZSQLiteBaseDriver.Step(Stmt: Psqlite3_stmt): Integer;
1162 begin
1163  Result := SQLite_API.sqlite_step(Stmt);
1164 end;
1165 
1166 function TZSQLiteBaseDriver.data_count(pStmt: Psqlite3_stmt): Integer;
1167 begin
1168  Result := SQLite_API.sqlite_data_count(pStmt);
1169 end;
1170 
1171 function TZSQLiteBaseDriver.bind_blob(pStmt: Psqlite3_stmt; ParamIndex: Integer;
1172  const Buffer: Pointer; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer;
1173 begin
1174  Result := SQLite_API.sqlite_bind_blob(pStmt, ParamIndex, Buffer, N, ValDestructor);
1175 end;
1176 
1177 function TZSQLiteBaseDriver.bind_double(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Double): Integer;
1178 begin
1179  Result := SQLite_API.sqlite_bind_double(pStmt, ParamIndex, Value);
1180 end;
1181 
1182 function TZSQLiteBaseDriver.bind_int(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Integer): Integer;
1183 begin
1184  Result := SQLite_API.sqlite_bind_int(pStmt, ParamIndex, Value);
1185 end;
1186 
1187 function TZSQLiteBaseDriver.bind_int64(pStmt: Psqlite3_stmt; ParamIndex: Integer; Value: Int64): Integer;
1188 begin
1189  Result := SQLite_API.sqlite_bind_int64(pStmt, ParamIndex, Value);
1190 end;
1191 
1192 function TZSQLiteBaseDriver.bind_null(pStmt: Psqlite3_stmt; ParamIndex: Integer): Integer;
1193 begin
1194  Result := SQLite_API.sqlite_bind_null(pStmt, ParamIndex);
1195 end;
1196 
1197 function TZSQLiteBaseDriver.bind_text(pStmt: Psqlite3_stmt; ParamIndex: Integer;
1198  const Text: PAnsiChar; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer;
1199 begin
1200  Result := SQLite_API.sqlite_bind_text(pStmt, ParamIndex, Text, N, ValDestructor);
1201 end;
1202 
1203 function TZSQLiteBaseDriver.bind_text16(pStmt: Psqlite3_stmt; ParamIndex: Integer;
1204  const Text: PWideChar; N: Integer; ValDestructor: Tsqlite3_destructor_type): Integer;
1205 begin
1206  Result := SQLite_API.sqlite_bind_text16(pStmt, ParamIndex, Text, N, ValDestructor);
1207 end;
1208 
1209 function TZSQLiteBaseDriver.bind_value(pStmt: Psqlite3_stmt; ParamIndex: Integer; const Value: Psqlite3_value): Integer;
1210 begin
1211  Result := SQLite_API.sqlite_bind_value(pStmt, ParamIndex, Value);
1212 end;
1213 
1214 function TZSQLiteBaseDriver.bind_zeroblob(pStmt: Psqlite3_stmt; ParamIndex: Integer; N: Integer): Integer;
1215 begin
1216  Result := SQLite_API.sqlite_bind_zeroblob(pStmt, ParamIndex, N);
1217 end;
1218 
1219 function TZSQLiteBaseDriver.finalize(pStmt: Psqlite3_stmt): Integer;
1220 begin
1221  Result := SQLite_API.sqlite_finalize(pStmt);
1222 end;
1223 
1224 function TZSQLiteBaseDriver.reset(pStmt: Psqlite3_stmt): Integer;
1225 begin
1226  Result := SQLite_API.sqlite_reset(pStmt);
1227 end;
1228 
1229 function TZSQLiteBaseDriver.column_blob(Stmt: Psqlite3_stmt; iCol:integer): TStream;
1230 var
1231  P : Pointer;
1232  len : integer;
1233 begin
1234  result := TMemoryStream.Create;
1235  P := SQLite_API.sqlite_column_blob(Stmt, iCol-1);
1236  len := SQLite_API.sqlite_column_bytes(Stmt, iCol-1);
1237  result.WriteBuffer(P^,len);
1238 end;
1239 
1240 function TZSQLiteBaseDriver.column_bytes(Stmt: Psqlite3_stmt; iCol: Integer): integer;
1241 begin
1242  Result := SQLite_API.sqlite_column_bytes(Stmt, iCol);
1243 end;
1244 
1245 function TZSQLiteBaseDriver.column_bytes16(Stmt: Psqlite3_stmt; iCol: Integer): integer;
1246 begin
1247  Result := SQLite_API.sqlite_column_bytes16(Stmt, iCol);
1248 end;
1249 
1250 function TZSQLiteBaseDriver.column_double(Stmt: Psqlite3_stmt; iCol: Integer): Double;
1251 begin
1252  Result := SQLite_API.sqlite_column_double(Stmt, iCol);
1253 end;
1254 
1255 function TZSQLiteBaseDriver.column_int(Stmt: Psqlite3_stmt; iCol: Integer): Integer;
1256 begin
1257  Result := SQLite_API.sqlite_column_int(Stmt, iCol);
1258 end;
1259 
1260 function TZSQLiteBaseDriver.column_int64(Stmt: Psqlite3_stmt; iCol: Integer): Int64;
1261 begin
1262  Result := SQLite_API.sqlite_column_int64(Stmt, iCol);
1263 end;
1264 
1265 function TZSQLiteBaseDriver.column_text(Stmt: Psqlite3_stmt; iCol: Integer): PAnsiChar;
1266 begin
1267  Result := SQLite_API.sqlite_column_text(Stmt, iCol);
1268 end;
1269 
1270 function TZSQLiteBaseDriver.column_text16(Stmt: Psqlite3_stmt; iCol: Integer): PWideChar;
1271 begin
1272  Result := SQLite_API.sqlite_column_text16(Stmt, iCol);
1273 end;
1274 
1275 function TZSQLiteBaseDriver.column_type(Stmt: Psqlite3_stmt; iCol: Integer): String;
1276 begin
1277  if Assigned(SQLite_API.sqlite_column_type) then
1278  case SQLite_API.sqlite_column_type(stmt, iCol) of
1279  SQLITE_INTEGER:
1280  Result:='INT(19)';
1281  SQLITE_FLOAT:
1282  Result:='FLOAT(16)';
1283  SQLITE3_TEXT:
1284  //RESULT := 'CHAR'; //EgonHugeist: Need to boil down this type !
1285  //Else Metadatainformations are not readable !
1286  Result:='VARCHAR';
1287  SQLITE_BLOB:
1288  Result:='BLOB';
1289  SQLITE_NULL: Result := '';
1290  end
1291  else
1292  Result:='';
1293 end;
1294 
1295 function TZSQLiteBaseDriver.column_value(Stmt: Psqlite3_stmt; iCol: Integer): Psqlite3_value;
1296 begin
1297  Result := SQLite_API.sqlite_column_value(stmt, iCol);
1298 end;
1299 
1300 function TZSQLiteBaseDriver.Trace(db: Psqlite;
1301  callback: Tsqlite_trace_callback; ptr: Pointer): Pointer;
1302 begin
1303  Result := SQLite_API.sqlite_trace(db, callback, ptr);
1304 end;
1305 
1306 function TZSQLiteBaseDriver.UserData(func: Psqlite_func): Pointer;
1307 begin
1308  Result := SQLite_API.sqlite_user_data(func);
1309 end;
1310 
1311 function TZSQLiteBaseDriver.Close(db: Psqlite): Integer;
1312 begin
1313  Result := SQLite_API.sqlite_close(db);
1314 end;
1315 
1316 { TZSQLite3PlainDriver }
1317 
1318 function TZSQLite3PlainDriver.Clone: IZPlainDriver;
1319 begin
1320  Result := TZSQLite3PlainDriver.Create;
1321 end;
1322 
1323 procedure TZSQLite3PlainDriver.LoadApi;
1324 begin
1325 { ************** Load adresses of API Functions ************* }
1326  with Loader do
1327  begin
1328  @SQLite_API.sqlite_open := GetAddress('sqlite3_open');
1329  @SQLite_API.sqlite_close := GetAddress('sqlite3_close');
1330 
1331  { prepared Statment api }
1332  { prepared statement api }
1333  @SQLite_API.sqlite_prepare := GetAddress('sqlite3_prepare');
1334  @SQLite_API.sqlite_prepare_v2 := GetAddress('sqlite3_prepare_v2');
1335  @SQLite_API.sqlite_prepare16 := GetAddress('sqlite3_prepare16');
1336  @SQLite_API.sqlite_prepare16_v2 := GetAddress('sqlite3_prepare16_v2');
1337 
1338  @SQLite_API.sqlite_bind_parameter_count := GetAddress('sqlite3_bind_parameter_count');
1339  @SQLite_API.sqlite_bind_parameter_name := GetAddress('sqlite3_bind_parameter_name');
1340  @SQLite_API.sqlite_bind_parameter_index := GetAddress('sqlite3_bind_parameter_index');
1341 
1342  @SQLite_API.sqlite_clear_bindings := GetAddress('sqlite3_clear_bindings');
1343 
1344  @SQLite_API.sqlite_column_count := GetAddress('sqlite3_column_count');
1345  @SQLite_API.sqlite_column_bytes := GetAddress('sqlite3_column_bytes');
1346  @SQLite_API.sqlite_column_bytes16 := GetAddress('sqlite3_column_bytes16');
1347  @SQLite_API.sqlite_Column_blob := GetAddress('sqlite3_column_blob');
1348  @SQLite_API.sqlite_column_double := GetAddress('sqlite3_column_double');
1349  @SQLite_API.sqlite_column_int := GetAddress('sqlite3_column_int');
1350  @SQLite_API.sqlite_column_int64 := GetAddress('sqlite3_column_int64');
1351  @SQLite_API.sqlite_column_text := GetAddress('sqlite3_column_text');
1352  @SQLite_API.sqlite_column_text16 := GetAddress('sqlite3_column_text16');
1353  @SQLite_API.sqlite_column_type := GetAddress('sqlite3_column_type');
1354  @SQLite_API.sqlite_column_value := GetAddress('sqlite3_column_value');
1355  @SQLite_API.sqlite_column_name := GetAddress('sqlite3_column_name');
1356  @SQLite_API.sqlite_column_name16 := GetAddress('sqlite3_column_name16');
1357 
1358  @SQLite_API.sqlite_column_database_name := GetAddress('sqlite3_column_database_name');
1359  @SQLite_API.sqlite_column_database_name16 := GetAddress('sqlite3_column_database_name16');
1360  @SQLite_API.sqlite_column_table_name := GetAddress('sqlite3_column_table_name');
1361  @SQLite_API.sqlite_column_table_name16 := GetAddress('sqlite3_column_table_name16');
1362  @SQLite_API.sqlite_column_origin_name := GetAddress('sqlite3_column_origin_name');
1363  @SQLite_API.sqlite_column_origin_name16 := GetAddress('sqlite3_column_origin_name16');
1364 
1365  @SQLite_API.sqlite_column_decltype := GetAddress('sqlite3_column_decltype');
1366  @SQLite_API.sqlite_column_decltype16 := GetAddress('sqlite3_column_decltype16');
1367 
1368  @SQLite_API.sqlite_step := GetAddress('sqlite3_step');
1369  @SQLite_API.sqlite_data_count := GetAddress('sqlite3_data_count');
1370 
1371  @SQLite_API.sqlite_bind_blob := GetAddress('sqlite3_bind_blob');
1372  @SQLite_API.sqlite_bind_double := GetAddress('sqlite3_bind_double');
1373  @SQLite_API.sqlite_bind_int := GetAddress('sqlite3_bind_int');
1374  @SQLite_API.sqlite_bind_int64 := GetAddress('sqlite3_bind_int64');
1375  @SQLite_API.sqlite_bind_null := GetAddress('sqlite3_bind_null');
1376  @SQLite_API.sqlite_bind_text := GetAddress('sqlite3_bind_text');
1377  @SQLite_API.sqlite_bind_text16 := GetAddress('sqlite3_bind_text16');
1378  @SQLite_API.sqlite_bind_value := GetAddress('sqlite3_bind_value');
1379  @SQLite_API.sqlite_bind_zeroblob := GetAddress('sqlite3_bind_zeroblob');
1380 
1381  @SQLite_API.sqlite_finalize := GetAddress('sqlite3_finalize');
1382  @SQLite_API.sqlite_reset := GetAddress('sqlite3_reset');
1383 
1384  @SQLite_API.sqlite_exec := GetAddress('sqlite3_exec');
1385  @SQLite_API.sqlite_last_insert_rowid := GetAddress('sqlite3_last_insert_rowid');
1386  @SQLite_API.sqlite_changes := GetAddress('sqlite3_changes');
1387 // @SQLite_API.sqlite_last_statement_changes := GetAddress('sqlite3_last_statement_changes');
1388  @SQLite_API.sqlite_errmsg := GetAddress('sqlite3_errmsg');
1389  @SQLite_API.sqlite_errstr := GetAddress('sqlite3_errstr');
1390  @SQLite_API.sqlite_interrupt := GetAddress('sqlite3_interrupt');
1391  @SQLite_API.sqlite_complete := GetAddress('sqlite3_complete');
1392  @SQLite_API.sqlite_busy_handler := GetAddress('sqlite3_busy_handler');
1393  @SQLite_API.sqlite_busy_timeout := GetAddress('sqlite3_busy_timeout');
1394  @SQLite_API.sqlite_get_table := GetAddress('sqlite3_get_table');
1395  @SQLite_API.sqlite_free_table := GetAddress('sqlite3_free_table');
1396  @SQLite_API.sqlite_freemem := GetAddress('sqlite3_free');
1397  @SQLite_API.sqlite_libversion := GetAddress('sqlite3_libversion');
1398 // @SQLite_API.sqlite_libencoding := GetAddress('sqlite3_libencoding');
1399 // @SQLite_API.sqlite_create_function := GetAddress('sqlite3_create_function');
1400 // @SQLite_API.sqlite_create_aggregate := GetAddress('sqlite3_create_aggregate');
1401 // @SQLite_API.sqlite_function_type := GetAddress('sqlite3_function_type');
1402  @SQLite_API.sqlite_set_result_string := GetAddress('sqlite3_result_string');
1403  @SQLite_API.sqlite_set_result_int := GetAddress('sqlite3_result_int');
1404  @SQLite_API.sqlite_set_result_double := GetAddress('sqlite3_result_double');
1405  @SQLite_API.sqlite_set_result_error := GetAddress('sqlite3_result_error');
1406  @SQLite_API.sqlite_user_data := GetAddress('sqlite3_user_data');
1407  @SQLite_API.sqlite_aggregate_context := GetAddress('sqlite3_aggregate_context');
1408  @SQLite_API.sqlite_aggregate_count := GetAddress('sqlite3_aggregate_count');
1409  @SQLite_API.sqlite_set_authorizer := GetAddress('sqlite3_set_authorizer');
1410  @SQLite_API.sqlite_trace := GetAddress('sqlite3_trace');
1411  @SQLite_API.sqlite_progress_handler := GetAddress('sqlite3_progress_handler');
1412  @SQLite_API.sqlite_commit_hook := GetAddress('sqlite3_commit_hook');
1413 // @SQLite_API.sqlite_open_encrypted := GetAddress('sqlite3_open_encrypted');
1414  @SQLite_API.sqlite_rekey := GetAddress('sqlite3_rekey');
1415  @SQLite_API.sqlite_key := GetAddress('sqlite3_key');
1416  end;
1417 end;
1418 
1419 constructor TZSQLite3PlainDriver.Create;
1420 begin
1421  inherited Create;
1422  {$IFNDEF UNIX}
1423  FLoader.AddLocation(WINDOWS_DLL3_LOCATION);
1424  {$ELSE}
1425  FLoader.AddLocation(LINUX_DLL3_LOCATION);
1426  FLoader.AddLocation(LINUX_DLL3_LOCATION+'.0');
1427  {$ENDIF}
1428  LoadCodePages;
1429 end;
1430 
1431 function TZSQLite3PlainDriver.GetProtocol: string;
1432 begin
1433  Result := 'sqlite-3';
1434 end;
1435 
1436 function TZSQLite3PlainDriver.GetDescription: string;
1437 begin
1438  Result := 'Native Plain Driver for SQLite 3';
1439 end;
1440 
1441 end.
1442