unit dDatabase;

interface

uses
  System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
  FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait,
  Data.DB, FireDAC.Comp.Client, FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef,
  FireDAC.Stan.ExprFuncs, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
  FireDAC.DApt, FireDAC.Comp.DataSet;

type
  TDatabaseModule = class(TDataModule)
    FDConnection1: TFDConnection;
    FDQuery1: TFDQuery;
    FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
    procedure DataModuleCreate(Sender: TObject);
  private
  public
    class procedure ExecSQL(const SQL: string);
  end;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}

procedure TDatabaseModule.DataModuleCreate(Sender: TObject);
begin
  FDConnection1.Params.Values['Database'] := ChangeFileExt(ParamStr(0), '.db');
end;

class procedure TDatabaseModule.ExecSQL(const SQL: string);
var
  DB: TDatabaseModule;
begin
  DB := TDatabaseModule.Create(nil);
  try
    DB.FDQuery1.SQL.Text := SQL;
    DB.FDQuery1.ExecSQL;
  finally
    DB.Free;
  end;
end;

end.
