For me it's very hard to work with components jSqliteDataAccess and jSqliteCursor, for multiple reasons (no parameters, case sensitive field names, 'eating' exceptions, problems with different SQlite versions on different phones, no compatibity with desktop database classes, ...).
So I tried to access SQlite on Android with ZEOSdbo.
I didn't install ZEOSdbo in Lazarus, I just unpacked it and set path in 'Other unit files (-Fu)' (to src\component, src\dbc, src\core, src\parsesql and src\plain).
From SQlite's website I downloaded precompiled binaries for Android, and put libsqliteX.so file to 'assets' directory of project. First I tried to put it in 'libs\arm64-v8a', but app was immediately crushing. I didn't investigate further why so.
To use libsqliteX.so first I saved it to file from assets:
const cLib = 'libsqliteX.so';
var sPathData: String;
...
sPathData := GetFilePath(fpathData) + '/';
if not FileExists(sPathData + cLib) then
Asset_SaveToFile(cLib, sPathData + cLib);
After that I set up connection and query:
var
ZConn: TZConnection;
Query: TZQuery;
...
ZConn := TZConnection.Create(nil);
Query := TZQuery.Create(nil);
try
//ZConn.Database := GetFilePath(fpathDataBase) + 'test.db';
ZConn.Database := GetFilePath(sPathData) + 'test.db';
ZConn.Protocol := 'sqlite';
ZConn.LibraryLocation := sPathData + cLib;
ZConn.Properties.Append('ExtendedErrorMessage=1'); // show detailed errors
ZConn.Connected := True;
Query.Connection := ZConn;
Query.SQL.Text := 'select sqlite_version() AS sqlite_version';
Query.Open;
Result := Query.FieldByName('sqlite_version').AsString;
finally
Query.Free;
ZConn.Free;
end;
One other thing: database path didn't work (GetFilePath(fpathDataBase)). I don't know why, so I used GetFilePath(sPathData).
Versions used: Lazarus 2.2.4 (rev lazarus_2_2_4-0-g06a78ed923) FPC 3.2.2 x86_64-win64-win32/win64, ZEOS: 7.2.14 version.
I am still testing, but for now it looks promising, and I am very happy.
I would like to hear from other any thoughts or suggestions. I could prepare demo project if anyone is interested.
I am especially interested why it doesn't work when libsqliteX.so is put in libs directory and why database can't be created in database directory.