summaryrefslogtreecommitdiff
path: root/packages/sqlite
diff options
context:
space:
mode:
authormarco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-01-26 17:12:43 +0000
committermarco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-01-26 17:12:43 +0000
commit27930ea3c486b3e94bfaab676052eda4e8768087 (patch)
treef3d16f34985987113e8d8c49c2b5bcf1c54f5341 /packages/sqlite
parent6e0aa6d3a42be1c2fc460e988fdf311379bd5b83 (diff)
downloadfpc-27930ea3c486b3e94bfaab676052eda4e8768087.tar.gz
* postgres and sqlite moved
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@9945 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/sqlite')
-rw-r--r--packages/sqlite/Makefile.fpc29
-rw-r--r--packages/sqlite/fpmake.pp49
-rw-r--r--packages/sqlite/src/sqlite.pp162
-rw-r--r--packages/sqlite/src/sqlite3.inc576
-rw-r--r--packages/sqlite/src/sqlite3.pp5
-rw-r--r--packages/sqlite/src/sqlite3db.pas494
-rw-r--r--packages/sqlite/src/sqlite3dyn.pp7
-rw-r--r--packages/sqlite/src/sqlitedb.pas410
-rw-r--r--packages/sqlite/tests/test.pas52
-rw-r--r--packages/sqlite/tests/testapiv3x.README44
-rw-r--r--packages/sqlite/tests/testapiv3x.pp83
11 files changed, 1911 insertions, 0 deletions
diff --git a/packages/sqlite/Makefile.fpc b/packages/sqlite/Makefile.fpc
new file mode 100644
index 0000000000..2874cfc133
--- /dev/null
+++ b/packages/sqlite/Makefile.fpc
@@ -0,0 +1,29 @@
+#
+# Makefile.fpc for sqlite implementation
+#
+
+[package]
+name=sqlite
+version=2.0.0
+
+[target]
+units=sqlite sqlite3 sqlite3dyn sqlitedb sqlite3db
+
+[require]
+
+[install]
+fpcpackage=y
+
+[default]
+fpcdir=../..
+
+[compiler]
+includedir=src
+sourcedir=src tests examples
+
+[shared]
+build=n
+
+[rules]
+.NOTPARALLEL:
+
diff --git a/packages/sqlite/fpmake.pp b/packages/sqlite/fpmake.pp
new file mode 100644
index 0000000000..2e820d8490
--- /dev/null
+++ b/packages/sqlite/fpmake.pp
@@ -0,0 +1,49 @@
+{$ifndef ALLPACKAGES}
+{$mode objfpc}{$H+}
+program fpmake;
+
+uses fpmkunit;
+
+Var
+ P : TPackage;
+ T : TTarget;
+begin
+ With Installer do
+ begin
+{$endif ALLPACKAGES}
+
+ P:=AddPackage('sqlite');
+{$ifdef ALLPACKAGES}
+ P.Directory:='sqlite';
+{$endif ALLPACKAGES}
+ P.Version:='2.0.0';
+ P.SourcePath.Add('src');
+
+ T:=P.Targets.AddUnit('sqlite3db.pas');
+ with T.Dependencies do
+ begin
+ AddUnit('sqlite3');
+ end;
+ T:=P.Targets.AddUnit('sqlite3dyn.pp');
+ with T.Dependencies do
+ begin
+ AddInclude('sqlite3.inc');
+ end;
+ T:=P.Targets.AddUnit('sqlite3.pp');
+ with T.Dependencies do
+ begin
+ AddInclude('sqlite3.inc');
+ end;
+ T:=P.Targets.AddUnit('sqlitedb.pas');
+ with T.Dependencies do
+ begin
+ AddUnit('sqlite');
+ end;
+ T:=P.Targets.AddUnit('sqlite.pp');
+
+
+{$ifndef ALLPACKAGES}
+ Run;
+ end;
+end.
+{$endif ALLPACKAGES}
diff --git a/packages/sqlite/src/sqlite.pp b/packages/sqlite/src/sqlite.pp
new file mode 100644
index 0000000000..277ef1227f
--- /dev/null
+++ b/packages/sqlite/src/sqlite.pp
@@ -0,0 +1,162 @@
+{$mode objfpc}
+
+{$ifdef bsd}
+ {$linklib c}
+{$endif}
+
+unit sqlite;
+
+interface
+
+{
+ Automatically converted by H2Pas 0.99.15 from sqlite.h
+ The following command line parameters were used:
+ -S
+ -D
+ -p
+ -l
+ sqlite
+ sqlite.h
+}
+
+{$PACKRECORDS C}
+
+const
+ External_library='sqlite';
+
+ SQLITE_ISO8859 = 1;//?
+
+ //sqlite_exec and sqlite_step return values
+ SQLITE_OK = 0;
+ SQLITE_ERROR = 1;
+ SQLITE_INTERNAL = 2;
+ SQLITE_PERM = 3;
+ SQLITE_ABORT = 4;
+ SQLITE_BUSY = 5;
+ SQLITE_LOCKED = 6;
+ SQLITE_NOMEM = 7;
+ SQLITE_READONLY = 8;
+ SQLITE_INTERRUPT = 9;
+ SQLITE_IOERR = 10;
+ SQLITE_CORRUPT = 11;
+ SQLITE_NOTFOUND = 12;
+ SQLITE_FULL = 13;
+ SQLITE_CANTOPEN = 14;
+ SQLITE_PROTOCOL = 15;
+ SQLITE_EMPTY = 16;
+ SQLITE_SCHEMA = 17;
+ SQLITE_TOOBIG = 18;
+ SQLITE_CONSTRAINT = 19;
+ SQLITE_MISMATCH = 20;
+ SQLITE_MISUSE = 21;
+ SQLITE_NOLFS = 22;
+ SQLITE_AUTH = 23;
+ SQLITE_FORMAT = 24;
+ SQLITE_RANGE = 25;
+ SQLITE_ROW = 100;
+ SQLITE_DONE = 101;
+
+ // values used in sqlite_set_authorizer to define what operations authorize
+ SQLITE_COPY = 0;
+ SQLITE_CREATE_INDEX = 1;
+ SQLITE_CREATE_TABLE = 2;
+ SQLITE_CREATE_TEMP_INDEX = 3;
+ SQLITE_CREATE_TEMP_TABLE = 4;
+ SQLITE_CREATE_TEMP_TRIGGER = 5;
+ SQLITE_CREATE_TEMP_VIEW = 6;
+ SQLITE_CREATE_TRIGGER = 7;
+ SQLITE_CREATE_VIEW = 8;
+ SQLITE_DELETE = 9;
+ SQLITE_DROP_INDEX = 10;
+ SQLITE_DROP_TABLE = 11;
+ SQLITE_DROP_TEMP_INDEX = 12;
+ SQLITE_DROP_TEMP_TABLE = 13;
+ SQLITE_DROP_TEMP_TRIGGER = 14;
+ SQLITE_DROP_TEMP_VIEW = 15;
+ SQLITE_DROP_TRIGGER = 16;
+ SQLITE_DROP_VIEW = 17;
+ SQLITE_INSERT = 18;
+ SQLITE_PRAGMA = 19;
+ SQLITE_READ = 20;
+ SQLITE_SELECT = 21;
+ SQLITE_TRANSACTION = 22;
+ SQLITE_UPDATE = 23;
+
+ //Return values of the authorizer function
+ SQLITE_DENY = 1;
+ SQLITE_IGNORE = 2;
+
+ SQLITE_NUMERIC = -1;
+ SQLITE_TEXT = -2;
+ SQLITE_ARGS = -3;
+
+Type
+ PPPchar = ^ppchar;
+ Psqlite = Pointer;
+ Psqlite_vm = Pointer;
+ PPsqlite_vm = ^Psqlite_vm;
+ Psqlite_func = Pointer;
+
+ // Procedural types used in functions.
+
+ sqlite_callback = function (_para1:pointer; _para2:longint; _para3:PPchar; _para4:PPchar):longint;cdecl;
+ sqlite_trace_func = procedure (_para1:pointer; _para2:Pchar);cdecl;
+ sqlite_create_func = procedure (_para1:Psqlite_func; _para2:longint; _para3:PPchar);cdecl;
+ sqlite_handler = function (_para1:pointer; _para2:Pchar; _para3:longint):longint;cdecl;
+ sqlite_step_func = procedure (_para1:Psqlite_func; _para2:longint; _para3:PPchar);cdecl;
+ sqlite_finalize_func = procedure (_para1:Psqlite_func);cdecl;
+ sqlite_authorize_func = function (_para1:pointer; _para2:longint; _para3, _para4,_para5,_para6:Pchar):longint;cdecl;
+
+ function sqlite_create_function(_para1:Psqlite; zName:Pchar; nArg:longint; xFunc:sqlite_create_func; pUserData:pointer):longint;cdecl;external External_library name 'sqlite_create_function';
+ function sqlite_open(filename:Pchar; mode:longint; errmsg:PPchar):Psqlite;cdecl;external External_library name 'sqlite_open';
+ procedure sqlite_close(_para1:Psqlite);cdecl;external External_library name 'sqlite_close';
+ function sqlite_exec(_para1:Psqlite; sql:Pchar; _para3:sqlite_callback; _para4:pointer; errmsg:PPchar):longint;cdecl;external External_library name 'sqlite_exec';
+ function sqlite_last_insert_rowid(_para1:Psqlite):longint;cdecl;external External_library name 'sqlite_last_insert_rowid';
+ function sqlite_changes(_para1:Psqlite):longint;cdecl;external External_library name 'sqlite_changes';
+ function sqlite_error_string(_para1:longint):Pchar;cdecl;external External_library name 'sqlite_error_string';
+ procedure do_sqlite_interrupt(_para1:Psqlite);cdecl;external External_library name 'sqlite_interrupt';
+ function sqlite_complete(sql:Pchar):longint;cdecl;external External_library name 'sqlite_complete';
+ procedure sqlite_busy_handler(_para1:Psqlite; _para2:sqlite_handler; _para3:pointer);cdecl;external External_library name 'sqlite_busy_handler';
+ procedure sqlite_busy_timeout(_para1:Psqlite; ms:longint);cdecl;external External_library name 'sqlite_busy_timeout';
+ function sqlite_get_table(_para1:Psqlite; sql:Pchar; resultp:PPPchar; nrow:Plongint; ncolumn:Plongint;
+ errmsg:PPchar):longint;cdecl;external External_library name 'sqlite_get_table';
+ procedure sqlite_free_table(result:PPchar);cdecl;external External_library name 'sqlite_free_table';
+ function sqlite_exec_printf(_para1:Psqlite; sqlFormat:Pchar; _para3:sqlite_callback; _para4:pointer; errmsg:PPchar;
+ args:array of const):longint;cdecl;external External_library name 'sqlite_exec_printf';
+ function sqlite_exec_printf(_para1:Psqlite; sqlFormat:Pchar; _para3:sqlite_callback; _para4:pointer; errmsg:PPchar):longint;cdecl;varargs;external External_library name 'sqlite_exec_printf';
+ function sqlite_exec_vprintf(_para1:Psqlite; sqlFormat:Pchar; _para3:sqlite_callback; _para4:pointer; errmsg:PPchar;
+ ap:array of const):longint;cdecl;external External_library name 'sqlite_exec_vprintf';
+ function sqlite_get_table_printf(_para1:Psqlite; sqlFormat:Pchar; resultp:PPPchar; nrow:Plongint; ncolumn:Plongint;
+ errmsg:PPchar; args:array of const):longint;cdecl;external External_library name 'sqlite_get_table_printf';
+ function sqlite_get_table_printf(_para1:Psqlite; sqlFormat:Pchar; resultp:PPPchar; nrow:Plongint; ncolumn:Plongint;
+ errmsg:PPchar):longint;cdecl;varargs;external External_library name 'sqlite_get_table_printf';
+ function sqlite_get_table_vprintf(_para1:Psqlite; sqlFormat:Pchar; resultp:PPPchar; nrow:Plongint; ncolumn:Plongint;
+ errmsg:PPchar; ap:array of const):longint;cdecl;external External_library name 'sqlite_get_table_vprintf';
+ function sqlite_mprintf(_para1:Pchar; args:array of const):Pchar;cdecl;external External_library name 'sqlite_mprintf';
+ function sqlite_mprintf(_para1:Pchar):Pchar;cdecl;varargs;external External_library name 'sqlite_mprintf';
+ procedure sqlite_freemem(p:pointer);cdecl;external External_library name 'sqlite_freemem';
+ function sqlite_libversion:Pchar;cdecl;external External_library name 'sqlite_libversion';
+ function sqlite_libencoding:Pchar;cdecl;external External_library name 'sqlite_libencoding';
+ function sqlite_create_aggregate(_para1:Psqlite; zName:Pchar; nArg:longint; xStep:sqlite_step_func ; xFinalize:sqlite_finalize_func;
+ pUserData:pointer):longint;cdecl;external External_library name 'sqlite_create_aggregate';
+ function sqlite_function_type(db:Psqlite; zName:Pchar; datatype:longint):longint;cdecl;external External_library name 'sqlite_function_type';
+ function sqlite_set_result_string(_para1:Psqlite_func; _para2:Pchar; _para3:longint):Pchar;cdecl;external External_library name 'sqlite_set_result_string';
+ procedure sqlite_set_result_int(_para1:Psqlite_func; _para2:longint);cdecl;external External_library name 'sqlite_set_result_int';
+ procedure sqlite_set_result_double(_para1:Psqlite_func; _para2:double);cdecl;external External_library name 'sqlite_set_result_double';
+ procedure sqlite_set_result_error(_para1:Psqlite_func; _para2:Pchar; _para3:longint);cdecl;external External_library name 'sqlite_set_result_error';
+ function sqlite_user_data(_para1:Psqlite_func):pointer;cdecl;external External_library name 'sqlite_user_data';
+ function sqlite_aggregate_context(_para1:Psqlite_func; nBytes:longint):pointer;cdecl;external External_library name 'sqlite_aggregate_context';
+ function sqlite_aggregate_count(_para1:Psqlite_func):longint;cdecl;external External_library name 'sqlite_aggregate_count';
+ function sqlite_set_authorizer(_para1:Psqlite; xAuth:sqlite_authorize_func ; pUserData:pointer):longint;cdecl;external External_library name 'sqlite_set_authorizer';
+ function sqlite_trace(_para1:Psqlite; xTrace:sqlite_trace_func; _para3:pointer):pointer;cdecl;external External_library name 'sqlite_trace';
+ function sqlite_compile(db:Psqlite; zSql:Pchar; pzTail:PPchar; ppVm:PPsqlite_vm; pzErrmsg:PPchar):longint;cdecl;external External_library name 'sqlite_compile';
+ function sqlite_step(pVm:Psqlite_vm; pN:Plongint; pazValue:PPPchar; pazColName:PPPchar):longint;cdecl;external External_library name 'sqlite_step';
+ function sqlite_finalize(_para1:Psqlite_vm; pzErrMsg:PPchar):longint;cdecl;external External_library name 'sqlite_finalize';
+
+ //Use functions instead of external variables to retrieve version and encoding info
+ function sqlite_version: PChar external External_library name 'sqlite_libversion';
+ function sqlite_encoding: PChar external External_library name 'sqlite_libencoding';
+
+implementation
+
+end.
diff --git a/packages/sqlite/src/sqlite3.inc b/packages/sqlite/src/sqlite3.inc
new file mode 100644
index 0000000000..830f321a88
--- /dev/null
+++ b/packages/sqlite/src/sqlite3.inc
@@ -0,0 +1,576 @@
+{$mode objfpc}
+
+{$ifdef BSD}
+ {$linklib c}
+ {$linklib pthread}
+{$endif}
+
+interface
+
+{$ifdef LOAD_DYNAMICALLY}
+uses
+ SysUtils, DynLibs;
+{$endif}
+
+{
+ Automatically converted by H2Pas 0.99.16 from sqlite3.h
+ The following command line parameters were used:
+ -D
+ -c
+ sqlite3.h
+
+ Manual corrections made by Luiz Américo - 2005
+}
+
+{$PACKRECORDS C}
+
+const
+{$IFDEF WINDOWS}
+ Sqlite3Lib = 'sqlite3.dll';
+{$else}
+ Sqlite3Lib = 'libsqlite3.so';
+{$endif}
+
+ SQLITE_INTEGER = 1;
+ SQLITE_FLOAT = 2;
+{ #define SQLITE_TEXT 3 // See below }
+ SQLITE_BLOB = 4;
+ SQLITE_NULL = 5;
+ SQLITE_TEXT = 3;
+ SQLITE3_TEXT = 3;
+ SQLITE_UTF8 = 1;
+ SQLITE_UTF16LE = 2;
+ SQLITE_UTF16BE = 3;
+{ Use native byte order }
+ SQLITE_UTF16 = 4;
+{ sqlite3_create_function only }
+ SQLITE_ANY = 5;
+
+ //sqlite_exec return values
+ SQLITE_OK = 0;
+ SQLITE_ERROR = 1;{ SQL error or missing database }
+ SQLITE_INTERNAL = 2;{ An internal logic error in SQLite }
+ SQLITE_PERM = 3; { Access permission denied }
+ SQLITE_ABORT = 4; { Callback routine requested an abort }
+ SQLITE_BUSY = 5; { The database file is locked }
+ SQLITE_LOCKED = 6;{ A table in the database is locked }
+ SQLITE_NOMEM = 7; { A malloc() failed }
+ SQLITE_READONLY = 8;{ Attempt to write a readonly database }
+ SQLITE_INTERRUPT = 9;{ Operation terminated by sqlite3_interrupt() }
+ SQLITE_IOERR = 10; { Some kind of disk I/O error occurred }
+ SQLITE_CORRUPT = 11; { The database disk image is malformed }
+ SQLITE_NOTFOUND = 12; { (Internal Only) Table or record not found }
+ SQLITE_FULL = 13; { Insertion failed because database is full }
+ SQLITE_CANTOPEN = 14; { Unable to open the database file }
+ SQLITE_PROTOCOL = 15; { Database lock protocol error }
+ SQLITE_EMPTY = 16; { Database is empty }
+ SQLITE_SCHEMA = 17; { The database schema changed }
+ SQLITE_TOOBIG = 18; { Too much data for one row of a table }
+ SQLITE_CONSTRAINT = 19; { Abort due to contraint violation }
+ SQLITE_MISMATCH = 20; { Data type mismatch }
+ SQLITE_MISUSE = 21; { Library used incorrectly }
+ SQLITE_NOLFS = 22; { Uses OS features not supported on host }
+ SQLITE_AUTH = 23; { Authorization denied }
+ SQLITE_FORMAT = 24; { Auxiliary database format error }
+ SQLITE_RANGE = 25; { 2nd parameter to sqlite3_bind out of range }
+ SQLITE_NOTADB = 26; { File opened that is not a database file }
+ SQLITE_ROW = 100; { sqlite3_step() has another row ready }
+ SQLITE_DONE = 101; { sqlite3_step() has finished executing }
+
+ SQLITE_COPY = 0;
+ SQLITE_CREATE_INDEX = 1;
+ SQLITE_CREATE_TABLE = 2;
+ SQLITE_CREATE_TEMP_INDEX = 3;
+ SQLITE_CREATE_TEMP_TABLE = 4;
+ SQLITE_CREATE_TEMP_TRIGGER = 5;
+ SQLITE_CREATE_TEMP_VIEW = 6;
+ SQLITE_CREATE_TRIGGER = 7;
+ SQLITE_CREATE_VIEW = 8;
+ SQLITE_DELETE = 9;
+ SQLITE_DROP_INDEX = 10;
+ SQLITE_DROP_TABLE = 11;
+ SQLITE_DROP_TEMP_INDEX = 12;
+ SQLITE_DROP_TEMP_TABLE = 13;
+ SQLITE_DROP_TEMP_TRIGGER = 14;
+ SQLITE_DROP_TEMP_VIEW = 15;
+ SQLITE_DROP_TRIGGER = 16;
+ SQLITE_DROP_VIEW = 17;
+ SQLITE_INSERT = 18;
+ SQLITE_PRAGMA = 19;
+ SQLITE_READ = 20;
+ SQLITE_SELECT = 21;
+ SQLITE_TRANSACTION = 22;
+ SQLITE_UPDATE = 23;
+ SQLITE_ATTACH = 24;
+ SQLITE_DETACH = 25;
+ SQLITE_ALTER_TABLE = 26;
+ SQLITE_REINDEX = 27;
+
+ SQLITE_DENY = 1;
+ SQLITE_IGNORE = 2;
+
+// Original from sqlite3.h:
+//#define SQLITE_STATIC ((void(*)(void *))0)
+//#define SQLITE_TRANSIENT ((void(*)(void *))-1)
+Const
+ SQLITE_STATIC = 0;
+ SQLITE_TRANSIENT = -1;
+
+type
+ sqlite_int64 = int64;
+ sqlite_uint64 = qword;
+ PPPChar = ^PPChar;
+ Psqlite3 = Pointer;
+ PPSqlite3 = ^PSqlite3;
+ Psqlite3_context = Pointer;
+ Psqlite3_stmt = Pointer;
+ PPsqlite3_stmt = ^Psqlite3_stmt;
+ Psqlite3_value = Pointer;
+ PPsqlite3_value = ^Psqlite3_value;
+
+//Callback function types
+//Notice that most functions were named using as prefix the function name that uses them,
+//rather than describing their functions
+
+ sqlite3_callback = function (_para1:pointer; _para2:longint; _para3:PPchar; _para4:PPchar):longint;cdecl;
+ busy_handler_func = function (_para1:pointer; _para2:longint):longint;cdecl;
+ sqlite3_set_authorizer_func = function (_para1:pointer; _para2:longint; _para3:Pchar; _para4:Pchar; _para5:Pchar; _para6:Pchar):longint;cdecl;
+ sqlite3_trace_func = procedure (_para1:pointer; _para2:Pchar);cdecl;
+ sqlite3_progress_handler_func = function (_para1:pointer):longint;cdecl;
+ sqlite3_commit_hook_func = function (_para1:pointer):longint;cdecl;
+ bind_destructor_func = procedure (_para1:pointer);cdecl;
+ create_function_step_func = procedure (_para1:Psqlite3_context; _para2:longint; _para3:PPsqlite3_value);cdecl;
+ create_function_func_func = procedure (_para1:Psqlite3_context; _para2:longint; _para3:PPsqlite3_value);cdecl;
+ create_function_final_func = procedure (_para1:Psqlite3_context);cdecl;
+ sqlite3_set_auxdata_func = procedure (_para1:pointer);cdecl;
+ sqlite3_result_func = procedure (_para1:pointer);cdecl;
+ sqlite3_create_collation_func = function (_para1:pointer; _para2:longint; _para3:pointer; _para4:longint; _para5:pointer):longint;cdecl;
+ sqlite3_collation_needed_func = procedure (_para1:pointer; _para2:Psqlite3; eTextRep:longint; _para4:Pchar);cdecl;
+
+{$ifndef win32}
+var
+ //This is not working under windows. Any clues?
+ sqlite3_temp_directory : Pchar;cvar; external;
+{$endif}
+
+{$IFNDEF LOAD_DYNAMICALLY}
+
+function sqlite3_close(_para1:Psqlite3):longint;cdecl; external Sqlite3Lib name 'sqlite3_close';
+function sqlite3_exec(_para1:Psqlite3; sql:Pchar; _para3:sqlite3_callback; _para4:pointer; errmsg:PPchar):longint;cdecl; external Sqlite3Lib name 'sqlite3_exec';
+function sqlite3_last_insert_rowid(_para1:Psqlite3):sqlite_int64;cdecl; external Sqlite3Lib name 'sqlite3_last_insert_rowid';
+function sqlite3_changes(_para1:Psqlite3):longint;cdecl; external Sqlite3Lib name 'sqlite3_changes';
+function sqlite3_total_changes(_para1:Psqlite3):longint;cdecl; external Sqlite3Lib name 'sqlite3_total_changes';
+procedure sqlite3_interrupt(_para1:Psqlite3);cdecl; external Sqlite3Lib name 'sqlite3_interrupt';
+function sqlite3_complete(sql:Pchar):longint;cdecl; external Sqlite3Lib name 'sqlite3_complete';
+function sqlite3_complete16(sql:pointer):longint;cdecl; external Sqlite3Lib name 'sqlite3_complete16';
+function sqlite3_busy_handler(_para1:Psqlite3; _para2:busy_handler_func; _para3:pointer):longint;cdecl; external Sqlite3Lib name 'sqlite3_busy_handler';
+function sqlite3_busy_timeout(_para1:Psqlite3; ms:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_busy_timeout';
+function sqlite3_get_table(_para1:Psqlite3; sql:Pchar; resultp:PPPchar; nrow:Plongint; ncolumn:Plongint; errmsg:PPchar):longint;cdecl; external Sqlite3Lib name 'sqlite3_get_table';
+procedure sqlite3_free_table(result:PPchar);cdecl; external Sqlite3Lib name 'sqlite3_free_table';
+// Todo: see how translate sqlite3_mprintf, sqlite3_vmprintf, sqlite3_snprintf
+// function sqlite3_mprintf(_para1:Pchar; args:array of const):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_mprintf';
+function sqlite3_mprintf(_para1:Pchar):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_mprintf';
+//function sqlite3_vmprintf(_para1:Pchar; _para2:va_list):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_vmprintf';
+procedure sqlite3_free(z:Pchar);cdecl; external Sqlite3Lib name 'sqlite3_free';
+//function sqlite3_snprintf(_para1:longint; _para2:Pchar; _para3:Pchar; args:array of const):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_snprintf';
+function sqlite3_snprintf(_para1:longint; _para2:Pchar; _para3:Pchar):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_snprintf';
+function sqlite3_set_authorizer(_para1:Psqlite3; xAuth:sqlite3_set_authorizer_func; pUserData:pointer):longint;cdecl; external Sqlite3Lib name 'sqlite3_set_authorizer';
+function sqlite3_trace(_para1:Psqlite3; xTrace:sqlite3_trace_func; _para3:pointer):pointer;cdecl; external Sqlite3Lib name 'sqlite3_trace';
+procedure sqlite3_progress_handler(_para1:Psqlite3; _para2:longint; _para3:sqlite3_progress_handler_func; _para4:pointer);cdecl; external Sqlite3Lib name 'sqlite3_progress_handler';
+function sqlite3_commit_hook(_para1:Psqlite3; _para2:sqlite3_commit_hook_func; _para3:pointer):pointer;cdecl; external Sqlite3Lib name 'sqlite3_commit_hook';
+function sqlite3_open(filename:Pchar; ppDb:PPsqlite3):longint;cdecl; external Sqlite3Lib name 'sqlite3_open';
+function sqlite3_open16(filename:pointer; ppDb:PPsqlite3):longint;cdecl; external Sqlite3Lib name 'sqlite3_open16';
+function sqlite3_errcode(db:Psqlite3):longint;cdecl; external Sqlite3Lib name 'sqlite3_errcode';
+function sqlite3_errmsg(_para1:Psqlite3):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_errmsg';
+function sqlite3_errmsg16(_para1:Psqlite3):pointer;cdecl; external Sqlite3Lib name 'sqlite3_errmsg16';
+function sqlite3_prepare(db:Psqlite3; zSql:Pchar; nBytes:longint; ppStmt:PPsqlite3_stmt; pzTail:PPchar):longint;cdecl; external Sqlite3Lib name 'sqlite3_prepare';
+function sqlite3_prepare16(db:Psqlite3; zSql:pointer; nBytes:longint; ppStmt:PPsqlite3_stmt; pzTail:Ppointer):longint;cdecl; external Sqlite3Lib name 'sqlite3_prepare16';
+function sqlite3_bind_blob(_para1:Psqlite3_stmt; _para2:longint; _para3:pointer; n:longint; _para5:bind_destructor_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_blob';
+function sqlite3_bind_double(_para1:Psqlite3_stmt; _para2:longint; _para3:double):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_double';
+function sqlite3_bind_int(_para1:Psqlite3_stmt; _para2:longint; _para3:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_int';
+function sqlite3_bind_int64(_para1:Psqlite3_stmt; _para2:longint; _para3:sqlite_int64):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_int64';
+function sqlite3_bind_null(_para1:Psqlite3_stmt; _para2:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_null';
+function sqlite3_bind_text(_para1:Psqlite3_stmt; _para2:longint; _para3:Pchar; n:longint; _para5:bind_destructor_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_text';
+function sqlite3_bind_text16(_para1:Psqlite3_stmt; _para2:longint; _para3:pointer; _para4:longint; _para5:bind_destructor_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_text16';
+//function sqlite3_bind_value(_para1:Psqlite3_stmt; _para2:longint; _para3:Psqlite3_value):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_value';
+//These overloaded functions were introduced to allow the use of SQLITE_STATIC and SQLITE_TRANSIENT
+//It's the c world man ;-)
+function sqlite3_bind_blob(_para1:Psqlite3_stmt; _para2:longint; _para3:pointer; n:longint; _para5:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_blob';
+function sqlite3_bind_text(_para1:Psqlite3_stmt; _para2:longint; _para3:Pchar; n:longint; _para5:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_text';
+function sqlite3_bind_text16(_para1:Psqlite3_stmt; _para2:longint; _para3:pointer; _para4:longint; _para5:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_text16';
+
+function sqlite3_bind_parameter_count(_para1:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_parameter_count';
+function sqlite3_bind_parameter_name(_para1:Psqlite3_stmt; _para2:longint):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_bind_parameter_name';
+function sqlite3_bind_parameter_index(_para1:Psqlite3_stmt; zName:Pchar):longint;cdecl; external Sqlite3Lib name 'sqlite3_bind_parameter_index';
+//function sqlite3_clear_bindings(_para1:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_clear_bindings';
+function sqlite3_column_count(pStmt:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_column_count';
+function sqlite3_column_name(_para1:Psqlite3_stmt; _para2:longint):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_column_name';
+function sqlite3_column_name16(_para1:Psqlite3_stmt; _para2:longint):pointer;cdecl; external Sqlite3Lib name 'sqlite3_column_name16';
+function sqlite3_column_decltype(_para1:Psqlite3_stmt; i:longint):Pchar;cdecl; external Sqlite3Lib name 'sqlite3_column_decltype';
+function sqlite3_column_decltype16(_para1:Psqlite3_stmt; _para2:longint):pointer;cdecl; external Sqlite3Lib name 'sqlite3_column_decltype16';
+function sqlite3_step(_para1:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_step';
+function sqlite3_data_count(pStmt:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_data_count';
+function sqlite3_column_blob(_para1:Psqlite3_stmt; iCol:longint):pointer;cdecl; external Sqlite3Lib name 'sqlite3_column_blob';
+function sqlite3_column_bytes(_para1:Psqlite3_stmt; iCol:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_column_bytes';
+function sqlite3_column_bytes16(_para1:Psqlite3_stmt; iCol:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_column_bytes16';
+function sqlite3_column_double(_para1:Psqlite3_stmt; iCol:longint):double;cdecl; external Sqlite3Lib name 'sqlite3_column_double';
+function sqlite3_column_int(_para1:Psqlite3_stmt; iCol:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_column_int';
+function sqlite3_column_int64(_para1:Psqlite3_stmt; iCol:longint):sqlite_int64;cdecl; external Sqlite3Lib name 'sqlite3_column_int64';
+function sqlite3_column_text(_para1:Psqlite3_stmt; iCol:longint):PChar;cdecl; external Sqlite3Lib name 'sqlite3_column_text';
+function sqlite3_column_text16(_para1:Psqlite3_stmt; iCol:longint):pointer;cdecl; external Sqlite3Lib name 'sqlite3_column_text16';
+function sqlite3_column_type(_para1:Psqlite3_stmt; iCol:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_column_type';
+function sqlite3_finalize(pStmt:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_finalize';
+function sqlite3_reset(pStmt:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_reset';
+function sqlite3_create_function(_para1:Psqlite3; zFunctionName:Pchar; nArg:longint; eTextRep:longint; _para5:pointer; xFunc:create_function_func_func; xStep:create_function_step_func; xFinal:create_function_final_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_create_function';
+function sqlite3_create_function16(_para1:Psqlite3; zFunctionName:pointer; nArg:longint; eTextRep:longint; _para5:pointer; xFunc:create_function_func_func; xStep:create_function_step_func; xFinal:create_function_final_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_create_function16';
+function sqlite3_aggregate_count(_para1:Psqlite3_context):longint;cdecl; external Sqlite3Lib name 'sqlite3_aggregate_count';
+function sqlite3_value_blob(_para1:Psqlite3_value):pointer;cdecl; external Sqlite3Lib name 'sqlite3_value_blob';
+function sqlite3_value_bytes(_para1:Psqlite3_value):longint;cdecl; external Sqlite3Lib name 'sqlite3_value_bytes';
+function sqlite3_value_bytes16(_para1:Psqlite3_value):longint;cdecl; external Sqlite3Lib name 'sqlite3_value_bytes16';
+function sqlite3_value_double(_para1:Psqlite3_value):double;cdecl; external Sqlite3Lib name 'sqlite3_value_double';
+function sqlite3_value_int(_para1:Psqlite3_value):longint;cdecl; external Sqlite3Lib name 'sqlite3_value_int';
+function sqlite3_value_int64(_para1:Psqlite3_value):sqlite_int64;cdecl; external Sqlite3Lib name 'sqlite3_value_int64';
+function sqlite3_value_text(_para1:Psqlite3_value):PChar;cdecl; external Sqlite3Lib name 'sqlite3_value_text';
+function sqlite3_value_text16(_para1:Psqlite3_value):pointer;cdecl; external Sqlite3Lib name 'sqlite3_value_text16';
+function sqlite3_value_text16le(_para1:Psqlite3_value):pointer;cdecl; external Sqlite3Lib name 'sqlite3_value_text16le';
+function sqlite3_value_text16be(_para1:Psqlite3_value):pointer;cdecl; external Sqlite3Lib name 'sqlite3_value_text16be';
+function sqlite3_value_type(_para1:Psqlite3_value):longint;cdecl; external Sqlite3Lib name 'sqlite3_value_type';
+function sqlite3_aggregate_context(_para1:Psqlite3_context; nBytes:longint):pointer;cdecl; external Sqlite3Lib name 'sqlite3_aggregate_context';
+function sqlite3_user_data(_para1:Psqlite3_context):pointer;cdecl; external Sqlite3Lib name 'sqlite3_user_data';
+function sqlite3_get_auxdata(_para1:Psqlite3_context; _para2:longint):pointer;cdecl; external Sqlite3Lib name 'sqlite3_get_auxdata';
+procedure sqlite3_set_auxdata(_para1:Psqlite3_context; _para2:longint; _para3:pointer; _para4:sqlite3_set_auxdata_func);cdecl; external Sqlite3Lib name 'sqlite3_set_auxdata';
+procedure sqlite3_result_blob(_para1:Psqlite3_context; _para2:pointer; _para3:longint; _para4:sqlite3_result_func);cdecl; external Sqlite3Lib name 'sqlite3_result_blob';
+procedure sqlite3_result_double(_para1:Psqlite3_context; _para2:double);cdecl; external Sqlite3Lib name 'sqlite3_result_double';
+procedure sqlite3_result_error(_para1:Psqlite3_context; _para2:Pchar; _para3:longint);cdecl; external Sqlite3Lib name 'sqlite3_result_error';
+procedure sqlite3_result_error16(_para1:Psqlite3_context; _para2:pointer; _para3:longint);cdecl; external Sqlite3Lib name 'sqlite3_result_error16';
+procedure sqlite3_result_int(_para1:Psqlite3_context; _para2:longint);cdecl; external Sqlite3Lib name 'sqlite3_result_int';
+procedure sqlite3_result_int64(_para1:Psqlite3_context; _para2:sqlite_int64);cdecl; external Sqlite3Lib name 'sqlite3_result_int64';
+procedure sqlite3_result_null(_para1:Psqlite3_context);cdecl; external Sqlite3Lib name 'sqlite3_result_null';
+procedure sqlite3_result_text(_para1:Psqlite3_context; _para2:Pchar; _para3:longint; _para4:sqlite3_result_func);cdecl; external Sqlite3Lib name 'sqlite3_result_text';
+procedure sqlite3_result_text16(_para1:Psqlite3_context; _para2:pointer; _para3:longint; _para4:sqlite3_result_func);cdecl; external Sqlite3Lib name 'sqlite3_result_text16';
+procedure sqlite3_result_text16le(_para1:Psqlite3_context; _para2:pointer; _para3:longint; _para4:sqlite3_result_func);cdecl; external Sqlite3Lib name 'sqlite3_result_text16le';
+procedure sqlite3_result_text16be(_para1:Psqlite3_context; _para2:pointer; _para3:longint; _para4:sqlite3_result_func);cdecl; external Sqlite3Lib name 'sqlite3_result_text16be';
+procedure sqlite3_result_value(_para1:Psqlite3_context; _para2:Psqlite3_value);cdecl; external Sqlite3Lib name 'sqlite3_result_value';
+function sqlite3_create_collation(_para1:Psqlite3; zName:Pchar; eTextRep:longint; _para4:pointer; xCompare:sqlite3_create_collation_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_create_collation';
+function sqlite3_create_collation16(_para1:Psqlite3; zName:Pchar; eTextRep:longint; _para4:pointer; xCompare:sqlite3_create_collation_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_create_collation16';
+function sqlite3_collation_needed(_para1:Psqlite3; _para2:pointer; _para3:sqlite3_collation_needed_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_collation_needed';
+function sqlite3_collation_needed16(_para1:Psqlite3; _para2:pointer; _para3:sqlite3_collation_needed_func):longint;cdecl; external Sqlite3Lib name 'sqlite3_collation_needed16';
+function sqlite3_libversion:PChar;cdecl; external Sqlite3Lib name 'sqlite3_libversion';
+//Alias for allowing better code portability (win32 is not working with external variables)
+function sqlite3_version:PChar;cdecl; external Sqlite3Lib name 'sqlite3_libversion';
+
+// Not published functions
+function sqlite3_libversion_number:longint;cdecl; external Sqlite3Lib name 'sqlite3_libversion_number';
+//function sqlite3_key(db:Psqlite3; pKey:pointer; nKey:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_key';
+//function sqlite3_rekey(db:Psqlite3; pKey:pointer; nKey:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_rekey';
+//function sqlite3_sleep(_para1:longint):longint;cdecl; external Sqlite3Lib name 'sqlite3_sleep';
+//function sqlite3_expired(_para1:Psqlite3_stmt):longint;cdecl; external Sqlite3Lib name 'sqlite3_expired';
+//function sqlite3_global_recover:longint;cdecl; external Sqlite3Lib name 'sqlite3_global_recover';
+
+{$ELSE LOAD_DYNAMICALLY}
+
+Var
+ sqlite3_close : function (_para1:Psqlite3):longint;cdecl;
+ sqlite3_exec : function (_para1:Psqlite3; sql:Pchar; _para3:sqlite3_callback; _para4:pointer; errmsg:PPchar):longint;cdecl;
+ sqlite3_last_insert_rowid : function (_para1:Psqlite3):sqlite_int64;cdecl;
+ sqlite3_changes : function (_para1:Psqlite3):longint;cdecl;
+ sqlite3_total_changes : function (_para1:Psqlite3):longint;cdecl;
+ sqlite3_interrupt : procedure (_para1:Psqlite3);cdecl;
+ sqlite3_complete : function (sql:Pchar):longint;cdecl;
+ sqlite3_complete16 : function (sql:pointer):longint;cdecl;
+ sqlite3_busy_handler : function (_para1:Psqlite3; _para2:busy_handler_func; _para3:pointer):longint;cdecl;
+ sqlite3_busy_timeout : function (_para1:Psqlite3; ms:longint):longint;cdecl;
+ sqlite3_get_table : function (_para1:Psqlite3; sql:Pchar; resultp:PPPchar; nrow:Plongint; ncolumn:Plongint; errmsg:PPchar):longint;cdecl;
+ sqlite3_free_table : procedure (result:PPchar);cdecl;
+// Todo: see how translate sqlite3_mprintf, sqlite3_vmprintf, sqlite3_snprintf
+// sqlite3_mprintf : function (_para1:Pchar; args:array of const):Pchar;cdecl;
+ sqlite3_mprintf : function (_para1:Pchar):Pchar;cdecl;
+// sqlite3_vmprintf : function (_para1:Pchar; _para2:va_list):Pchar;cdecl;
+ sqlite3_free : procedure (z:Pchar);cdecl;
+// sqlite3_snprintf : function (_para1:longint; _para2:Pchar; _para3:Pchar; args:array of const):Pchar;cdecl;
+ sqlite3_snprintf : function (_para1:longint; _para2:Pchar; _para3:Pchar):Pchar;cdecl;
+ sqlite3_set_authorizer : function (_para1:Psqlite3; xAuth:sqlite3_set_authorizer_func; pUserData:pointer):longint;cdecl;
+ sqlite3_trace : function (_para1:Psqlite3; xTrace:sqlite3_trace_func; _para3:pointer):pointer;cdecl;
+ sqlite3_progress_handler : procedure (_para1:Psqlite3; _para2:longint; _para3:sqlite3_progress_handler_func; _para4:pointer);cdecl;
+ sqlite3_commit_hook : function (_para1:Psqlite3; _para2:sqlite3_commit_hook_func; _para3:pointer):pointer;cdecl;
+ sqlite3_open : function (filename:Pchar; ppDb:PPsqlite3):longint;cdecl;
+ sqlite3_open16 : function (filename:pointer; ppDb:PPsqlite3):longint;cdecl;
+ sqlite3_errcode : function (db:Psqlite3):longint;cdecl;
+ sqlite3_errmsg : function (_para1:Psqlite3):Pchar;cdecl;
+ sqlite3_errmsg16 : function (_para1:Psqlite3):pointer;cdecl;
+ sqlite3_prepare : function (db:Psqlite3; zSql:Pchar; nBytes:longint; ppStmt:PPsqlite3_stmt; pzTail:PPchar):longint;cdecl;
+ sqlite3_prepare16 : function (db:Psqlite3; zSql:pointer; nBytes:longint; ppStmt:PPsqlite3_stmt; pzTail:Ppointer):longint;cdecl;
+ sqlite3_bind_blob : function (_para1:Psqlite3_stmt; _para2:longint; _para3:pointer; n:longint; _para5:bind_destructor_func):longint;cdecl;
+ sqlite3_bind_double : function (_para1:Psqlite3_stmt; _para2:longint; _para3:double):longint;cdecl;
+ sqlite3_bind_int : function (_para1:Psqlite3_stmt; _para2:longint; _para3:longint):longint;cdecl;
+ sqlite3_bind_int64 : function (_para1:Psqlite3_stmt; _para2:longint; _para3:sqlite_int64):longint;cdecl;
+ sqlite3_bind_null : function (_para1:Psqlite3_stmt; _para2:longint):longint;cdecl;
+ sqlite3_bind_text : function (_para1:Psqlite3_stmt; _para2:longint; _para3:Pchar; n:longint; _para5:bind_destructor_func):longint;cdecl;
+ sqlite3_bind_text16 : function (_para1:Psqlite3_stmt; _para2:longint; _para3:pointer; _para4:longint; _para5:bind_destructor_func):longint;cdecl;
+// sqlite3_bind_value : function (_para1:Psqlite3_stmt; _para2:longint; _para3:Psqlite3_value):longint;cdecl;
+//These overloaded functions were introduced to allow the use of SQLITE_STATIC and SQLITE_TRANSIENT
+//It's the c world man ;-)
+ sqlite3_bind_blob1 : function (_para1:Psqlite3_stmt; _para2:longint; _para3:pointer; n:longint; _para5:longint):longint;cdecl;
+ sqlite3_bind_text1 : function (_para1:Psqlite3_stmt; _para2:longint; _para3:Pchar; n:longint; _para5:longint):longint;cdecl;
+ sqlite3_bind_text161 : function (_para1:Psqlite3_stmt; _para2:longint; _para3:pointer; _para4:longint; _para5:longint):longint;cdecl;
+
+ sqlite3_bind_parameter_count : function (_para1:Psqlite3_stmt):longint;cdecl;
+ sqlite3_bind_parameter_name : function (_para1:Psqlite3_stmt; _para2:longint):Pchar;cdecl;
+ sqlite3_bind_parameter_index : function (_para1:Psqlite3_stmt; zName:Pchar):longint;cdecl;
+// sqlite3_clear_bindings : function (_para1:Psqlite3_stmt):longint;cdecl;
+ sqlite3_column_count : function (pStmt:Psqlite3_stmt):longint;cdecl;
+ sqlite3_column_name : function (_para1:Psqlite3_stmt; _para2:longint):Pchar;cdecl;
+ sqlite3_column_name16 : function (_para1:Psqlite3_stmt; _para2:longint):pointer;cdecl;
+ sqlite3_column_decltype : function (_para1:Psqlite3_stmt; i:longint):Pchar;cdecl;
+ sqlite3_column_decltype16 : function (_para1:Psqlite3_stmt; _para2:longint):pointer;cdecl;
+ sqlite3_step : function (_para1:Psqlite3_stmt):longint;cdecl;
+ sqlite3_data_count : function (pStmt:Psqlite3_stmt):longint;cdecl;
+ sqlite3_column_blob : function (_para1:Psqlite3_stmt; iCol:longint):pointer;cdecl;
+ sqlite3_column_bytes : function (_para1:Psqlite3_stmt; iCol:longint):longint;cdecl;
+ sqlite3_column_bytes16 : function (_para1:Psqlite3_stmt; iCol:longint):longint;cdecl;
+ sqlite3_column_double : function (_para1:Psqlite3_stmt; iCol:longint):double;cdecl;
+ sqlite3_column_int : function (_para1:Psqlite3_stmt; iCol:longint):longint;cdecl;
+ sqlite3_column_int64 : function (_para1:Psqlite3_stmt; iCol:longint):sqlite_int64;cdecl;
+ sqlite3_column_text : function (_para1:Psqlite3_stmt; iCol:longint):PChar;cdecl;
+ sqlite3_column_text16 : function (_para1:Psqlite3_stmt; iCol:longint):pointer;cdecl;
+ sqlite3_column_type : function (_para1:Psqlite3_stmt; iCol:longint):longint;cdecl;
+ sqlite3_finalize : function (pStmt:Psqlite3_stmt):longint;cdecl;
+ sqlite3_reset : function (pStmt:Psqlite3_stmt):longint;cdecl;
+ sqlite3_create_function : function (_para1:Psqlite3; zFunctionName:Pchar; nArg:longint; eTextRep:longint; _para5:pointer; xFunc:create_function_func_func; xStep:create_function_step_func; xFinal:create_function_final_func):longint;cdecl;
+ sqlite3_create_function16 : function (_para1:Psqlite3; zFunctionName:pointer; nArg:longint; eTextRep:longint; _para5:pointer; xFunc:create_function_func_func; xStep:create_function_step_func; xFinal:create_function_final_func):longint;cdecl;
+ sqlite3_aggregate_count : function (_para1:Psqlite3_context):longint;cdecl;
+ sqlite3_value_blob : function (_para1:Psqlite3_value):pointer;cdecl;
+ sqlite3_value_bytes : function (_para1:Psqlite3_value):longint;cdecl;
+ sqlite3_value_bytes16 : function (_para1:Psqlite3_value):longint;cdecl;
+ sqlite3_value_double : function (_para1:Psqlite3_value):double;cdecl;
+ sqlite3_value_int : function (_para1:Psqlite3_value):longint;cdecl;
+ sqlite3_value_int64 : function (_para1:Psqlite3_value):sqlite_int64;cdecl;
+ sqlite3_value_text : function (_para1:Psqlite3_value):PChar;cdecl;
+ sqlite3_value_text16 : function (_para1:Psqlite3_value):pointer;cdecl;
+ sqlite3_value_text16le : function (_para1:Psqlite3_value):pointer;cdecl;
+ sqlite3_value_text16be : function (_para1:Psqlite3_value):pointer;cdecl;
+ sqlite3_value_type : function (_para1:Psqlite3_value):longint;cdecl;
+ sqlite3_aggregate_context : function (_para1:Psqlite3_context; nBytes:longint):pointer;cdecl;
+ sqlite3_user_data : function (_para1:Psqlite3_context):pointer;cdecl;
+ sqlite3_get_auxdata : function (_para1:Psqlite3_context; _para2:longint):pointer;cdecl;
+ sqlite3_set_auxdata : procedure (_para1:Psqlite3_context; _para2:longint; _para3:pointer; _para4:sqlite3_set_auxdata_func);cdecl;
+ sqlite3_result_blob : procedure (_para1:Psqlite3_context; _para2:pointer; _para3:longint; _para4:sqlite3_result_func);cdecl;
+ sqlite3_result_double : procedure (_para1:Psqlite3_context; _para2:double);cdecl;
+ sqlite3_result_error : procedure (_para1:Psqlite3_context; _para2:Pchar; _para3:longint);cdecl;
+ sqlite3_result_error16 : procedure (_para1:Psqlite3_context; _para2:pointer; _para3:longint);cdecl;
+ sqlite3_result_int : procedure (_para1:Psqlite3_context; _para2:longint);cdecl;
+ sqlite3_result_int64 : procedure (_para1:Psqlite3_context; _para2:sqlite_int64);cdecl;
+ sqlite3_result_null : procedure (_para1:Psqlite3_context);cdecl;
+ sqlite3_result_text : procedure (_para1:Psqlite3_context; _para2:Pchar; _para3:longint; _para4:sqlite3_result_func);cdecl;
+ sqlite3_result_text16 : procedure (_para1:Psqlite3_context; _para2:pointer; _para3:longint; _para4:sqlite3_result_func);cdecl;
+ sqlite3_result_text16le : procedure (_para1:Psqlite3_context; _para2:pointer; _para3:longint; _para4:sqlite3_result_func);cdecl;
+ sqlite3_result_text16be : procedure (_para1:Psqlite3_context; _para2:pointer; _para3:longint; _para4:sqlite3_result_func);cdecl;
+ sqlite3_result_value : procedure (_para1:Psqlite3_context; _para2:Psqlite3_value);cdecl;
+ sqlite3_create_collation : function (_para1:Psqlite3; zName:Pchar; eTextRep:longint; _para4:pointer; xCompare:sqlite3_create_collation_func):longint;cdecl;
+ sqlite3_create_collation16 : function (_para1:Psqlite3; zName:Pchar; eTextRep:longint; _para4:pointer; xCompare:sqlite3_create_collation_func):longint;cdecl;
+ sqlite3_collation_needed : function (_para1:Psqlite3; _para2:pointer; _para3:sqlite3_collation_needed_func):longint;cdecl;
+ sqlite3_collation_needed16 : function (_para1:Psqlite3; _para2:pointer; _para3:sqlite3_collation_needed_func):longint;cdecl;
+ sqlite3_libversion: function : PChar;cdecl;
+//Alias for allowing better code portability (win32 is not working with external variables)
+ sqlite3_version: function: PChar;cdecl;
+
+// Not published functions
+ sqlite3_libversion_number : Function :longint;cdecl;
+// sqlite3_key : function (db:Psqlite3; pKey:pointer; nKey:longint):longint;cdecl;
+// sqlite3_rekey : function (db:Psqlite3; pKey:pointer; nKey:longint):longint;cdecl;
+// sqlite3_sleep : function (_para1:longint):longint;cdecl;
+// sqlite3_expired : function (_para1:Psqlite3_stmt):longint;cdecl;
+//function sqlite3_global_recover:longint;cdecl;
+
+Procedure InitialiseSQLite;
+Procedure InitialiseSQLite(LibraryName : String);
+Procedure ReleaseSQLite;
+
+var
+ SQLiteLibraryHandle : TLibHandle;
+ DefaultLibrary : String = Sqlite3Lib;
+
+{$ENDIF LOAD_DYNAMICALLY}
+
+implementation
+
+{$IFDEF LOAD_DYNAMICALLY}
+
+ResourceString
+ SErrLoadFailed = 'Can not load SQLite client library "%s". Check your installation.';
+ SErrAlreadyLoaded = 'SQLIte interface already initialized from library %s.';
+
+Procedure LoadAddresses(LibHandle : TLibHandle);
+
+begin
+ pointer(sqlite3_close) := GetProcedureAddress(LibHandle,'sqlite3_close');
+ pointer(sqlite3_exec) := GetProcedureAddress(LibHandle,'sqlite3_exec');
+ pointer(sqlite3_last_insert_rowid) := GetProcedureAddress(LibHandle,'sqlite3_last_insert_rowid');
+ pointer(sqlite3_changes) := GetProcedureAddress(LibHandle,'sqlite3_changes');
+ pointer(sqlite3_total_changes) := GetProcedureAddress(LibHandle,'sqlite3_total_changes');
+ pointer(sqlite3_interrupt) := GetProcedureAddress(LibHandle,'sqlite3_interrupt');
+ pointer(sqlite3_complete) := GetProcedureAddress(LibHandle,'sqlite3_complete');
+ pointer(sqlite3_complete16) := GetProcedureAddress(LibHandle,'sqlite3_complete16');
+ pointer(sqlite3_busy_handler) := GetProcedureAddress(LibHandle,'sqlite3_busy_handler');
+ pointer(sqlite3_busy_timeout) := GetProcedureAddress(LibHandle,'sqlite3_busy_timeout');
+ pointer(sqlite3_get_table) := GetProcedureAddress(LibHandle,'sqlite3_get_table');
+ pointer(sqlite3_free_table) := GetProcedureAddress(LibHandle,'sqlite3_free_table');
+// Todo: see how translate sqlite3_mprintf, sqlite3_vmprintf, sqlite3_snprintf
+// pointer(sqlite3_mprintf) := GetProcedureAddress(LibHandle,'sqlite3_mprintf');
+ pointer(sqlite3_mprintf) := GetProcedureAddress(LibHandle,'sqlite3_mprintf');
+// pointer(sqlite3_vmprintf) := GetProcedureAddress(LibHandle,'sqlite3_vmprintf');
+ pointer(sqlite3_free) := GetProcedureAddress(LibHandle,'sqlite3_free');
+// pointer(sqlite3_snprintf) := GetProcedureAddress(LibHandle,'sqlite3_snprintf');
+ pointer(sqlite3_snprintf) := GetProcedureAddress(LibHandle,'sqlite3_snprintf');
+ pointer(sqlite3_set_authorizer) := GetProcedureAddress(LibHandle,'sqlite3_set_authorizer');
+ pointer(sqlite3_trace) := GetProcedureAddress(LibHandle,'sqlite3_trace');
+ pointer(sqlite3_progress_handler) := GetProcedureAddress(LibHandle,'sqlite3_progress_handler');
+ pointer(sqlite3_commit_hook) := GetProcedureAddress(LibHandle,'sqlite3_commit_hook');
+ pointer(sqlite3_open) := GetProcedureAddress(LibHandle,'sqlite3_open');
+ pointer(sqlite3_open16) := GetProcedureAddress(LibHandle,'sqlite3_open16');
+ pointer(sqlite3_errcode) := GetProcedureAddress(LibHandle,'sqlite3_errcode');
+ pointer(sqlite3_errmsg) := GetProcedureAddress(LibHandle,'sqlite3_errmsg');
+ pointer(sqlite3_errmsg16) := GetProcedureAddress(LibHandle,'sqlite3_errmsg16');
+ pointer(sqlite3_prepare) := GetProcedureAddress(LibHandle,'sqlite3_prepare');
+ pointer(sqlite3_prepare16) := GetProcedureAddress(LibHandle,'sqlite3_prepare16');
+ pointer(sqlite3_bind_blob) := GetProcedureAddress(LibHandle,'sqlite3_bind_blob');
+ pointer(sqlite3_bind_double) := GetProcedureAddress(LibHandle,'sqlite3_bind_double');
+ pointer(sqlite3_bind_int) := GetProcedureAddress(LibHandle,'sqlite3_bind_int');
+ pointer(sqlite3_bind_int64) := GetProcedureAddress(LibHandle,'sqlite3_bind_int64');
+ pointer(sqlite3_bind_null) := GetProcedureAddress(LibHandle,'sqlite3_bind_null');
+ pointer(sqlite3_bind_text) := GetProcedureAddress(LibHandle,'sqlite3_bind_text');
+ pointer(sqlite3_bind_text16) := GetProcedureAddress(LibHandle,'sqlite3_bind_text16');
+// pointer(sqlite3_bind_value) := GetProcedureAddress(LibHandle,'sqlite3_bind_value');
+//These overloaded functions were introduced to allow the use of SQLITE_STATIC and SQLITE_TRANSIENT
+//It's the c world man ;-)
+ pointer(sqlite3_bind_blob1) := GetProcedureAddress(LibHandle,'sqlite3_bind_blob');
+ pointer(sqlite3_bind_text1) := GetProcedureAddress(LibHandle,'sqlite3_bind_text');
+ pointer(sqlite3_bind_text161) := GetProcedureAddress(LibHandle,'sqlite3_bind_text16');
+
+ pointer(sqlite3_bind_parameter_count) := GetProcedureAddress(LibHandle,'sqlite3_bind_parameter_count');
+ pointer(sqlite3_bind_parameter_name) := GetProcedureAddress(LibHandle,'sqlite3_bind_parameter_name');
+ pointer(sqlite3_bind_parameter_index) := GetProcedureAddress(LibHandle,'sqlite3_bind_parameter_index');
+// pointer(sqlite3_clear_bindings) := GetProcedureAddress(LibHandle,'sqlite3_clear_bindings');
+ pointer(sqlite3_column_count) := GetProcedureAddress(LibHandle,'sqlite3_column_count');
+ pointer(sqlite3_column_name) := GetProcedureAddress(LibHandle,'sqlite3_column_name');
+ pointer(sqlite3_column_name16) := GetProcedureAddress(LibHandle,'sqlite3_column_name16');
+ pointer(sqlite3_column_decltype) := GetProcedureAddress(LibHandle,'sqlite3_column_decltype');
+ pointer(sqlite3_column_decltype16) := GetProcedureAddress(LibHandle,'sqlite3_column_decltype16');
+ pointer(sqlite3_step) := GetProcedureAddress(LibHandle,'sqlite3_step');
+ pointer(sqlite3_data_count) := GetProcedureAddress(LibHandle,'sqlite3_data_count');
+ pointer(sqlite3_column_blob) := GetProcedureAddress(LibHandle,'sqlite3_column_blob');
+ pointer(sqlite3_column_bytes) := GetProcedureAddress(LibHandle,'sqlite3_column_bytes');
+ pointer(sqlite3_column_bytes16) := GetProcedureAddress(LibHandle,'sqlite3_column_bytes16');
+ pointer(sqlite3_column_double) := GetProcedureAddress(LibHandle,'sqlite3_column_double');
+ pointer(sqlite3_column_int) := GetProcedureAddress(LibHandle,'sqlite3_column_int');
+ pointer(sqlite3_column_int64) := GetProcedureAddress(LibHandle,'sqlite3_column_int64');
+ pointer(sqlite3_column_text) := GetProcedureAddress(LibHandle,'sqlite3_column_text');
+ pointer(sqlite3_column_text16) := GetProcedureAddress(LibHandle,'sqlite3_column_text16');
+ pointer(sqlite3_column_type) := GetProcedureAddress(LibHandle,'sqlite3_column_type');
+ pointer(sqlite3_finalize) := GetProcedureAddress(LibHandle,'sqlite3_finalize');
+ pointer(sqlite3_reset) := GetProcedureAddress(LibHandle,'sqlite3_reset');
+ pointer(sqlite3_create_function) := GetProcedureAddress(LibHandle,'sqlite3_create_function');
+ pointer(sqlite3_create_function16) := GetProcedureAddress(LibHandle,'sqlite3_create_function16');
+ pointer(sqlite3_aggregate_count) := GetProcedureAddress(LibHandle,'sqlite3_aggregate_count');
+ pointer(sqlite3_value_blob) := GetProcedureAddress(LibHandle,'sqlite3_value_blob');
+ pointer(sqlite3_value_bytes) := GetProcedureAddress(LibHandle,'sqlite3_value_bytes');
+ pointer(sqlite3_value_bytes16) := GetProcedureAddress(LibHandle,'sqlite3_value_bytes16');
+ pointer(sqlite3_value_double) := GetProcedureAddress(LibHandle,'sqlite3_value_double');
+ pointer(sqlite3_value_int) := GetProcedureAddress(LibHandle,'sqlite3_value_int');
+ pointer(sqlite3_value_int64) := GetProcedureAddress(LibHandle,'sqlite3_value_int64');
+ pointer(sqlite3_value_text) := GetProcedureAddress(LibHandle,'sqlite3_value_text');
+ pointer(sqlite3_value_text16) := GetProcedureAddress(LibHandle,'sqlite3_value_text16');
+ pointer(sqlite3_value_text16le) := GetProcedureAddress(LibHandle,'sqlite3_value_text16le');
+ pointer(sqlite3_value_text16be) := GetProcedureAddress(LibHandle,'sqlite3_value_text16be');
+ pointer(sqlite3_value_type) := GetProcedureAddress(LibHandle,'sqlite3_value_type');
+ pointer(sqlite3_aggregate_context) := GetProcedureAddress(LibHandle,'sqlite3_aggregate_context');
+ pointer(sqlite3_user_data) := GetProcedureAddress(LibHandle,'sqlite3_user_data');
+ pointer(sqlite3_get_auxdata) := GetProcedureAddress(LibHandle,'sqlite3_get_auxdata');
+ pointer(sqlite3_set_auxdata) := GetProcedureAddress(LibHandle,'sqlite3_set_auxdata');
+ pointer(sqlite3_result_blob) := GetProcedureAddress(LibHandle,'sqlite3_result_blob');
+ pointer(sqlite3_result_double) := GetProcedureAddress(LibHandle,'sqlite3_result_double');
+ pointer(sqlite3_result_error) := GetProcedureAddress(LibHandle,'sqlite3_result_error');
+ pointer(sqlite3_result_error16) := GetProcedureAddress(LibHandle,'sqlite3_result_error16');
+ pointer(sqlite3_result_int) := GetProcedureAddress(LibHandle,'sqlite3_result_int');
+ pointer(sqlite3_result_int64) := GetProcedureAddress(LibHandle,'sqlite3_result_int64');
+ pointer(sqlite3_result_null) := GetProcedureAddress(LibHandle,'sqlite3_result_null');
+ pointer(sqlite3_result_text) := GetProcedureAddress(LibHandle,'sqlite3_result_text');
+ pointer(sqlite3_result_text16) := GetProcedureAddress(LibHandle,'sqlite3_result_text16');
+ pointer(sqlite3_result_text16le) := GetProcedureAddress(LibHandle,'sqlite3_result_text16le');
+ pointer(sqlite3_result_text16be) := GetProcedureAddress(LibHandle,'sqlite3_result_text16be');
+ pointer(sqlite3_result_value) := GetProcedureAddress(LibHandle,'sqlite3_result_value');
+ pointer(sqlite3_create_collation) := GetProcedureAddress(LibHandle,'sqlite3_create_collation');
+ pointer(sqlite3_create_collation16) := GetProcedureAddress(LibHandle,'sqlite3_create_collation16');
+ pointer(sqlite3_collation_needed) := GetProcedureAddress(LibHandle,'sqlite3_collation_needed');
+ pointer(sqlite3_collation_needed16) := GetProcedureAddress(LibHandle,'sqlite3_collation_needed16');
+ pointer(sqlite3_libversion):=GetProcedureAddress(LibHandle,'sqlite3_libversion');
+//Alias for allowing better code portability (win32 is not working with external variables)
+ pointer(sqlite3_version):=GetProcedureAddress(LibHandle,'sqlite3_libversion');
+
+// Not published functions
+ pointer(sqlite3_libversion_number):=GetProcedureAddress(LibHandle,'sqlite3_libversion_number');
+// pointer(sqlite3_key) := GetProcedureAddress(LibHandle,'sqlite3_key');
+// pointer(sqlite3_rekey) := GetProcedureAddress(LibHandle,'sqlite3_rekey');
+// pointer(sqlite3_sleep) := GetProcedureAddress(LibHandle,'sqlite3_sleep');
+// pointer(sqlite3_expired) := GetProcedureAddress(LibHandle,'sqlite3_expired');
+// function sqlite3_global_recover:longint;cdecl;
+end;
+
+var
+ RefCount : integer;
+ LoadedLibrary : String;
+
+
+Function TryInitialiseSqlite(Const LibraryName : String) : Boolean;
+
+begin
+ Result:=False;
+ if (RefCount=0) then
+ begin
+ SQLiteLibraryHandle:=LoadLibrary(LibraryName);
+ Result:=(SQLiteLibraryHandle<>nilhandle);
+ If not Result then
+ Exit;
+ inc(RefCount);
+ LoadedLibrary:=LibraryName;
+ LoadAddresses(SQLiteLibraryHandle);
+ end
+ else
+ begin
+ If (LoadedLibrary<>LibraryName) then
+ Raise EInoutError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
+ inc(RefCount);
+ Result:=True;
+ end;
+end;
+
+Procedure InitialiseSQLite;
+
+begin
+ InitialiseSQLite(DefaultLibrary);
+end;
+
+
+Procedure InitialiseSQLite(LibraryName : String);
+
+begin
+ If Not TryInitialiseSQLIte(LibraryName) then
+ Raise EInOutError.CreateFmt(SErrLoadFailed,[LibraryName]);
+end;
+
+Procedure ReleaseSQLITE;
+
+begin
+ if RefCount>1 then
+ Dec(RefCount)
+ else if UnloadLibrary(SQLITELibraryHandle) then
+ begin
+ Dec(RefCount);
+ SQLITELibraryHandle := NilHandle;
+ LoadedLibrary:='';
+ end;
+end;
+
+{$ENDIF}
+
+end.
diff --git a/packages/sqlite/src/sqlite3.pp b/packages/sqlite/src/sqlite3.pp
new file mode 100644
index 0000000000..044542cf9e
--- /dev/null
+++ b/packages/sqlite/src/sqlite3.pp
@@ -0,0 +1,5 @@
+unit sqlite3;
+
+{$i sqlite3.inc}
+
+end. \ No newline at end of file
diff --git a/packages/sqlite/src/sqlite3db.pas b/packages/sqlite/src/sqlite3db.pas
new file mode 100644
index 0000000000..a7625b00db
--- /dev/null
+++ b/packages/sqlite/src/sqlite3db.pas
@@ -0,0 +1,494 @@
+{$mode objfpc}
+{$h+}
+{*************************************************************
+SQLite3 Object Oriented handle
+O. Rinaudo - 2005 - orinaudo@gmail.com
+G. Marcou - 2007 - g.marcou@chimie.u-strasbg.fr
+*************************************************************}
+
+unit SQLite3db;
+
+interface
+
+uses Classes,strings,sqlite3;
+{*************************************************************}
+{*************************************************************}
+type
+ TSQLiteExecCallback = function(Sender: pointer; Columns: Integer; ColumnValues: ppchar; ColumnNames: ppchar): integer of object; cdecl;
+ TSQLiteBusyCallback = function(Sender: TObject; BusyCount: integer): longint of object; cdecl;
+ TOnData = Procedure(Sender: TObject; Columns: Integer; ColumnNames, ColumnValues: String) of object;
+ TOnBusy = Procedure(Sender: TObject; BusyCount: integer; var Cancel: Boolean) of object;
+ TOnQueryComplete = Procedure(Sender: TObject) of object;
+
+ TSQLite = class(TObject)
+{*************************************************************}
+{*************************************************************}
+ private
+ fPSQlite: PPsqlite3;
+ fSQLite:Psqlite3;
+ fMsg: String;
+ fIsOpen: Boolean;
+ fBusy: Boolean;
+ fError: longint;
+ fVersion: String;
+ fEncoding: String;
+ fTable: TStrings;
+ fLstName: TStringList;
+ fLstVal: TStringList;
+ fOnData: TOnData;
+ fOnBusy: TOnBusy;
+ fOnQueryComplete: TOnQueryComplete;
+ fBusyTimeout: longint;
+ fPMsg: PChar;
+ fChangeCount: longint;
+ fNb_Champ : Integer;
+ fList_FieldName : TStringList;
+ fList_Field : TList;
+ procedure SetBusyTimeout(Timeout: integer);
+{*************************************************************}
+{*************************************************************}
+ public
+ constructor Create(DBFileName: String);
+ destructor Destroy; override;
+ function Query(Sql: String; Table: TStrings ): boolean;
+ function ErrorMessage(ErrNo: Integer): string;
+ function IsComplete(Sql: String): boolean;
+ function LastInsertRow: integer;
+ function Cancel: boolean;
+ function DatabaseDetails(Table: TStrings): boolean;
+ property LastErrorMessage: string read fMsg;
+ property LastError: longint read fError;
+ property Version: String read fVersion;
+ property Encoding: String read fEncoding;
+ property OnData: TOnData read fOnData write fOnData;
+ property OnBusy: TOnBusy read fOnBusy write fOnBusy;
+ property OnQueryComplete: TOnQueryComplete read fOnQueryComplete write fOnQueryComplete;
+ property BusyTimeout: longint read fBusyTimeout write SetBusyTimeout;
+ property ChangeCount: longint read fChangeCount;
+ property List_FieldName: TStringList read fList_FieldName write fList_FieldName;
+ property List_Field: TList read fList_Field write fList_Field;
+ property Nb_Champ: integer read fNb_Champ write fNb_Champ;
+ procedure SQLOnData(Sender: TObject; Columns: Integer; ColumnNames, ColumnValues: String);
+
+ end;
+function Pas2SQLStr(const PasString: string): string;
+function SQL2PasStr(const SQLString: string): string;
+function QuoteStr(const s: string; QuoteChar: Char ): string;
+function UnQuoteStr(const s: string; QuoteChar: Char ): string;
+procedure ValueList(const ColumnNames, ColumnValues: String; NameValuePairs: TStrings);
+{*************************************************************}
+{*************************************************************}
+implementation
+Const
+ DblQuote: Char = '"';
+ SngQuote: Char = #39;
+ DblSngQuote: String = #39#39;
+ Crlf: String = #13#10;
+ Tab: Char = #9;
+var
+ MsgNoError : String;
+{*************************************************************}
+{*************************************************************}
+function QuoteStr(const s: string; QuoteChar: Char ): string;
+{*************************************************************
+SQlite3 enclosing string with quotes
+G. Marcou
+*************************************************************}
+begin
+ Result := Concat(QuoteChar, s, QuoteChar);
+end;
+{*************************************************************}
+function UnQuoteStr(const s: string; QuoteChar: Char ): string;
+{*************************************************************
+SQlite3 Remove enclosing quotes from string
+G. Marcou
+*************************************************************}
+begin
+ Result := s;
+ if length(Result) > 1 then
+ begin
+ if Result[1] = QuoteChar then
+ Delete(Result, 1, 1);
+ if Result[Length(Result)] = QuoteChar then
+ Delete(Result, Length(Result), 1);
+ end;
+end;
+{*************************************************************}
+function Pas2SQLStr(const PasString: string): string;
+{*************************************************************
+SQlite3 SQL string are use double quotes, Pascal string use
+single quote.
+G. Marcou
+*************************************************************}
+var
+ n : integer;
+begin
+ Result := SQL2PasStr(PasString);
+ n := Length(Result);
+ while n > 0 do
+ begin
+ if Result[n] = SngQuote then
+ Insert(SngQuote, Result, n);
+ dec(n);
+ end;
+ Result := QuoteStr(Result,SngQuote);
+end;
+{*************************************************************}
+function SQL2PasStr(const SQLString: string): string;
+{*************************************************************
+SQlite3 SQL string are use double quotes, Pascal string use
+single quote.
+G. Marcou
+*************************************************************}
+var
+ p : integer;
+begin
+ Result := SQLString;
+ p := pos(DblSngQuote, Result);
+ while p > 0 do
+ begin
+ Delete(Result, p, 1);
+ p := pos(DblSngQuote, Result);
+ end;
+ Result := UnQuoteStr(Result,SngQuote);
+end;
+{*************************************************************}
+procedure ValueList(const ColumnNames, ColumnValues : String;
+NameValuePairs : TStrings);
+{*************************************************************
+SQlite3 build (name=value) pair list
+G. Marcou
+*************************************************************}
+var
+ n : integer;
+ lstName, lstValue : TStringList;
+begin
+ if NameValuePairs <> nil then
+ begin
+ lstName := TStringList.Create;
+ lstValue := TStringList.Create;
+ lstName.CommaText := ColumnNames;
+ lstValue.CommaText := ColumnValues;
+ NameValuePairs.Clear;
+ if lstName.Count = LstValue.Count then
+ if lstName.Count > 0 then
+ for n := 0 to lstName.Count - 1 do
+ NameValuePairs.Append(Concat(lstName.Strings[n], '=', lstValue.Strings[n]));
+ lstValue.Free;
+ lstName.Free;
+ end;
+end;
+{*************************************************************}
+{function SystemErrorMsg(ErrNo: Integer ): String;
+var
+ buf: PChar;
+ size: Integer;
+ MsgLen: Integer;
+begin}
+{ size := 256;
+ GetMem(buf, size);
+ If ErrNo = - 1 then
+ ErrNo := GetLastError;
+ MsgLen := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, ErrNo, 0, buf, size, nil);
+ if MsgLen = 0 then
+ Result := 'ERROR'
+ else
+ Result := buf;}
+{end;}
+{*************************************************************}
+function BusyCallback(Sender : pointer;
+BusyCount : integer): longint; cdecl;
+{*************************************************************
+SQlite3 busy callback
+G. Marcou
+*************************************************************}
+var
+ bCancel: Boolean;
+begin
+ Result := -1;
+ with TObject(Sender) as TSQLite do
+ begin
+ if Assigned(fOnBusy) then
+ begin
+ bCancel := False;
+ fOnBusy(Tobject(Sender), BusyCount, bCancel);
+ if bCancel then
+ Result := 0;
+ end;
+ end;
+end;
+{*************************************************************}
+function ExecCallback(Sender : Pointer;
+Columns : Integer;
+ColumnValues : PPChar;
+ColumnNames : PPchar): integer; cdecl;
+{*************************************************************
+SQlite3 Build table and data from callback
+G. Marcou
+*************************************************************}
+var
+ PVal, PName : ^PChar;
+ n : integer;
+ sVal, sName : String;
+begin
+ Result := 0;
+ with TObject(Sender) as TSQLite do
+ begin
+ if (Assigned(fOnData) or Assigned(fTable)) then
+ begin
+ fLstName.Clear;
+ fLstVal.Clear;
+ if Columns > 0 then
+ begin
+ PName := ColumnNames;
+ PVal := ColumnValues;
+ for n := 0 to Columns - 1 do
+ begin
+ fLstName.Append(PName^);
+ fLstVal.Append(PVal^);
+ inc(PName);
+ inc(PVal);
+ end;
+ end;
+ sVal := fLstVal.CommaText;
+ sName := fLstName.CommaText;
+ if Assigned(fOnData) then
+ fOnData(TObject(Sender), Columns, sName, sVal);
+ if Assigned(fTable) then
+ begin
+ if fTable.Count = 0 then
+ fTable.Append(sName);
+ fTable.Append(sVal);
+ end;
+ end;
+ end;
+end;
+{*************************************************************}
+procedure TSQLite.SQLOnData(Sender : TObject;
+Columns : Integer;
+ColumnNames, ColumnValues : String);
+{*************************************************************
+SQlite3 Fill up field list names and field list values
+G. Marcou
+*************************************************************}
+Var
+ InterS,val : String;
+ Field : TStringList;
+ {************************************************}
+ function Pos1(a: String ; s : char) : integer;
+ var i,j : Integer;
+ begin
+ j:=-1;
+ for i:=1 to length(a) Do
+ begin
+ if a[i] = s then
+ begin
+ j:=i;
+ break;
+ end;
+ end;
+ result:=j;
+ end; { Pos1 }
+ {*************************************************}
+begin
+ If Nb_Champ = -1 Then
+ Begin {Put the fields name in List_FieldName}
+ Nb_Champ:=Columns;
+ InterS:=ColumnNames;
+ While (Pos1(InterS,',') > 0) do
+ begin
+ val:=copy(InterS,1,Pos1(InterS,',')-1);
+ InterS:=copy(InterS,Pos1(InterS,',')+1,length(InterS));
+ List_FieldName.add(val);
+ end;
+ if length(InterS) > 0 then List_FieldName.add(InterS);
+ end;
+ {Put the list of TStringList of value}
+ Field :=TStringList.Create;
+ InterS:=ColumnValues;
+ While (Pos1(InterS,',') > 0) do
+ begin
+ val:=copy(InterS,1,Pos1(InterS,',')-1);
+ InterS:=copy(InterS,Pos1(InterS,',')+1,length(InterS));
+ Field.add(val);
+ end;
+ if length(InterS) > 0 then Field.add(InterS);
+ List_Field.add(Field);
+end;
+{*************************************************************}
+constructor TSQLite.Create(DBFileName: String);
+{*************************************************************
+SQlite3 constructor
+G. Marcou
+*************************************************************}
+var
+ name : pchar;
+begin
+ inherited Create;
+ List_FieldName := TStringList.Create;
+ List_Field := TList.Create;
+ fError := SQLITE_ERROR;
+ fIsOpen := False;
+ fLstName := TStringList.Create;
+ fLstVal := TStringList.Create;
+ fOnData := nil;
+ fOnBusy := nil;
+ fOnQueryComplete := nil;
+ fChangeCount := 0;
+ name:=StrAlloc (length(DBFileName)+1);
+ strpcopy(name,DBFileName);
+ OnData:=@SQLOnData;
+ writeln('Try to open');
+ sqlite3_open(name,@fSQLite);
+ writeln('Open success');
+ sqlite3_free(fPMsg);
+ writeln('Free memory');
+ if fSQLite <> nil then
+ begin
+ //fVersion := String(SQLite_Version);
+ //fEncoding := SQLite_Encoding;
+ fIsOpen := True;
+ fError := SQLITE_OK;
+ end;
+ fMsg := sqlite3_errmsg(fSQLite);
+end;
+{*************************************************************}
+destructor TSQLite.Destroy;
+{*************************************************************
+SQLite3 destructor
+G. Marcou
+*************************************************************}
+begin
+ if fIsOpen then
+ fError:=sqlite3_close(fSQLite);
+ fIsOpen := False;
+ fLstName.Free;
+ fLstVal.Free;
+ fSQLite := nil;
+ fOnData := nil;
+ fOnBusy := nil;
+ fOnQueryComplete := nil;
+ fLstName := nil;
+ fLstVal := nil;
+ List_FieldName.destroy;
+ List_Field.destroy;
+ inherited Destroy;
+end;
+{*************************************************************}
+function TSQLite.Query(Sql: String; Table: TStrings ): boolean;
+{*************************************************************
+SQLite3 query the database
+G. Marcou
+*************************************************************}
+//var
+// fPMsg: PChar;
+//var Psql : pchar;
+begin
+ fError := SQLITE_ERROR;
+ if fIsOpen then
+ begin
+ fPMsg := nil;
+ fBusy := True;
+ fTable := Table;
+ if fTable <> nil then
+ fTable.Clear;
+ List_FieldName.clear;
+ List_Field.clear;
+ Nb_Champ:=-1;
+ fError := sqlite3_exec(fSQLite, PChar(sql), @ExecCallback, Self, @fPMsg);
+ sqlite3_free(fPMsg);
+ fChangeCount := sqlite3_changes(fSQLite);
+ fTable := nil;
+ fBusy := False;
+ if Assigned(fOnQueryComplete) then
+ fOnQueryComplete(Self);
+ end;
+ fMsg := ErrorMessage(fError);
+ Result := (fError = SQLITE_OK);
+end;
+{*************************************************************}
+function TSQLite.Cancel: boolean;
+{*************************************************************
+SQLite3 interrupt database
+G. Marcou
+*************************************************************}
+begin
+ Result := False;
+ if fBusy and fIsOpen then
+ begin
+ sqlite3_interrupt(fSQLite);
+ fBusy := false;
+ Result := True;
+ end;
+end;
+{*************************************************************}
+procedure TSQLite.SetBusyTimeout(Timeout: Integer);
+{*************************************************************
+SQLite3 busy timeout
+G. Marcou
+*************************************************************}
+begin
+ fBusyTimeout := Timeout;
+ if fIsOpen then
+ begin
+ fError:=sqlite3_busy_timeout(fSQLite, fBusyTimeout);
+ if fBusyTimeout > 0 then
+ sqlite3_busy_handler(fSQLite, @BusyCallback, Self)
+ else
+ sqlite3_busy_handler(fSQLite, nil, nil);
+ end;
+end;
+{*************************************************************}
+function TSQLite.LastInsertRow: longint;
+{*************************************************************
+SQLite3 Get ID of the last inserted row
+G. Marcou
+*************************************************************}
+begin
+ if fIsOpen then
+ Result := sqlite3_last_insert_rowid(fSQLite)
+ else
+ Result := -1;
+end;
+{*************************************************************}
+function TSQLite.ErrorMessage(ErrNo: Integer): string;
+{*************************************************************
+SQLite3 Return comprehensive error message
+G. Marcou
+*************************************************************}
+begin
+ if ErrNo = 0 then
+ Result := MsgNoError
+ else
+ Result := sqlite3_errmsg(fSQLite);
+end;
+{*************************************************************}
+function TSQLite.IsComplete(Sql: String): boolean;
+{*************************************************************
+SQLite3 Return true when complete
+G. Marcou
+*************************************************************}
+var Psql : pchar;
+begin
+ Psql:=StrAlloc (length(Sql)+1);
+ strpcopy(Psql,Sql);
+// Writeln('Testing: ',psql);
+ Result := sqlite3_complete(Psql)<>0;
+ strdispose(Psql);
+end;
+{*************************************************************}
+function TSQLite.DatabaseDetails(Table: TStrings): boolean;
+{*************************************************************
+SQLite3 Query the database
+G. Marcou
+*************************************************************}
+begin
+ Result := Query('SELECT * FROM SQLITE_MASTER;', Table);
+end;
+{*************************************************************}
+{*************************************************************}
+initialization
+
+finalization
+
+end.
diff --git a/packages/sqlite/src/sqlite3dyn.pp b/packages/sqlite/src/sqlite3dyn.pp
new file mode 100644
index 0000000000..b720814741
--- /dev/null
+++ b/packages/sqlite/src/sqlite3dyn.pp
@@ -0,0 +1,7 @@
+unit sqlite3dyn;
+
+{$DEFINE LOAD_DYNAMICALLY}
+
+{$i sqlite3.inc}
+
+end. \ No newline at end of file
diff --git a/packages/sqlite/src/sqlitedb.pas b/packages/sqlite/src/sqlitedb.pas
new file mode 100644
index 0000000000..b07ae23950
--- /dev/null
+++ b/packages/sqlite/src/sqlitedb.pas
@@ -0,0 +1,410 @@
+{$mode objfpc}
+{$h+}
+
+unit SQLitedb;
+
+interface
+
+uses Classes,strings,sqlite;
+
+type
+ TSQLiteExecCallback = function(Sender: pointer; Columns: Integer; ColumnValues: ppchar; ColumnNames: ppchar): integer of object; cdecl;
+ TSQLiteBusyCallback = function(Sender: TObject; ObjectName: PChar; BusyCount: integer): integer of object; cdecl;
+ TOnData = Procedure(Sender: TObject; Columns: Integer; ColumnNames, ColumnValues: String) of object;
+ TOnBusy = Procedure(Sender: TObject; ObjectName: String; BusyCount: integer; var Cancel: Boolean) of object;
+ TOnQueryComplete = Procedure(Sender: TObject) of object;
+
+ TSQLite = class(TObject)
+ private
+ fSQLite: Pointer;
+ fMsg: String;
+ fIsOpen: Boolean;
+ fBusy: Boolean;
+ fError: Integer;
+ fVersion: String;
+ fEncoding: String;
+ fTable: TStrings;
+ fLstName: TStringList;
+ fLstVal: TStringList;
+ fOnData: TOnData;
+ fOnBusy: TOnBusy;
+ fOnQueryComplete: TOnQueryComplete;
+ fBusyTimeout: integer;
+ fPMsg: PChar;
+ fChangeCount: integer;
+ fNb_Champ : Integer;
+ fList_FieldName : TStringList;
+ fList_Field : TList;
+ procedure SetBusyTimeout(Timeout: integer);
+ public
+ constructor Create(DBFileName: String);
+ destructor Destroy; override;
+ function Query(Sql: String; Table: TStrings ): boolean;
+ function ErrorMessage(ErrNo: Integer): string;
+ function IsComplete(Sql: String): boolean;
+ function LastInsertRow: integer;
+ function Cancel: boolean;
+ function DatabaseDetails(Table: TStrings): boolean;
+ property LastErrorMessage: string read fMsg;
+ property LastError: Integer read fError;
+ property Version: String read fVersion;
+ property Encoding: String read fEncoding;
+ property OnData: TOnData read fOnData write fOnData;
+ property OnBusy: TOnBusy read fOnBusy write fOnBusy;
+ property OnQueryComplete: TOnQueryComplete read fOnQueryComplete write fOnQueryComplete;
+ property BusyTimeout: Integer read fBusyTimeout write SetBusyTimeout;
+ property ChangeCount: Integer read fChangeCount;
+ property List_FieldName: TStringList read fList_FieldName write fList_FieldName;
+ property List_Field: TList read fList_Field write fList_Field;
+ property Nb_Champ: integer read fNb_Champ write fNb_Champ;
+
+ procedure SQLOnData(Sender: TObject; Columns: Integer; ColumnNames, ColumnValues: String);
+
+ end;
+ function Pas2SQLStr(const PasString: string): string;
+ function SQL2PasStr(const SQLString: string): string;
+ function QuoteStr(const s: string; QuoteChar: Char ): string;
+ function UnQuoteStr(const s: string; QuoteChar: Char ): string;
+ procedure ValueList(const ColumnNames, ColumnValues: String; NameValuePairs: TStrings);
+
+implementation
+
+Const
+ DblQuote: Char = '"';
+ SngQuote: Char = #39;
+ Crlf: String = #13#10;
+ Tab: Char = #9;
+
+var
+ MsgNoError: String;
+
+function QuoteStr(const s: string; QuoteChar: Char ): string;
+begin
+ Result := Concat(QuoteChar, s, QuoteChar);
+end;
+
+function UnQuoteStr(const s: string; QuoteChar: Char ): string;
+begin
+ Result := s;
+ if length(Result) > 1 then
+ begin
+ if Result[1] = QuoteChar then
+ Delete(Result, 1, 1);
+ if Result[Length(Result)] = QuoteChar then
+ Delete(Result, Length(Result), 1);
+ end;
+end;
+
+function Pas2SQLStr(const PasString: string): string;
+var
+ n: integer;
+begin
+ Result := SQL2PasStr(PasString);
+ n := Length(Result);
+ while n > 0 do
+ begin
+ if Result[n] = SngQuote then
+ Insert(SngQuote, Result, n);
+ dec(n);
+ end;
+ Result := QuoteStr(Result,#39);
+end;
+
+function SQL2PasStr(const SQLString: string): string;
+const
+ DblSngQuote: String = #39#39;
+var
+ p: integer;
+begin
+ Result := SQLString;
+ p := pos(DblSngQuote, Result);
+ while p > 0 do
+ begin
+ Delete(Result, p, 1);
+ p := pos(DblSngQuote, Result);
+ end;
+ Result := UnQuoteStr(Result,#39);
+end;
+
+procedure ValueList(const ColumnNames, ColumnValues: String; NameValuePairs: TStrings);
+var
+ n: integer;
+ lstName, lstValue: TStringList;
+begin
+ if NameValuePairs <> nil then
+ begin
+ lstName := TStringList.Create;
+ lstValue := TStringList.Create;
+ lstName.CommaText := ColumnNames;
+ lstValue.CommaText := ColumnValues;
+ NameValuePairs.Clear;
+ if lstName.Count = LstValue.Count then
+ if lstName.Count > 0 then
+ for n := 0 to lstName.Count - 1 do
+ NameValuePairs.Append(Concat(lstName.Strings[n], '=', lstValue.Strings[n]));
+ lstValue.Free;
+ lstName.Free;
+ end;
+end;
+
+
+
+function SystemErrorMsg(ErrNo: Integer ): String;
+var
+ buf: PChar;
+ size: Integer;
+ MsgLen: Integer;
+begin
+{ size := 256;
+ GetMem(buf, size);
+ If ErrNo = - 1 then
+ ErrNo := GetLastError;
+ MsgLen := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, ErrNo, 0, buf, size, nil);
+ if MsgLen = 0 then
+ Result := 'ERROR'
+ else
+ Result := buf;}
+end;
+
+function BusyCallback(Sender: pointer; ObjectName: PChar; BusyCount: integer): integer; cdecl;
+var
+ sObjName: String;
+ bCancel: Boolean;
+begin
+ Result := -1;
+ with TObject(Sender) as TSQLite do
+ begin
+ if Assigned(fOnBusy) then
+ begin
+ bCancel := False;
+ sObjName := ObjectName;
+ fOnBusy(Tobject(Sender), sObjName, BusyCount, bCancel);
+ if bCancel then
+ Result := 0;
+ end;
+ end;
+end;
+
+function ExecCallback(Sender: Pointer; Columns: Integer; ColumnValues: PPChar; ColumnNames: PPchar): integer; cdecl;
+var
+ PVal, PName: ^PChar;
+ n: integer;
+ sVal, sName: String;
+begin
+ Result := 0;
+ with TObject(Sender) as TSQLite do
+ begin
+ if (Assigned(fOnData) or Assigned(fTable)) then
+ begin
+ fLstName.Clear;
+ fLstVal.Clear;
+ if Columns > 0 then
+ begin
+ PName := ColumnNames;
+ PVal := ColumnValues;
+ for n := 0 to Columns - 1 do
+ begin
+ fLstName.Append(PName^);
+ fLstVal.Append(PVal^);
+ inc(PName);
+ inc(PVal);
+ end;
+ end;
+ sVal := fLstVal.CommaText;
+ sName := fLstName.CommaText;
+ if Assigned(fOnData) then
+ fOnData(TObject(Sender), Columns, sName, sVal);
+ if Assigned(fTable) then
+ begin
+ if fTable.Count = 0 then
+ fTable.Append(sName);
+ fTable.Append(sVal);
+ end;
+ end;
+ end;
+end;
+
+
+procedure TSQLite.SQLOnData(Sender: TObject; Columns: Integer; ColumnNames, ColumnValues: String);
+Var i : Integer;
+ InterS,val : String;
+ Field : TStringList;
+
+ function Pos1(a: String ; s : char) : integer;
+ var i,j : Integer;
+
+ begin
+ j:=-1;
+ for i:=1 to length(a) Do
+ begin
+ if a[i] = s then
+ begin
+ j:=i;
+ break;
+ end;
+ end;
+ result:=j;
+ end;
+begin
+ If Nb_Champ = -1 Then
+ Begin // Put the fields name in List_FieldName
+ Nb_Champ:=Columns;
+ InterS:=ColumnNames;
+ While (Pos1(InterS,',') > 0) do
+ begin
+ val:=copy(InterS,1,Pos1(InterS,',')-1);
+ InterS:=copy(InterS,Pos1(InterS,',')+1,length(InterS));
+ List_FieldName.add(val);
+ end;
+ if length(InterS) > 0 then List_FieldName.add(InterS);
+ end;
+ // Put the list of TStringList of value
+ Field :=TStringList.Create;
+ InterS:=ColumnValues;
+ While (Pos1(InterS,',') > 0) do
+ begin
+ val:=copy(InterS,1,Pos1(InterS,',')-1);
+ InterS:=copy(InterS,Pos1(InterS,',')+1,length(InterS));
+ Field.add(val);
+ end;
+ if length(InterS) > 0 then Field.add(InterS);
+ List_Field.add(Field);
+end;
+
+constructor TSQLite.Create(DBFileName: String);
+var
+ fPMsg1: PChar;
+ name : pchar;
+begin
+ inherited Create;
+ List_FieldName := TStringList.Create;
+ List_Field := TList.Create;
+ fError := SQLITE_ERROR;
+ fIsOpen := False;
+ fLstName := TStringList.Create;
+ fLstVal := TStringList.Create;
+ fOnData := nil;
+ fOnBusy := nil;
+ fOnQueryComplete := nil;
+ fChangeCount := 0;
+ name:=StrAlloc (length(DBFileName)+1);
+ strpcopy(name,DBFileName);
+ OnData:=@SQLOnData;
+ fSQLite := SQLite_Open(name, 1, @fPMsg);
+ SQLite_FreeMem(fPMsg);
+ if fSQLite <> nil then
+ begin
+ //fVersion := String(SQLite_Version);
+ //fEncoding := SQLite_Encoding;
+ fIsOpen := True;
+ fError := SQLITE_OK;
+ end;
+ fMsg := ErrorMessage(fError);
+end;
+
+destructor TSQLite.Destroy;
+begin
+ if fIsOpen then
+ SQLite_Close(fSQLite);
+ fIsOpen := False;
+ fLstName.Free;
+ fLstVal.Free;
+ fSQLite := nil;
+ fOnData := nil;
+ fOnBusy := nil;
+ fOnQueryComplete := nil;
+ fLstName := nil;
+ fLstVal := nil;
+ List_FieldName.destroy;
+ List_Field.destroy;
+ inherited Destroy;
+end;
+
+function TSQLite.Query(Sql: String; Table: TStrings ): boolean;
+//var
+// fPMsg: PChar;
+//var Psql : pchar;
+begin
+ fError := SQLITE_ERROR;
+ if fIsOpen then
+ begin
+ fPMsg := nil;
+ fBusy := True;
+ fTable := Table;
+ if fTable <> nil then
+ fTable.Clear;
+ List_FieldName.clear;
+ List_Field.clear;
+ Nb_Champ:=-1;
+ fError := SQLite_Exec(fSQLite, PChar(sql), @ExecCallback, Self, @fPMsg);
+ SQLite_FreeMem(fPMsg);
+ fChangeCount := SQLite_Changes(fSQLite);
+ fTable := nil;
+ fBusy := False;
+ if Assigned(fOnQueryComplete) then
+ fOnQueryComplete(Self);
+ end;
+ fMsg := ErrorMessage(fError);
+ Result := (fError = SQLITE_OK);
+end;
+
+function TSQLite.Cancel: boolean;
+begin
+ Result := False;
+ if fBusy and fIsOpen then
+ begin
+ do_SQLite_interrupt(fSQLite);
+ fBusy := false;
+ Result := True;
+ end;
+end;
+
+procedure TSQLite.SetBusyTimeout(Timeout: Integer);
+begin
+ fBusyTimeout := Timeout;
+ if fIsOpen then
+ begin
+ SQLite_Busy_Timeout(fSQLite, fBusyTimeout);
+ if fBusyTimeout > 0 then
+ SQLite_Busy_Handler(fSQLite, @BusyCallback, Self)
+ else
+ SQLite_Busy_Handler(fSQLite, nil, nil);
+ end;
+end;
+
+function TSQLite.LastInsertRow: integer;
+begin
+ if fIsOpen then
+ Result := SQLite_Last_Insert_RowID(fSQLite)
+ else
+ Result := -1;
+end;
+
+function TSQLite.ErrorMessage(ErrNo: Integer): string;
+begin
+ if ErrNo = 0 then
+ Result := MsgNoError
+ else
+ Result := SQLite_Error_String(ErrNo);
+end;
+
+function TSQLite.IsComplete(Sql: String): boolean;
+var Psql : pchar;
+begin
+ Psql:=StrAlloc (length(Sql)+1);
+ strpcopy(Psql,Sql);
+ Writeln('Testing: ',psql);
+ Result := SQLite_Complete(Psql)<>0;
+ strdispose(Psql);
+end;
+
+function TSQLite.DatabaseDetails(Table: TStrings): boolean;
+begin
+ Result := Query('SELECT * FROM SQLITE_MASTER;', Table);
+end;
+
+initialization
+
+finalization
+
+end.
diff --git a/packages/sqlite/tests/test.pas b/packages/sqlite/tests/test.pas
new file mode 100644
index 0000000000..0a7121c75e
--- /dev/null
+++ b/packages/sqlite/tests/test.pas
@@ -0,0 +1,52 @@
+program test;
+
+uses sqlite,sqlitedb, strings,classes;
+
+var
+ MySQL: TSQLite;
+ SQL: String;
+ i, j: Integer;
+ a: TStringList;
+begin
+ Writeln('Creating class');
+ MySQL := TSQLite.Create('test.db');
+ MySQL.BusyTimeout := 1000;
+
+ // writeln(MySQL.Version);
+ Writeln('Creating table');
+ SQL := 'CREATE TABLE Test(No int, Nom varchar(32),Prenom varchar(32));';
+ MySQL.Query(sql, nil);
+ SQL := 'INSERT INTO Test VALUES(1,''Coursiere'', ''Olivier'');';
+ if MySQL.IsComplete(sql) then
+ begin
+ Writeln('Inserting first row');
+ MySQL.Query(sql, nil);
+ end;
+ SQL := 'INSERT INTO Test VALUES(2,''Jourde'', ''Eric'');';
+ if MySQL.IsComplete(sql) then
+ begin
+ Writeln('Inserting second row') ;
+ MySQL.Query(sql, nil);
+ end;
+ Writeln('Selecting rows') ;
+
+ SQL := 'SELECT * FROM Test;';
+ MySQL.Query(sql, nil);
+ writeln('Fields Names -------------------');
+ for i:=0 to MySQL.List_FieldName.count-1 do
+ writeln(i,' -> ',MySQL.List_FieldName.Strings[i]);
+ writeln('Fields -------------------');
+ for i:=0 to MySQL.List_Field.count-1 do
+ begin
+ a:=TStringList(MySQL.List_Field.items[i]);
+ write(i,' -> ');
+ for j:=0 to a.count-1 do
+ write(a.Strings[j],' ');
+ writeln('');
+ end;
+
+// Uncomment to remove table again.
+// SQL := 'DROP TABLE Test;';
+// MySQL.Query(sql, nil);
+ MySQL.Free;
+end.
diff --git a/packages/sqlite/tests/testapiv3x.README b/packages/sqlite/tests/testapiv3x.README
new file mode 100644
index 0000000000..90df74814e
--- /dev/null
+++ b/packages/sqlite/tests/testapiv3x.README
@@ -0,0 +1,44 @@
+Testing SQLite v3
+
+This prog is a simple direct api call
+sample for sqlite v3x.
+
+I.install
+1°)win32
+
+sqlite3.dll should be in default path or current dir
+and can be downloaded from here :
+ http://www.sqlite.org/
+
+
+2°)wince-arm
+
+.sqlite3.dll should be in default path or current dir
+and wince version can be downloaded from here :
+ http://sourceforge.net/projects/sqlite-wince
+this is a source only release need evc++4
+also pre-compiled libraries for arm-wince are
+on ftp://ftp.freepascal.org/pub/fpc/contrib/arm-wince-sqlite322.zip
+..shell/console is required on target system
+more info here : http://www.freepascal.org/wiki/index.php/WinCE_port
+...sqlite unit is not build automaticaly for arm-wince target
+add it in the path or build it manually
+
+II.tests
+
+2005/09/19 :
+ wince-arm :
+ testapvv3x have been tested with v3.2.2
+ compiled fpc2.1.1 today svn rep
+ command line for cross-compiling from XP:
+ fpc.exe -a -dNORMAL -Twince -Parm -XParm-wince-pe- -FDd:\binutils\win32-arm-pe -FE. -va testapiv3x.pp >test-arm-wince.log
+
+ win32 :
+ testapvv3x have been tested with v3.2.4
+ compiled fpc2.1.1 today svn rep under lazarus
+
+
+
+Regards
+olivier
+orinaudo@gmail.com
diff --git a/packages/sqlite/tests/testapiv3x.pp b/packages/sqlite/tests/testapiv3x.pp
new file mode 100644
index 0000000000..ea820980ce
--- /dev/null
+++ b/packages/sqlite/tests/testapiv3x.pp
@@ -0,0 +1,83 @@
+program testapiv3x;
+
+{$APPTYPE CONSOLE}
+{$MODE DELPHI}
+
+uses sqlite3, sysutils;
+
+const
+ DBFILE='dbtest.db';
+
+var
+ rc : Integer;
+ db : PPsqlite3;
+ sql : string;
+ pzErrMsg : PChar;
+
+function MyCallback(_para1:pointer; plArgc:longint; argv:PPchar; argcol:PPchar):longint; cdecl;
+var i: Integer;
+ PVal, PName: ^PChar;
+begin
+ PVal:=argv;
+ PName:=argcol;
+ for i:=0 to plArgc-1 do begin
+ writeln(Format('%s = ''%s'''#13, [PName^, PVal^]));
+ inc(PVal);
+ inc(PName);
+ end;
+ writeln(#13);
+ Result:=0;
+end;
+
+begin
+ writeln(Format('SQLite version : %d',[sqlite3_libversion_number]));
+ rc := sqlite3_open(PChar(DBFILE), @db);
+ try
+ if rc<>SQLITE_OK then begin
+ writeln(Format('Can''t open database: %s',[DBFILE]));
+ end;
+
+ sql:= 'DROP TABLE Test;';
+ rc:=sqlite3_exec(db, PChar(sql), @MyCallback, nil, @pzErrMsg);
+ if( rc<>SQLITE_OK )
+ then writeln(Format('SQL error: %s', [pzErrMsg^]));
+
+ sql:='CREATE TABLE Test(No integer, name varchar(32),shortname varchar(32), age integer);';
+ rc:=sqlite3_exec(db, PChar(sql), @MyCallback, nil, @pzErrMsg);
+ if( rc<>SQLITE_OK )
+ then writeln(Format('SQL error: %s', [pzErrMsg^]));
+
+ sql:='INSERT INTO Test VALUES(1,''hi'', ''by'', -1);';
+ rc:=sqlite3_exec(db, PChar(sql), @MyCallback, nil, @pzErrMsg);
+ Writeln('Inserting row');
+ if( rc<>SQLITE_OK )
+ then writeln(Format('SQL error: %s', [pzErrMsg^]));
+
+ SQL := 'INSERT INTO Test VALUES(2,''dualcore'', ''runwell'',-1);';
+ rc:=sqlite3_exec(db, PChar(sql), @MyCallback, nil, @pzErrMsg);
+ Writeln('Inserting row') ;
+ if( rc<>SQLITE_OK )
+ then writeln(Format('SQL error: %s', [pzErrMsg^]));
+
+ SQL := 'INSERT INTO Test VALUES(3,''Hello'', ''World'',NULL);';
+ rc:=sqlite3_exec(db, PChar(sql), @MyCallback, nil, @pzErrMsg);
+ Writeln('Inserting row') ;
+ if( rc<>SQLITE_OK )
+ then writeln(Format('SQL error: %s', [pzErrMsg^]));
+
+ SQL := 'INSERT INTO Test VALUES(4,''just a little'', ''test'',-1);';
+ rc:=sqlite3_exec(db, PChar(sql), @MyCallback, nil, @pzErrMsg);
+ Writeln('Inserting row') ;
+ if( rc<>SQLITE_OK )
+ then writeln(Format('SQL error: %s', [pzErrMsg^]));
+
+ SQL := 'select * from Test;';
+ rc:=sqlite3_exec(db, PChar(sql), @MyCallback, nil, @pzErrMsg);
+ if( rc<>SQLITE_OK )
+ then writeln(Format('SQL error: %s', [pzErrMsg^]));
+ finally sqlite3_close(db); end;
+
+ sleep(5000);
+end.
+
+