On 7-11-2011 8:23, Reinier Olislagers wrote:
> 2. You can apparently load the spatialite (and dependencies) dll/so as
> an extension to SQLite, with a statement like [3]
> select load_extension('libspatialite-4.dll');
> However, it seems you have to enable the extension load mechanism first
> using the C API [2]:
> int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
> (onoff==1 to turn extension loading on)
Attached diff (against fixes_2_6) seems to work for letting SQLite load
the libspatialite extension, e.g. using this in my Lazarus FormCreate event:
// Try to load extensions
DBConnection.DatabaseName:='osm.sqlite';
DBConnection.Open;
DBConnection.LoadExtension('libspatialite-4.dll');
//Note: we need an open db before doing this
Now I'm getting an error message saying that libfreexl-1.dll can't be
found, apparently an Excel reader library required by spatialite...
I'm going to ask the spatialite guys for clarification on this...
I'll upload the diff as a patch unless somebody has objections/a better
implementation...
Thanks,
Reinier
Index: packages/fcl-db/src/sqldb/sqlite/sqlite3conn.pp
===================================================================
--- packages/fcl-db/src/sqldb/sqlite/sqlite3conn.pp (revision 19599)
+++ packages/fcl-db/src/sqldb/sqlite/sqlite3conn.pp (working copy)
@@ -89,6 +89,7 @@
constructor Create(AOwner : TComponent); override;
function GetInsertID: int64;
procedure GetFieldNames(const TableName : string; List : TStrings);
override;
+ procedure LoadExtension(LibraryFile: string);
published
property Options: TSqliteOptions read FOptions write SetOptions;
end;
@@ -883,6 +884,24 @@
GetDBInfo(stColumns,TableName,'name',List);
end;
+procedure Tsqlite3connection.LoadExtension(Libraryfile: String);
+var
+ LoadResult: integer;
+begin
+ CheckConnected; //Apparently we need a connection before we can load
extensions.
+ try
+ LoadResult:=SQLITE_ERROR; //Default to failed
+ sqlite3_enable_load_extension(fhandle, 1); //Make sure we are allowed to
load
+ LoadResult:=sqlite3_load_extension(fhandle, PChar(LibraryFile), nil, nil);
//Actually load extension
+ if LoadResult=SQLITE_ERROR then
+ begin
+ DatabaseError('LoadExtension: failed to load SQLite extension (SQLite
returned an error while loading).',Self);
+ end;
+ except
+ DatabaseError('LoadExtension: failed to load SQLite extension.',Self);
+ end;
+end;
+
procedure TSQLite3Connection.setoptions(const avalue: tsqliteoptions);
begin
if avalue <> foptions then
_______________________________________________
fpc-pascal maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal