program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.IOUtils,
{$REGION 'FireDAC.*'}
FireDAC.Comp.Client,
FireDAC.Phys.SQLite,
FireDAC.Phys.SQLiteDef,
FireDAC.Stan.Def,
FireDAC.Stan.Async
{$ENDREGION}
;
type
TTest =
class
class procedure RunBuildScript(Sender: TObject);
class procedure Test();
class procedure InsertTestValues(
const connection: TFDConnection);
end;
class procedure TTest.Test();
const
filePath:
String = '
y:\myDatabase.db';
var
connection: TFdConnection;
driverLink: TFDPhysSQLiteDriverLink;
begin
connection :=
nil; driverLink :=
nil;
try
connection := TFDConnection.Create(
nil);
driverLink := TFDPhysSQLiteDriverLink.Create(
nil);
connection.DriverName := '
SQLite';
(connection.Params
as TFDPhysSQLiteConnectionDefParams).StringFormat :=
TFDSQLiteStringFormat.sfUnicode;
connection.Params.Database := filePath;
if not TFile.Exists(filePath)
then
connection.AfterConnect := TTest.RunBuildScript;
connection.Connected := True;
InsertTestValues(connection);
finally
connection.Free(); driverLink.Free();
end;
end;
class procedure TTest.RunBuildScript(Sender: TObject);
const
buildScript =
'
CREATE TABLE [myTable]('+
'
[id] TEXT PRIMARY KEY NOT NULL UNIQUE ON CONFLICT REPLACE, '+
'
[someText] TEXT);';
begin
(Sender
as TFDConnection).ExecSQL(buildScript);
end;
class procedure TTest.InsertTestValues(
const connection: TFDConnection);
const
donger = '
( ͡° ͜ʖ ͡°)';
statement = '
INSERT INTO [myTable] VALUES(:id, :someText)';
begin
connection.ExecSQL(statement, ['
Günther', donger]);
end;
begin
try
TTest.Test();
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
WriteLn(sLineBreak, '
end.'); ReadLn;
end.