[6.2.8 / SQLite] How to create an non existing SQLite database ?
Posted: Wed 07 Oct 2015 12:28
I'm getting "Unable to open database file" on non existing database file despite setting SQLite.ForceCreateDatabase=True !
Looks like I'm doing something wrong but I can't see it !
Code: Select all
procedure CreateDatabase;
var
Connection_Locale: TUniConnection;
Script_Local: TUniScript;
begin
Connection_Locale := TUniConnection.Create(nil);
Script_Local := TUniScript.Create(nil);
try
Script_Local.Connection := Connection_Locale;
Connection_Locale.ProviderName := 'SQLite';
Connection_Locale.Database := 'C:\Users\Public\Documents\SAS\Labels Printer\MyDB.DB3';
Connection_Locale.LoginPrompt := false;
Connection_Locale.SpecificOptions.Add('SQLite.ForceCreateDatabase=True');
Connection_Locale.SpecificOptions.Add('SQLite.Direct=True');
Connection_Locale.Connect;
try
Connection_Locale.StartTransaction;
Script_Local.SQL.Text := 'CREATE TABLE Ref_Compteurs (Reference string NOT NULL,Compteur integer,PRIMARY KEY (Reference));';
Script_Local.Execute;
Connection_Locale.Commit;
except
on e: Exception do
begin
if Connection_Locale.Connected then
Connection_Locale.Rollback;
raise;
end;
end;
finally
try
if Connection_Locale.Connected then
Connection_Locale.Close;
Script_Local.Free;
Connection_Locale.Free;
except
end;
end;
end;