Recent

Author Topic: ZEOS in LAMW  (Read 955 times)

dseligo

  • Hero Member
  • *****
  • Posts: 1361
ZEOS in LAMW
« on: July 22, 2024, 10:11:44 am »
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:

Code: Pascal  [Select][+][-]
  1. const cLib = 'libsqliteX.so';
  2. var sPathData: String;
  3. ...
  4. sPathData := GetFilePath(fpathData) + '/';
  5.  
  6. if not FileExists(sPathData + cLib) then
  7.   Asset_SaveToFile(cLib, sPathData + cLib);

After that I set up connection and query:

Code: Pascal  [Select][+][-]
  1. var
  2.   ZConn: TZConnection;
  3.   Query: TZQuery;
  4.  
  5. ...
  6.  
  7.   ZConn := TZConnection.Create(nil);
  8.   Query := TZQuery.Create(nil);
  9.   try
  10.     //ZConn.Database := GetFilePath(fpathDataBase) + 'test.db';
  11.     ZConn.Database := GetFilePath(sPathData) + 'test.db';
  12.     ZConn.Protocol := 'sqlite';
  13.     ZConn.LibraryLocation := sPathData + cLib;
  14.     ZConn.Properties.Append('ExtendedErrorMessage=1'); // show detailed errors
  15.     ZConn.Connected := True;
  16.  
  17.     Query.Connection := ZConn;
  18.  
  19.     Query.SQL.Text := 'select sqlite_version() AS sqlite_version';
  20.     Query.Open;
  21.     Result := Query.FieldByName('sqlite_version').AsString;
  22.  
  23.   finally
  24.     Query.Free;
  25.     ZConn.Free;
  26.   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.

af0815

  • Hero Member
  • *****
  • Posts: 1365
Re: ZEOS in LAMW
« Reply #1 on: July 22, 2024, 10:30:45 am »
There is a Forum for ZEOS itself, maybe there is more information about possibilities of ZEOS with Android. https://zeoslib.sourceforge.io/viewforum.php?f=50

For me the idea itself is very interesting.
regards
Andreas

dseligo

  • Hero Member
  • *****
  • Posts: 1361
Re: ZEOS in LAMW
« Reply #2 on: August 07, 2024, 07:32:02 pm »
Just an update.
I am testing Zeos for a while know and everything works fine for now.

One other thing: database path didn't work (GetFilePath(fpathDataBase)). I don't know why, so I used GetFilePath(sPathData).

I discovered that if I first create database with jSqliteDataAccess I could use it later with Zeos in 'fpathDataBase'. Probably some Android/Java stuff going on. Anyway, for now I first check if my DB exists, if not, I create it with jSqliteDataAccess, disconnect and after that work with Zeos.

Quote
I am especially interested why it doesn't work when libsqliteX.so is put in libs directory

I still didn't get this to work. I checked with logcat and it says it didn't find some class "org.sqlite.database.sqlite.SQLiteCustomFunction", but I have no clue what to do with that.

Code: Text  [Select][+][-]
  1. 08-07 18:45:36.979 16841 16841 F mw.testrazno: java_vm_ext.cc:591] JNI DETECTED ERROR IN APPLICATION: JNI GetFieldID called with pending exception java.lang.ClassNotFoundException: Didn't find class "org.sqlite.database.sqlite.SQLiteCustomFunction" on path: DexPathList[[zip file "/data/app/~~y7ZR3DoN15qIvIpjEdVYfg==/org.lamw.testrazno-1VLPn2q1nQDIRDwBaMjDbQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~y7ZR3DoN15qIvIpjEdVYfg==/org.lamw.testrazno-1VLPn2q1nQDIRDwBaMjDbQ==/lib/arm64, /data/app/~~y7ZR3DoN15qIvIpjEdVYfg==/org.lamw.testrazno-1VLPn2q1nQDIRDwBaMjDbQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]

 

TinyPortal © 2005-2018