4

I am trying to deploy an application to run on the android emulator using delphi that uses an SQLite database and populates a combobox with the query results.

I Have tested all the code on a Win32 application and everything is working as intended, however when i deploy the SQLite database and try to run the application on the emulator i raise an exception with "TDBXError with message" and the ErrorMessage contains 'no such table: cars'

Below is the code for my form.

    var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
begin
  // Populate Manufacturer box
  SQLConnection1.Connected := True;
  SQLQuery1.SQL.Clear;
  SQLQuery1.Close;
  SQLQuery1.SQL.Add('SELECT DISTINCT manufacturer FROM cars');
  try
    SQLQuery1.Open;
    cbManufac.Items.Clear;
    while not SQLQuery1.Eof do
    begin
      cbManufac.Items.Add(SQLQuery1.Fields[0].AsString);
      SQLQuery1.Next;
    end;
  finally
    SQLQuery1.Close;
  end;
end;

procedure TForm1.SQLConnection1BeforeConnect(Sender: TObject);
begin
  {$IF DEFINED(iOS) or DEFINED(ANDROID)}
  SQLConnection1.Params.Values['ColumnMetadataSupported'] := 'False';
  SQLConnection1.Params.Values['Database'] :=
      System.IOUtils.TPath.Combine(TPath.GetDocumentsPath, 'cars.sqlite');
  {$ENDIF}
end;

end.

I Have made sure System.IOUtils is added to uses and my database file is added under my projects deployment settings.

If i activate Win32 and test the application the combobox entries are added just fine.

On the form designer i am using TSQLConnection and TSQLQuery

Can anybody point me in the right direction.

Thanks

Abdullah Ilgaz
  • 719
  • 1
  • 17
  • 39
amit2k5
  • 97
  • 2
  • 9

1 Answers1

4

In the Deployment Manager, set your remote path for your database to assets\external. (See the documentation here for the difference between assets\internal and assets\external.)

Change your BeforeConnect event code to:

procedure TForm1.SQLConnection1BeforeConnect(Sender: TObject);
begin
  {$IF DEFINED(iOS) or DEFINED(ANDROID)}
  SQLConnection1.Params.Values['ColumnMetadataSupported'] := 'False';
  SQLConnection1.Params.Values['Database'] :=
      TPath.Combine(TPath.GetSharedDocumentsPath, 'cars.sqlite');
  {$ENDIF}
end;

To see the physical location of TPath.GetSharedDocumentsPath and other locations, see Standard RTL Path Functions Across the Supported Target Platforms.

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
Ken White
  • 123,280
  • 14
  • 225
  • 444