Jump to content
at3s

FireDAC SQLite error upon table open

Recommended Posts

Few months ago I prepared small demo application used FireDAC SQLite connection on an Android system.

And it worked fine in an application built in Delphi 10.3.

Then I updated Delphi to 10.4.

And now I got:

Project xxx.apk raised exception class ESQLiteNativeException with message ''. 

and after that:

[FireDAC][Phys][SQLite] ERROR: no such table: items.

Even table 'items' exists in the database file and I did not any changes in sources.

 

Anyone had the same issue?

Edited by at3s

Share this post


Link to post

Keep all The Query components in data-module, if you keep FDconnection and Query or table in another form this error gives, i had the same issue. so then i kept all tables in side Data-module , its work fine.

  • Thanks 1

Share this post


Link to post
9 hours ago, JDS2018 said:

Keep all The Query components in data-module, if you keep FDconnection and Query or table in another form this error gives, i had the same issue. so then i kept all tables in side Data-module , its work fine.

Thank you for your answer.

Unfortunately it didn't fix my issue.

 

Probably I have to describe more details here.

My SQLite database has predefined tables inside with the data.

It's added to deploy to an Android device into 'assets\internal'.

But when I did:

FDConnection.Connected := True;
FDQuery.Open; 

the application raised an exception [FireDAC][Phys][SQLite] ERROR: no such table: items.

 

But when I've added code below:

procedure Tdm.FDConnectionBeforeConnect(Sender: TObject);
begin
  {$IF DEFINED(iOS) or DEFINED(ANDROID)}
  FDConnection.Params.Values['Database'] :=
      TPath.Combine(TPath.GetDocumentsPath, 'db.s3db');
  {$ENDIF}
end;

procedure Tdm.FDConnectionAfterConnect(Sender: TObject);
begin
  FDConnection.ExecSQL('CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY, image_name TEXT, name TEXT)');
end;

FDQuery opens properly.

It seems, that database file was not deployed to the Android device.

 

What I did wrong?

Share this post


Link to post

Hi,

 

You didn't specify the path. 

 

assests\internal is for deployment

 

TPath.GetDocumentsPath, 'db.s3db' is for PATH

 

br,

M

  • Thanks 1

Share this post


Link to post
2 minutes ago, mausmb said:

Hi,

 

You didn't specify the path. 

 

assests\internal is for deployment

 


TPath.GetDocumentsPath, 'db.s3db' is for PATH

 

br,

M

Well, I found solution. It was my bad.

I had

FDConnection.Params.OpenMode = omCreateUTF8

So changing it to omReadWrite rather is a solution.

  • Like 1

Share this post


Link to post

Use the FDConnection BeforeConnect event

   procedure TdbModule.fdConnectionBeforeConnect(Sender: TObject);
   {$IF DEFINED(MACOS)}
   var
      resourcesPath : String ;
      newPath       : String ;
      position      : Integer ;
   {$ENDIF)}
   begin
      // Get the correct Win, OSX, iOS or Android DB path
      fdConnection.Params.Values['Database'] := 'mydb.s3db' ;
      {$IF DEFINED(iOS) or DEFINED(ANDROID)}
         fdConnection.Params.Values['ColumnMetadataSupported'] := 'False' ;
         fdConnection.Params.Values['Database'] := TPath.Combine(TPath.GetDocumentsPath, 'mydb.s3db') ;
      {$ELSEIF DEFINED(MACOS)}
         resourcesPath := paramstr(0) ;
         position :=  Pos( '/Contents', resourcesPath ) ;
         newPath := paramstr(0).SubString(0, position )+'Contents/Resources/mydb.s3db' ;
         fdConnection.Params.Values['Database']:= newPath ;
      {$ENDIF}
   end;

Don't forget to add the db to the Project Deployment window and set Remote Path for each platform:

macOS: Contents\Resources\

iOS: StartUp\Documents\ (this one will show up the DB in FileSharing under iTunes or your device finder  - You can download, erase, add the file to the app)

iOS: Library/Application Support/[your app directory] for files you want accessible from your app but not from the user (not shared)

Android: .\assets\internal


 

  • Like 3

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×