* Patch from Reinier to implement library loader for Sqlite

git-svn-id: trunk@27342 -
This commit is contained in:
michael 2014-03-29 18:42:12 +00:00
parent 0082db46ea
commit dbf13fc77a
2 changed files with 34 additions and 3 deletions

View File

@ -111,6 +111,9 @@ type
class function TypeName: string; override;
class function ConnectionClass: TSQLConnectionClass; override;
class function Description: string; override;
class Function DefaultLibraryName : String; override;
class Function LoadFunction : TLibraryLoadFunction; override;
class Function UnLoadFunction : TLibraryUnLoadFunction; override;
class function LoadedLibraryName: string; override;
end;
@ -735,7 +738,8 @@ begin
Inherited;
if Length(databasename)=0 then
DatabaseError(SErrNoDatabaseName,self);
InitializeSqlite(SQLiteDefaultLibrary);
if (SQLiteLoadedLibrary='') then
InitializeSqlite(SQLiteDefaultLibrary);
str1:= databasename;
checkerror(sqlite3_open(pchar(str1),@fhandle));
if (Length(Password)>0) and assigned(sqlite3_key) then
@ -1027,11 +1031,26 @@ begin
Result := 'Connect to a SQLite3 database directly via the client library';
end;
class function TSQLite3ConnectionDef.DefaultLibraryName: string;
begin
Result := SQLiteDefaultLibrary;
end;
class function TSQLite3ConnectionDef.LoadedLibraryName: string;
begin
Result := SQLiteLoadedLibrary;
end;
class function TSQLite3ConnectionDef.LoadFunction: TLibraryLoadFunction;
begin
Result:=@InitializeSqliteANSI; //the function taking the filename argument
end;
class function TSQLite3ConnectionDef.UnLoadFunction: TLibraryUnLoadFunction;
begin
Result:=@ReleaseSQLite;
end;
initialization
RegisterConnection(TSQLite3ConnectionDef);

View File

@ -987,9 +987,11 @@ Type
{$IFDEF LOAD_DYNAMICALLY}
function InitializeSqliteANSI(const LibraryName: AnsiString = ''): Integer; //needed as TLibraryLoadFunction
function InitializeSqlite(const LibraryName: UnicodeString = ''): Integer;
function TryInitializeSqlite(const LibraryName: Unicodestring = ''): Integer;
function ReleaseSqlite: Integer;
procedure ReleaseSqlite; //needed as TLibraryUnLoadFunction
function InitialiseSQLite: Integer; deprecated;
function InitialiseSQLite(const LibraryName: UnicodeString): Integer; deprecated;
@ -1011,7 +1013,7 @@ end;
resourcestring
SErrLoadFailed = 'Can not load SQLite client library "%s". Check your installation.';
SErrAlreadyLoaded = 'SQLIte interface already initialized from library %s.';
SErrAlreadyLoaded = 'SQLite interface already initialized from library %s.';
procedure LoadAddresses(LibHandle: TLibHandle);
begin
@ -1238,12 +1240,17 @@ begin
result:=InitializeSqlite(SQLiteDefaultLibrary);
end;
function InitializeSQLiteANSI(const LibraryName: AnsiString):integer;
begin
result:=InitializeSQLite(LibraryName);
end;
function InitializeSQLite(const LibraryName: UnicodeString) :integer;
begin
if (LibraryName<>'') and (SQLiteLoadedLibrary <> '') and (SQLiteLoadedLibrary <> LibraryName) then
raise EInoutError.CreateFmt(SErrAlreadyLoaded,[SQLiteLoadedLibrary]);
result:= TryInitializeSQLIte(LibraryName);
result:= TryInitializeSQLite(LibraryName);
if result=-1 then
if LibraryName='' then
raise EInOutError.CreateFmt(SErrLoadFailed,[SQLiteDefaultLibrary])
@ -1268,4 +1275,9 @@ begin
end;
end;
procedure ReleaseSQLite;
begin
ReleaseSQLite;
end;
{$ENDIF}