按照DocWiki的指导,我将SQLite数据库部署到assets\internal\目录下,并使用以下代码:
SQLConnection1.Params.Values['Database'] :=
TPath.Combine(TPath.GetDocumentsPath, 'myDB.db');
然而,当我尝试访问其中一个表时,它并不存在。
对于SQLite,正确的部署和访问设置是什么?
按照DocWiki的指导,我将SQLite数据库部署到assets\internal\目录下,并使用以下代码:
SQLConnection1.Params.Values['Database'] :=
TPath.Combine(TPath.GetDocumentsPath, 'myDB.db');
然而,当我尝试访问其中一个表时,它并不存在。
对于SQLite,正确的部署和访问设置是什么?
我刚刚经历了将SQLite数据库部署到Android应用程序的过程。以下是我的心得体会。
与其将数据库与应用程序一起部署,我选择在连接时创建它,并在需要时创建表。
我还使用TFDConnection组件,而不是TSQLConnection组件。
因此,在TFDConnection的BeforeConnect事件中:
{$IF DEFINED(IOS) or DEFINED(ANDROID)}
FDConnection1.Params.Values['Database'] :=
TPath.GetDocumentsPath + PathDelim + 'MyDatabase.s3db';
{$ENDIF}
在TFDConnection的AfterConnect事件中:
FDConnection1.ExecSQL('CREATE TABLE IF NOT EXISTS MyTable (myField1 TEXT NOT NULL)');
我刚在模拟器和我的Droid X上测试了这个方法。
同时确保你包含了TFDGUIxWaitCursor和TFDPhysSQLiteDriverLink组件。
正确的部署集(所有配置 - Android 平台):
Local Name: myDB.db
Remote Path: .\assets\internal\
Remote Filename: myDB.db
BeforeConnection事件必须包含以下代码:
procedure TDM.conSQLiteBeforeConnect(Sender: TObject);
var
dbPath: string;
begin
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
dbPath := TPath.Combine(TPath.GetDocumentsPath, 'myDB.db');
{$ENDIF}
FDConnection1.Params.Values['Database'] := dbPath;
end;
Add使用了“System.IOUtils”。
在连接按钮中:
var
DbYol : string;
begin
DbYol := System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'SqliteDers.s3db';
With FDConnection1 do
begin
LoginPrompt := False;
Params.Clear;
Params.Values['Database'] := DbYol;
Params.Values['DriverID'] := 'SQLite';
Params.Values['CharacterSet'] := 'utf8';
Connected := True;
// Create new database if no exist
end;
With FDQuery1 do
begin
Active := False;
Connection := FDConnection1;
SQL.Clear;
SQL.Add( 'CREATE TABLE IF NOT EXISTS DERS (' );
SQL.Add( ' ADI nvarchar(10)');
SQL.Add( ' );');
ExecSQL;
göre ayarlıyoruz
SQL.Clear;
SQL.Add( 'SELECT');
SQL.Add( ' ADI' );
SQL.Add( ' FROM DERS' );
Active := True;
end;
http://www.brsatalay.com/xe5-mobil-uygulamada-sqlite-veritabani-kullanimi
我使用了FireDac。
FDConnection1.Params.Values['Database'] := '$(DOC)/QuickQuote.s3db';
我在FDConnection1BeforeConnect中使用它。
同时确保在部署中包含数据库文件。
我遵循了这个教程 点击这里
assets\internal\
中的数据库复制到文档路径? - mjn