2018-09-27 12:26:50 +02:00
|
|
|
unit MainFormU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Winapi.Windows,
|
|
|
|
Winapi.Messages,
|
|
|
|
System.SysUtils,
|
|
|
|
System.Variants,
|
|
|
|
System.Classes,
|
|
|
|
Vcl.Graphics,
|
|
|
|
Vcl.Controls,
|
|
|
|
Vcl.Forms,
|
|
|
|
Vcl.Dialogs,
|
|
|
|
Vcl.StdCtrls,
|
|
|
|
Vcl.ExtCtrls;
|
|
|
|
|
|
|
|
type
|
|
|
|
TMainForm = class(TForm)
|
|
|
|
Panel1: TPanel;
|
|
|
|
btnParse: TButton;
|
|
|
|
Panel2: TPanel;
|
|
|
|
mmSQL: TMemo;
|
|
|
|
Splitter1: TSplitter;
|
|
|
|
lbRQL: TListBox;
|
|
|
|
Panel3: TPanel;
|
|
|
|
edtExpression: TEdit;
|
|
|
|
btnAdd: TButton;
|
2018-10-23 16:18:34 +02:00
|
|
|
rgBackend: TRadioGroup;
|
|
|
|
Memo1: TMemo;
|
|
|
|
Splitter2: TSplitter;
|
2018-09-27 12:26:50 +02:00
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure btnAddClick(Sender: TObject);
|
|
|
|
procedure btnParseClick(Sender: TObject);
|
|
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
|
|
procedure lbRQLClick(Sender: TObject);
|
|
|
|
private
|
|
|
|
procedure SaveHistory;
|
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
MainForm: TMainForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.IOUtils,
|
2018-10-23 16:18:34 +02:00
|
|
|
MVCFramework.RQL.Parser,
|
2018-11-02 21:43:09 +01:00
|
|
|
System.TypInfo,
|
|
|
|
MVCFramework.RQL.AST2FirebirdSQL,
|
2019-06-24 20:59:33 +02:00
|
|
|
MVCFramework.RQL.AST2InterbaseSQL,
|
|
|
|
MVCFramework.RQL.AST2SQLite,
|
|
|
|
MVCFramework.RQL.AST2PostgreSQL,
|
|
|
|
MVCFramework.RQL.AST2MSSQL,
|
2018-11-02 21:43:09 +01:00
|
|
|
MVCFramework.RQL.AST2MySQL;
|
2018-09-27 12:26:50 +02:00
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
procedure TMainForm.FormCreate(Sender: TObject);
|
2018-10-23 16:18:34 +02:00
|
|
|
var
|
2018-11-02 21:43:09 +01:00
|
|
|
lComp: string;
|
2018-09-27 12:26:50 +02:00
|
|
|
begin
|
|
|
|
if TFile.Exists('rqlhistory.txt') then
|
|
|
|
begin
|
|
|
|
lbRQL.Items.LoadFromFile('rqlhistory.txt');
|
|
|
|
end;
|
2018-10-23 16:18:34 +02:00
|
|
|
|
|
|
|
rgBackend.Items.Clear;
|
2018-11-02 21:43:09 +01:00
|
|
|
for lComp in TRQLCompilerRegistry.Instance.RegisteredCompilers do
|
2018-10-23 16:18:34 +02:00
|
|
|
begin
|
2018-11-02 21:43:09 +01:00
|
|
|
rgBackend.Items.AddObject(lComp, TRQLCompilerRegistry.Instance.GetCompiler(lComp).Create(nil));
|
2018-10-23 16:18:34 +02:00
|
|
|
end;
|
|
|
|
rgBackend.ItemIndex := 0;
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.btnAddClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if not Trim(edtExpression.Text).IsEmpty then
|
|
|
|
begin
|
|
|
|
lbRQL.Items.Insert(0, edtExpression.Text);
|
|
|
|
SaveHistory;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.btnParseClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
lParser: TRQL2SQL;
|
|
|
|
lSQL: string;
|
|
|
|
begin
|
|
|
|
lParser := TRQL2SQL.Create;
|
|
|
|
try
|
2018-10-23 16:18:34 +02:00
|
|
|
try
|
2018-11-02 21:43:09 +01:00
|
|
|
lParser.Execute(edtExpression.Text, lSQL, TRQLCompiler(rgBackend.Items.Objects[rgBackend.ItemIndex]));
|
2018-10-23 16:18:34 +02:00
|
|
|
mmSQL.Lines.Text := lSQL;
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
begin
|
|
|
|
Memo1.Lines.Text := E.Message;
|
|
|
|
end;
|
|
|
|
end;
|
2018-09-27 12:26:50 +02:00
|
|
|
finally
|
|
|
|
lParser.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
|
2018-11-02 21:43:09 +01:00
|
|
|
var
|
|
|
|
i: Integer;
|
2018-09-27 12:26:50 +02:00
|
|
|
begin
|
|
|
|
SaveHistory;
|
2018-11-02 21:43:09 +01:00
|
|
|
for i := 0 to rgBackend.Items.count - 1 do
|
|
|
|
begin
|
|
|
|
rgBackend.Items.Objects[i].Free;
|
|
|
|
end;
|
2018-09-27 12:26:50 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.lbRQLClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
edtExpression.Text := lbRQL.Items[lbRQL.ItemIndex];
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMainForm.SaveHistory;
|
|
|
|
begin
|
|
|
|
lbRQL.Items.SaveToFile('rqlhistory.txt');
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|