1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
...
type
T_sqlite3_open_v2 = function (filename: pchar; var sqlite3: pointer;flags:integer;zVfs:pointer): integer; cdecl;
T_sqlite3_close = function (sqlite3: pointer): integer; cdecl;
T_sqlite3_libversion = function:pchar; cdecl;
T_sqlite3_libversion_number = function:integer; cdecl;
T_sqlite3_prepare_v2 = function (sqlite3:pointer;sql:pchar;nBytes:integer;var stmt:pointer;var ztail:pchar):integer; cdecl;
T_sqlite3_step = function (sqlite3_stmt: pointer): integer; cdecl;
T_sqlite3_finalize = function (sqlite3_stmt: pointer): integer; cdecl;
T_sqlite3_column_text = function (sqlite3_stmt: pointer; col: integer): pchar; cdecl;
T_sqlite3_errmsg= function (sqlite3:pointer): pchar; cdecl;
const
SQLite3Path = 'C:\SQLite367';
SQLite367dll = 'SQLite367.dll';
var
hSQLite3: THandle;
user_sqlite3_open_v2: T_sqlite3_open_v2;
user_sqlite3_close: T_sqlite3_close;
user_sqlite3_libversion: T_sqlite3_libversion;
user_sqlite3_libversion_number: T_sqlite3_libversion_number;
user_sqlite3_prepare_v2: T_sqlite3_prepare_v2;
user_sqlite3_step: T_sqlite3_step;
user_sqlite3_finalize: T_sqlite3_finalize;
user_sqlite3_column_text: T_sqlite3_column_text;
user_sqlite3_errmsg: T_sqlite3_errmsg;
...
Implementation
// load library and connect to the required SQLite367 functions
procedure Load_sqlite3_interface;
begin
hSQLite3 := LoadLibrary(SQLite3Path+'\'+SQLite367dll);
@user_sqlite3_open_v2 := GetProcAddress(hSQLite3, pchar('sqlite3_open_v2'));
@user_sqlite3_close := GetProcAddress(hSQLite3, pchar('sqlite3_close'));
@user_sqlite3_libversion := GetProcAddress(hSQLite3, pchar('sqlite3_libversion'));
@user_sqlite3_libversion_number := GetProcAddress(hSQLite3, pchar('sqlite3_libversion_number'));
@user_sqlite3_prepare_v2 := GetProcAddress(hSQLite3, pchar('sqlite3_prepare_v2'));
@user_sqlite3_step := GetProcAddress(hSQLite3,pchar('sqlite3_step'));
@user_sqlite3_finalize := GetProcAddress(hSQLite3,pchar('sqlite3_finalize'));
@user_sqlite3_column_text := GetProcAddress(hSQLite3,pchar('sqlite3_column_text'));
@user_sqlite3_errmsg := GetProcAddress(hSQLite3,pchar('sqlite3_errmsg'));
end;
// unload library
procedure Unload_sqlite3_interface;
begin
FreeLibrary(hSQLite3);
end;
// interface functions replacind the wrapper within sqlite3.dll
function sqlite3_open_v2(filename: pchar; var sqlite3: pointer;flags:integer;zVfs:pointer): integer;
begin
result := user_sqlite3_open_v2(filename,sqlite3,flags,zVfs);
end;
function sqlite3_close(sqlite3: pointer): integer; cdecl;
begin
result := user_sqlite3_close(sqlite3);
end;
function sqlite3_libversion:pchar; cdecl;
begin
result := user_sqlite3_libversion;
end;
function sqlite3_libversion_number:integer;
begin
result := user_sqlite3_libversion_number;
end;
function sqlite3_prepare_v2(sqlite3:pointer;sql:pchar;nBytes:integer;var stmt:pointer;var ztail:pchar):integer; cdecl;
begin
result := user_sqlite3_prepare_v2(sqlite3,sql,nBytes,stmt,ztail);
end;
function sqlite3_step(sqlite3_stmt: pointer): integer; cdecl;
begin
result := user_sqlite3_step(sqlite3_stmt);
end;
function sqlite3_finalize(sqlite3_stmt: pointer): integer; cdecl;
begin
result := user_sqlite3_finalize(sqlite3_stmt);
end;
function sqlite3_column_text(sqlite3_stmt: pointer; col: integer): pchar; cdecl;
begin
result := user_sqlite3_column_text(sqlite3_stmt, col);
end;
function sqlite3_errmsg(sqlite3:pointer): pchar; cdecl;
begin
result := user_sqlite3_errmsg(sqlite3);
end;
{
************ fonctions générales *************
}
// initialiser l'environnement SQLite3: extraire la DLL si nécessaire
function InitializeSQLite3: integer; stdcall; export;
var
s: string;
begin
result := -1;
try
// créer le dossier C:\SQLite367 si nécessaire
//if not directoryexists(SQLite3Path) then showmessage('création de '+SQLite3Path);
if not directoryexists(SQLite3Path) then CreateDir(SQLite3Path);
s := SQLite3Path+'\'+SQLite367dll;
//if not FileExists(s) then showmessage('extact dans '+s);
if not FileExists(s) then ExtractResToFile('DATAFILE','SQLITE367',s); // récupérer le fichier SQLite3.dll
Load_sqlite3_interface;
result := 0;
except
end;
end;
exports InitializeSQLite3;
// purger l'environnement SQLite: supprimer SQLite367.dll
function ResetSQLite3: integer; stdcall; export;
var
s: string;
begin
result := -1;
try
Unload_sqlite3_interface;
result := 0;
except
end;
end;
exports ResetSQLite3;
... |
Partager