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, ComCtrls, IBSystemTables, IBDatabase, IBCustomDataSet, IB; |
33 |
> |
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, |
34 |
> |
ibselectsqleditor, IBDatabase, IBCustomDataset, IBSQLEditFrame; |
35 |
|
|
36 |
|
type |
37 |
|
|
38 |
|
{ TIBDeleteSQLEditorForm } |
39 |
|
|
40 |
< |
TIBDeleteSQLEditorForm = class(TForm) |
42 |
< |
Button1: TButton; |
43 |
< |
Button2: TButton; |
44 |
< |
ExecuteOnlyIndicator: TLabel; |
45 |
< |
GenerateBtn: TButton; |
46 |
< |
GenerateParams: TCheckBox; |
47 |
< |
Label1: TLabel; |
48 |
< |
Label16: TLabel; |
49 |
< |
Label17: TLabel; |
50 |
< |
Label18: TLabel; |
51 |
< |
Label4: TLabel; |
52 |
< |
PageControl: TPageControl; |
53 |
< |
PrimaryKeyList: TListBox; |
54 |
< |
ProcedureNames: TComboBox; |
55 |
< |
ProcInputList: TListBox; |
56 |
< |
ProcOutputList: TListBox; |
57 |
< |
TableNamesCombo: TComboBox; |
58 |
< |
DeletePage: TTabSheet; |
59 |
< |
ExecutePage: TTabSheet; |
60 |
< |
TestBtn: TButton; |
61 |
< |
IBTransaction1: TIBTransaction; |
62 |
< |
Label3: TLabel; |
63 |
< |
QuoteFields: TCheckBox; |
64 |
< |
SQLText: TMemo; |
65 |
< |
procedure DeletePageShow(Sender: TObject); |
66 |
< |
procedure ExecutePageShow(Sender: TObject); |
40 |
> |
TIBDeleteSQLEditorForm = class(TIBSelectSQLEditorForm) |
41 |
|
procedure GenerateBtnClick(Sender: TObject); |
68 |
– |
procedure ProcedureNamesCloseUp(Sender: TObject); |
69 |
– |
procedure TestBtnClick(Sender: TObject); |
70 |
– |
procedure FormShow(Sender: TObject); |
71 |
– |
procedure PrimaryKeyListDblClick(Sender: TObject); |
72 |
– |
procedure TableNamesComboCloseUp(Sender: TObject); |
42 |
|
private |
43 |
< |
{ private declarations } |
75 |
< |
FIBSystemTables: TIBSystemTables; |
43 |
> |
|
44 |
|
public |
77 |
– |
{ public declarations } |
78 |
– |
constructor Create(TheOwner: TComponent); override; |
79 |
– |
destructor Destroy; override; |
80 |
– |
procedure SetDatabase(Database: TIBDatabase); |
81 |
– |
end; |
45 |
|
|
46 |
< |
var |
84 |
< |
IBDeleteSQLEditorForm: TIBDeleteSQLEditorForm; |
46 |
> |
end; |
47 |
|
|
48 |
|
function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean; |
49 |
|
|
50 |
< |
implementation |
50 |
> |
var |
51 |
> |
IBDeleteSQLEditorForm: TIBDeleteSQLEditorForm; |
52 |
|
|
53 |
< |
uses IBSQL; |
53 |
> |
implementation |
54 |
|
|
55 |
|
{$R *.lfm} |
56 |
|
|
68 |
|
try |
69 |
|
if assigned(DataSet) then |
70 |
|
begin |
71 |
< |
SetDatabase(DataSet.Database); |
71 |
> |
IBSQLEditFrame1.Database := DataSet.Database; |
72 |
|
GenerateParams.Checked := DataSet.GenerateParamNames; |
73 |
|
end; |
74 |
< |
SQLText.Lines.Assign(SelectSQL); |
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 |
|
begin |
83 |
< |
SelectSQL.Assign(SQLText.Lines); |
83 |
> |
SelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
84 |
|
if assigned(DataSet) then |
85 |
|
DataSet.GenerateParamNames := GenerateParams.Checked |
86 |
|
end; |
91 |
|
|
92 |
|
{ TIBDeleteSQLEditorForm } |
93 |
|
|
126 |
– |
procedure TIBDeleteSQLEditorForm.FormShow(Sender: TObject); |
127 |
– |
var IsProcedureName: boolean; |
128 |
– |
SQLType: TIBSQLStatementTypes; |
129 |
– |
begin |
130 |
– |
GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
131 |
– |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
132 |
– |
if Trim(SQLText.Text) <> '' then |
133 |
– |
begin |
134 |
– |
try |
135 |
– |
SQLType := FIBSystemTables.GetStatementType(SQLText.Text,IsProcedureName); |
136 |
– |
except end; |
137 |
– |
if SQLType = SQLExecProcedure then |
138 |
– |
PageControl.ActivePage := ExecutePage |
139 |
– |
else |
140 |
– |
PageControl.ActivePage := DeletePage; |
141 |
– |
end |
142 |
– |
else |
143 |
– |
PageControl.ActivePage := DeletePage; |
144 |
– |
end; |
145 |
– |
|
146 |
– |
procedure TIBDeleteSQLEditorForm.PrimaryKeyListDblClick(Sender: TObject); |
147 |
– |
begin |
148 |
– |
SQLText.SelText := PrimaryKeyList.Items[PrimaryKeyList.ItemIndex]; |
149 |
– |
SQLText.SetFocus |
150 |
– |
end; |
151 |
– |
|
94 |
|
procedure TIBDeleteSQLEditorForm.GenerateBtnClick(Sender: TObject); |
95 |
|
begin |
96 |
|
if PageControl.ActivePage = ExecutePage then |
97 |
< |
FIBSystemTables.GenerateExecuteSQL(ProcedureNames.Text,QuoteFields.Checked,true, |
156 |
< |
ProcInputList.Items,ProcOutputList.Items,SQLText.Lines) |
97 |
> |
IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked) |
98 |
|
else |
99 |
< |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,SQLText.Lines) |
159 |
< |
end; |
160 |
< |
|
161 |
< |
procedure TIBDeleteSQLEditorForm.ProcedureNamesCloseUp(Sender: TObject); |
162 |
< |
var ExecuteOnly: boolean; |
163 |
< |
begin |
164 |
< |
FIBSystemTables.GetProcParams(ProcedureNames.Text,ExecuteOnly,ProcInputList.Items,ProcOutputList.Items); |
165 |
< |
ExecuteOnlyIndicator.Visible := ExecuteOnly; |
166 |
< |
end; |
167 |
< |
|
168 |
< |
procedure TIBDeleteSQLEditorForm.DeletePageShow(Sender: TObject); |
169 |
< |
var TableName: string; |
170 |
< |
begin |
171 |
< |
TableNamesCombo.Items.Clear; |
172 |
< |
try |
173 |
< |
FIBSystemTables.GetTableNames(TableNamesCombo.Items); |
174 |
< |
if TableNamesCombo.Items.Count > 0 then |
175 |
< |
begin |
176 |
< |
TableNamesCombo.ItemIndex := 0; |
177 |
< |
if Trim(SQLText.Text) <> '' then |
178 |
< |
begin |
179 |
< |
FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil); |
180 |
< |
TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName) |
181 |
< |
end; |
182 |
< |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
183 |
< |
end; |
184 |
< |
except {ignore} end; |
185 |
< |
end; |
186 |
< |
|
187 |
< |
procedure TIBDeleteSQLEditorForm.ExecutePageShow(Sender: TObject); |
188 |
< |
var ProcName: string; |
189 |
< |
IsProcedureName: boolean; |
190 |
< |
begin |
191 |
< |
FIBSystemTables.GetProcedureNames(ProcedureNames.Items,false); |
192 |
< |
if ProcedureNames.Items.Count > 0 then |
193 |
< |
begin |
194 |
< |
if (FIBSystemTables.GetStatementType(SQLText.Text,IsProcedureName) = SQLExecProcedure) or IsProcedureName then |
195 |
< |
begin |
196 |
< |
FIBSystemTables.GetTableAndColumns(SQLText.Text,ProcName,nil); |
197 |
< |
ProcedureNames.ItemIndex := ProcedureNames.Items.IndexOf(ProcName) |
198 |
< |
end |
199 |
< |
else |
200 |
< |
ProcedureNames.ItemIndex := 0; |
201 |
< |
end; |
202 |
< |
ProcedureNamesCloseUp(nil); |
203 |
< |
end; |
204 |
< |
|
205 |
< |
procedure TIBDeleteSQLEditorForm.TestBtnClick(Sender: TObject); |
206 |
< |
begin |
207 |
< |
FIBSystemTables.TestSQL(SQLText.Lines.Text,GenerateParams.Checked) |
208 |
< |
end; |
209 |
< |
|
210 |
< |
procedure TIBDeleteSQLEditorForm.TableNamesComboCloseUp(Sender: TObject); |
211 |
< |
begin |
212 |
< |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
213 |
< |
end; |
214 |
< |
|
215 |
< |
constructor TIBDeleteSQLEditorForm.Create(TheOwner: TComponent); |
216 |
< |
begin |
217 |
< |
inherited Create(TheOwner); |
218 |
< |
FIBSystemTables := TIBSystemTables.Create; |
219 |
< |
end; |
220 |
< |
|
221 |
< |
destructor TIBDeleteSQLEditorForm.Destroy; |
222 |
< |
begin |
223 |
< |
if assigned(FIBSystemTables) then FIBSystemTables.Free; |
224 |
< |
inherited Destroy; |
225 |
< |
end; |
226 |
< |
|
227 |
< |
procedure TIBDeleteSQLEditorForm.SetDatabase(Database: TIBDatabase); |
228 |
< |
begin |
229 |
< |
IBTransaction1.DefaultDatabase := Database; |
230 |
< |
FIBSystemTables.SelectDatabase(Database,IBTransaction1) |
99 |
> |
IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked); |
100 |
|
end; |
101 |
|
|
102 |
|
end. |
103 |
+ |
|