[SOLVED] [LAMW] jSQLiteDataAccess doesn't seem to create a database file lazarus / 43-Android ---------------------------------------------------------------------- r.lukasiak · 2021-11-30 11:35 Hi everyone, I'm creating an app that needs Sqlite, I dropped jSQLiteDataAccess and jSqliteCursor onto my form. I set the database name and I fire: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  jSqliteDataAccess1.OpenOrCreate(jSqliteDataAccess1.DataBaseName)no errors reported. then I create a table using Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i jSqliteDataAccess1.CreateTable('CREATE TABLE.....')no errors either but Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i jSqliteDataAccess1.Select('SELECT * FROM...;')doesn't return anything. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i jSqliteCursor.GetRowCount returns 0. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i jSQLiteDataAccess.FullPathDataBaseNamegives me /data/user/0/org.myapp.myapp/Databases. I checked the location and it doesn't exists. I checked the demos and I didn't find anything different to what I'm doing. I thought it may be related to permissions so the app asks for WRITE_EXTERNAL_STORAGE and it's grant. Any idea what may be wrong? ---------------------------------------------------------------------- dseligo · 2021-11-30 15:09 After you create a table you need to insert data into it. So, before you do "select * from ..." you need "insert into ... (..., ..., ...) values (..., ..., ...). ---------------------------------------------------------------------- r.lukasiak · 2021-11-30 19:58 yes, of course, I did it. I'm sorry I forgot to mention. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQL.InsertIntoTable('INSERT INTO......); Anyway even the database file is not created and it should after just creating a table. ---------------------------------------------------------------------- dseligo · 2021-12-01 01:17 Did you set DatabaseName? I tried this code in emulator and it works (I attached screenshot of result): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.btnSQliteClick(Sender: TObject);var s: String;    i: Integer;begin  jSqliteDataAccess1.DataBaseName := 'my.db';  jSqliteDataAccess1.OpenOrCreate(jSqliteDataAccess1.DataBaseName);   jSqliteDataAccess1.CreateTable('create table if not exists jedan (id int primary key, name text not null)');   If jSqliteDataAccess1.InsertIntoTable('insert into jedan (id, name) values (10, ''dog'')') then    lvLog.Add('Row inserted.')  else    lvLog.Add('Row not inserted.');    s := jSqliteDataAccess1.Select('select * from jedan');  lvLog.Add('Res: '+s);   i := jSqliteCursor1.GetRowCount;  lvLog.Add('Rowcount: '+IntToStr(i));   s := jSQLiteDataAccess1.GetFullPathDataBaseName();  lvLog.Add(s);end; ---------------------------------------------------------------------- dseligo · 2021-12-01 01:24 Quote from: dseligo on December 01, 2021, 02:17:08 amI tried this code in emulator and it works (I attached screenshot of result): I tried this code in Galaxy S9 and it does work too. ---------------------------------------------------------------------- r.lukasiak · 2021-12-01 17:28 yes, I did. In Object Inspector and manually as well: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQL.DataBaseName := 'mydb.db';SQL.OpenOrCreate(SQL.DataBaseName); if SQL.CreateTable('CREATE TABLE IF NOT EXISTS...') then showmessage('table created!') else showmessage('table not created'); and I get the message "table created!", however no file is created in /data/user/0/org.myapp.myapp, there is no directory either but when inserting: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sqlstr:='INSERT INTO ....';if SQL.InsertIntoTable(sqlstr) then showmessage('inserted!') else showmessage('not inserted'); I get "not inserted". now I come to think, maybe I have some syntax error. I'll try with some simple INSERT clause. ---------------------------------------------------------------------- r.lukasiak · 2021-12-01 17:48 it looks like I had some syntax error in the INSERT clause. Now it shows "database created" and "inserted" and then SELECT returns the right number of rows so it seems to be ok but... GetFullPathDataBaseName() gives me /data/user/0/org.myapp.myapp but it doesn't exist or at least I can't see it. Where else the file may be possibly saved? I'm trying to use SQLiteManager to browse the db but I can't find the file. I close the app, run it again and it still shows the inserted rows. Reinstalling the app apparently deletes the db because each another version I install starts with number of rows: 0. I'm testing it on Nokia 5.4 which runs Android 11, in case it matters. ---------------------------------------------------------------------- dseligo · 2021-12-01 20:07 Quote from: r.lukasiak on November 30, 2021, 12:35:04 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i jSQLiteDataAccess.FullPathDataBaseNamegives me /data/user/0/org.myapp.myapp/Databases. I checked the location and it doesn't exists. Quote from: r.lukasiak on December 01, 2021, 06:48:26 pmbut... GetFullPathDataBaseName() gives me /data/user/0/org.myapp.myapp but it doesn't exist or at least I can't see it. What do you mean by 'gives me'? How does it give you? Maybe the path doesn't fit on your screen? Can you try my code (without modification)? ---------------------------------------------------------------------- r.lukasiak · 2021-12-01 20:37 I display it in a message after it creates the database: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i showmessage(SQL.GetFullPathDataBaseName()); ok, I'll test your code. ---------------------------------------------------------------------- r.lukasiak · 2021-12-01 20:51 I've just tested your code and the effect is the same. It's supposedly creating the db, table and inserting a row but there is no db file in the given location. ---------------------------------------------------------------------- dseligo · 2021-12-01 22:25 Quote from: r.lukasiak on December 01, 2021, 09:51:05 pmI've just tested your code and the effect is the same. It's supposedly creating the db, table and inserting a row but there is no db file in the given location. It creates db, it's just that you can't see it from some other app. It's probably Android's security or something similar. Try this code and you should see your files: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.jButton1Click(Sender: TObject);var sr: TSearchRec;begin  if FindFirst ('/data/user/0/org.lamw.applamwproject1/databases/*', faAnyFile, sr) = 0 then  begin    repeat      lvLog.Add(sr.Name + ' [' + IntToStr(sr.Size) + ']');    until FindNext(sr) <> 0;    FindClose(sr);  end  else    lvLog.Add('No files.');end; ---------------------------------------------------------------------- r.lukasiak · 2021-12-02 02:44 That's what I was thinking, Android somehow blocks access to it. Anyway I don't really need the file, as long as the db works, I started looking for it because I couldn't have the db work. It just beats me where the heck the file is I looks like the code you provided with neither can find the file. I added 3 rows and the fired your code. ---------------------------------------------------------------------- r.lukasiak · 2021-12-02 21:14 ok, it found it. The db is created from my app so it's named differently, I just copied your code as it is so it was searching a different location, my bad. Now I changed the search path and it's ok. I still can't access the file from an SQLiteManager but at least I know the file exists and it's in tact :-) Thanks a lot! ---------------------------------------------------------------------- dseligo · 2021-12-02 23:13 Np, glad it worked for you