23 |
|
* Contributor(s): ______________________________________. |
24 |
|
* |
25 |
|
*) |
26 |
– |
|
26 |
|
unit ibdeletesqleditor; |
27 |
|
|
28 |
|
{$mode objfpc}{$H+} |
30 |
|
interface |
31 |
|
|
32 |
|
uses |
33 |
< |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, |
34 |
< |
StdCtrls, IBSystemTables, IBDatabase; |
33 |
> |
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, |
34 |
> |
ibselectsqleditor, IBDatabase, IBCustomDataset; |
35 |
|
|
36 |
|
type |
37 |
|
|
38 |
|
{ TIBDeleteSQLEditorForm } |
39 |
|
|
40 |
< |
TIBDeleteSQLEditorForm = class(TForm) |
42 |
< |
Button1: TButton; |
43 |
< |
Button2: TButton; |
44 |
< |
GenerateBtn: TButton; |
45 |
< |
TestBtn: TButton; |
46 |
< |
IBTransaction1: TIBTransaction; |
47 |
< |
Label1: TLabel; |
48 |
< |
Label3: TLabel; |
49 |
< |
Label4: TLabel; |
50 |
< |
PrimaryKeyList: TListBox; |
51 |
< |
QuoteFields: TCheckBox; |
52 |
< |
SQLText: TMemo; |
53 |
< |
TableNamesCombo: TComboBox; |
40 |
> |
TIBDeleteSQLEditorForm = class(TIBSelectSQLEditorForm) |
41 |
|
procedure GenerateBtnClick(Sender: TObject); |
55 |
– |
procedure TestBtnClick(Sender: TObject); |
56 |
– |
procedure FormShow(Sender: TObject); |
57 |
– |
procedure PrimaryKeyListDblClick(Sender: TObject); |
58 |
– |
procedure TableNamesComboCloseUp(Sender: TObject); |
42 |
|
private |
43 |
< |
{ private declarations } |
61 |
< |
FIBSystemTables: TIBSystemTables; |
43 |
> |
|
44 |
|
public |
45 |
< |
{ public declarations } |
46 |
< |
constructor Create(TheOwner: TComponent); override; |
47 |
< |
destructor Destroy; override; |
48 |
< |
procedure SetDatabase(Database: TIBDatabase); |
67 |
< |
end; |
45 |
> |
|
46 |
> |
end; |
47 |
> |
|
48 |
> |
function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean; |
49 |
|
|
50 |
|
var |
51 |
|
IBDeleteSQLEditorForm: TIBDeleteSQLEditorForm; |
52 |
|
|
72 |
– |
function EditSQL(Database: TIBDatabase; SelectSQL: TStrings): boolean; |
73 |
– |
|
53 |
|
implementation |
54 |
|
|
55 |
|
{$R *.lfm} |
56 |
|
|
57 |
< |
function EditSQL(Database: TIBDatabase; SelectSQL: TStrings): boolean; |
57 |
> |
function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean; |
58 |
|
begin |
59 |
|
Result := false; |
60 |
< |
if assigned(Database) then |
60 |
> |
if assigned(DataSet) and assigned(DataSet.Database) then |
61 |
|
try |
62 |
< |
Database.Connected := true; |
62 |
> |
DataSet.Database.Connected := true; |
63 |
|
except on E: Exception do |
64 |
|
ShowMessage(E.Message) |
65 |
|
end; |
66 |
|
|
67 |
|
with TIBDeleteSQLEditorForm.Create(Application) do |
68 |
|
try |
69 |
< |
SetDatabase(Database); |
70 |
< |
SQLText.Lines.Assign(SelectSQL); |
69 |
> |
if assigned(DataSet) then |
70 |
> |
begin |
71 |
> |
IBSQLEditFrame1.Database := DataSet.Database; |
72 |
> |
GenerateParams.Checked := DataSet.GenerateParamNames; |
73 |
> |
end; |
74 |
> |
with IBSQLEditFrame1 do |
75 |
> |
begin |
76 |
> |
IncludeReadOnlyFields := false; |
77 |
> |
ExecuteOnlyProcs := true; |
78 |
> |
SQLText.Lines.Assign(SelectSQL); |
79 |
> |
end; |
80 |
|
Result := ShowModal = mrOK; |
81 |
|
if Result then |
82 |
< |
SelectSQL.Assign(SQLText.Lines) |
82 |
> |
begin |
83 |
> |
SelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
84 |
> |
if assigned(DataSet) then |
85 |
> |
DataSet.GenerateParamNames := GenerateParams.Checked |
86 |
> |
end; |
87 |
|
finally |
88 |
|
Free |
89 |
|
end; |
91 |
|
|
92 |
|
{ TIBDeleteSQLEditorForm } |
93 |
|
|
102 |
– |
procedure TIBDeleteSQLEditorForm.FormShow(Sender: TObject); |
103 |
– |
var TableName: string; |
104 |
– |
begin |
105 |
– |
GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
106 |
– |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
107 |
– |
TableNamesCombo.Items.Clear; |
108 |
– |
try |
109 |
– |
FIBSystemTables.GetTableNames(TableNamesCombo.Items); |
110 |
– |
if TableNamesCombo.Items.Count > 0 then |
111 |
– |
begin |
112 |
– |
TableNamesCombo.ItemIndex := 0; |
113 |
– |
if Trim(SQLText.Text) <> '' then |
114 |
– |
begin |
115 |
– |
FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil); |
116 |
– |
TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName) |
117 |
– |
end; |
118 |
– |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
119 |
– |
end; |
120 |
– |
except {ignore} end; |
121 |
– |
end; |
122 |
– |
|
123 |
– |
procedure TIBDeleteSQLEditorForm.PrimaryKeyListDblClick(Sender: TObject); |
124 |
– |
begin |
125 |
– |
SQLText.SelText := PrimaryKeyList.Items[PrimaryKeyList.ItemIndex]; |
126 |
– |
SQLText.SetFocus |
127 |
– |
end; |
128 |
– |
|
94 |
|
procedure TIBDeleteSQLEditorForm.GenerateBtnClick(Sender: TObject); |
95 |
|
begin |
96 |
< |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,SQLText.Lines) |
97 |
< |
end; |
98 |
< |
|
99 |
< |
procedure TIBDeleteSQLEditorForm.TestBtnClick(Sender: TObject); |
135 |
< |
begin |
136 |
< |
FIBSystemTables.TestSQL(SQLText.Lines.Text) |
137 |
< |
end; |
138 |
< |
|
139 |
< |
procedure TIBDeleteSQLEditorForm.TableNamesComboCloseUp(Sender: TObject); |
140 |
< |
begin |
141 |
< |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
142 |
< |
end; |
143 |
< |
|
144 |
< |
constructor TIBDeleteSQLEditorForm.Create(TheOwner: TComponent); |
145 |
< |
begin |
146 |
< |
inherited Create(TheOwner); |
147 |
< |
FIBSystemTables := TIBSystemTables.Create; |
148 |
< |
end; |
149 |
< |
|
150 |
< |
destructor TIBDeleteSQLEditorForm.Destroy; |
151 |
< |
begin |
152 |
< |
if assigned(FIBSystemTables) then FIBSystemTables.Free; |
153 |
< |
inherited Destroy; |
154 |
< |
end; |
155 |
< |
|
156 |
< |
procedure TIBDeleteSQLEditorForm.SetDatabase(Database: TIBDatabase); |
157 |
< |
begin |
158 |
< |
IBTransaction1.DefaultDatabase := Database; |
159 |
< |
FIBSystemTables.SelectDatabase(Database,IBTransaction1) |
96 |
> |
if PageControl.ActivePage = ExecutePage then |
97 |
> |
IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked) |
98 |
> |
else |
99 |
> |
IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked); |
100 |
|
end; |
101 |
|
|
102 |
|
end. |