[英]Deploying SQLite database to Android with Delphi FireMonkey
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. 我试图使用delphi使用SQLite数据库部署应用程序在Android模拟器上运行,并使用查询结果填充组合框。
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' 我已经测试了Win32应用程序上的所有代码,一切都按预期工作,但是当我部署SQLite数据库并尝试在模拟器上运行应用程序时,我引发了带有“带消息的TDBXError”的异常,并且ErrorMessage包含'没有这样的桌子:汽车'
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. 我已确保将System.IOUtils添加到用途中,并在我的项目部署设置下添加了我的数据库文件。
If i activate Win32 and test the application the combobox entries are added just fine. 如果我激活Win32并测试应用程序,则组合框条目添加得很好。
On the form designer i am using TSQLConnection and TSQLQuery 在表单设计器上我使用TSQLConnection和TSQLQuery
Can anybody point me in the right direction. 任何人都可以指出我正确的方向。
Thanks 谢谢
In the Deployment Manager, set your remote path for your database to assets\\external
. 在Deployment Manager中,将数据库的远程路径设置为assets\\external
。 (See the documentation here for the difference between assets\\internal
and assets\\external
.) (有关assets\\internal
和assets\\external
之间的区别,请参阅此处的文档 。)
Change your BeforeConnect
event code to: 将BeforeConnect
事件代码更改为:
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 . 要查看TPath.GetSharedDocumentsPath
和其他位置的物理位置,请参阅支持的目标平台上的标准RTL路径功能 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.