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; |
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 |
> |
IncludePrimaryKeys := true; |
77 |
> |
IncludeReadOnlyFields := false; |
78 |
> |
ExecuteOnlyProcs := true; |
79 |
> |
SQLText.Lines.Assign(SelectSQL); |
80 |
> |
end; |
81 |
|
Result := ShowModal = mrOK; |
82 |
|
if Result then |
83 |
|
begin |
84 |
< |
SelectSQL.Assign(SQLText.Lines); |
84 |
> |
SelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
85 |
|
if assigned(DataSet) then |
86 |
|
DataSet.GenerateParamNames := GenerateParams.Checked |
87 |
|
end; |
92 |
|
|
93 |
|
{ TIBDeleteSQLEditorForm } |
94 |
|
|
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 |
– |
|
95 |
|
procedure TIBDeleteSQLEditorForm.GenerateBtnClick(Sender: TObject); |
96 |
|
begin |
97 |
|
if PageControl.ActivePage = ExecutePage then |
98 |
< |
FIBSystemTables.GenerateExecuteSQL(ProcedureNames.Text,QuoteFields.Checked,true, |
156 |
< |
ProcInputList.Items,ProcOutputList.Items,SQLText.Lines) |
98 |
> |
IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked) |
99 |
|
else |
100 |
< |
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) |
100 |
> |
IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked); |
101 |
|
end; |
102 |
|
|
103 |
|
end. |
104 |
+ |
|