1 |
< |
(* |
2 |
< |
* IBX For Lazarus (Firebird Express) |
3 |
< |
* |
4 |
< |
* The contents of this file are subject to the Initial Developer's |
5 |
< |
* Public License Version 1.0 (the "License"); you may not use this |
6 |
< |
* file except in compliance with the License. You may obtain a copy |
7 |
< |
* of the License here: |
8 |
< |
* |
9 |
< |
* http://www.firebirdsql.org/index.php?op=doc&id=idpl |
10 |
< |
* |
11 |
< |
* Software distributed under the License is distributed on an "AS |
12 |
< |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
13 |
< |
* implied. See the License for the specific language governing rights |
14 |
< |
* and limitations under the License. |
15 |
< |
* |
16 |
< |
* The Initial Developer of the Original Code is Tony Whyman. |
17 |
< |
* |
18 |
< |
* The Original Code is (C) 2011 Tony Whyman, MWA Software |
19 |
< |
* (http://www.mwasoftware.co.uk). |
20 |
< |
* |
21 |
< |
* All Rights Reserved. |
22 |
< |
* |
23 |
< |
* Contributor(s): ______________________________________. |
24 |
< |
* |
25 |
< |
*) |
26 |
< |
|
27 |
< |
unit IBDataSetEditor; |
28 |
< |
|
29 |
< |
{$mode objfpc}{$H+} |
30 |
< |
|
31 |
< |
interface |
32 |
< |
|
33 |
< |
uses |
34 |
< |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, |
35 |
< |
ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBCustomDataSet, IBDatabase; |
36 |
< |
|
37 |
< |
type |
38 |
< |
|
39 |
< |
{ TIBDataSetEditorForm } |
40 |
< |
|
41 |
< |
TIBDataSetEditorForm = class(TForm) |
42 |
< |
GenerateParams: TCheckBox; |
43 |
< |
TestBtn: TButton; |
44 |
< |
CancelButton: TButton; |
45 |
< |
FieldsPage: TTabSheet; |
46 |
< |
GenerateButton: TButton; |
47 |
< |
GroupBox1: TGroupBox; |
48 |
< |
IBTransaction1: TIBTransaction; |
49 |
< |
IncludePrimaryKeys: TCheckBox; |
50 |
< |
PrimaryKeyList: TListBox; |
51 |
< |
Label1: TLabel; |
52 |
< |
Label2: TLabel; |
53 |
< |
Label3: TLabel; |
54 |
< |
Label4: TLabel; |
55 |
< |
OkButton: TButton; |
56 |
< |
PageControl: TPageControl; |
57 |
< |
QuoteFields: TCheckBox; |
58 |
< |
SQLMemo: TMemo; |
59 |
< |
SQLPage: TTabSheet; |
60 |
< |
StatementType: TRadioGroup; |
61 |
< |
FieldList: TListBox; |
62 |
< |
TableNamesCombo: TComboBox; |
63 |
< |
procedure TestBtnClick(Sender: TObject); |
64 |
< |
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); |
65 |
< |
procedure FormShow(Sender: TObject); |
66 |
< |
procedure GenerateButtonClick(Sender: TObject); |
67 |
< |
procedure SQLMemoChange(Sender: TObject); |
68 |
< |
procedure SQLPageShow(Sender: TObject); |
69 |
< |
procedure StatementTypeClick(Sender: TObject); |
70 |
< |
procedure TableNamesComboCloseUp(Sender: TObject); |
71 |
< |
private |
72 |
< |
{ private declarations } |
73 |
< |
FDataSet: TIBDataSet; |
74 |
< |
FIBSystemTables: TIBSystemTables; |
75 |
< |
FDirty: boolean; |
76 |
< |
FCurrentStatement: integer; |
77 |
< |
FSelectSQL: TStringList; |
78 |
< |
FModifySQL: TStringList; |
79 |
< |
FInsertSQL: TStringList; |
80 |
< |
FDeleteSQL: TStringList; |
81 |
< |
FRefreshSQL: TStringList; |
82 |
< |
procedure UpdateSQLMemo; |
83 |
< |
public |
84 |
< |
{ public declarations } |
85 |
< |
constructor Create(TheOwner: TComponent); override; |
86 |
< |
destructor Destroy; override; |
87 |
< |
procedure SetDataSet(AObject: TIBDataSet); |
88 |
< |
end; |
89 |
< |
|
90 |
< |
var |
91 |
< |
IBDataSetEditorForm: TIBDataSetEditorForm; |
92 |
< |
|
93 |
< |
function EditIBDataSet(DataSet: TIBDataSet): boolean; |
94 |
< |
|
95 |
< |
implementation |
96 |
< |
|
97 |
< |
{$R *.lfm} |
98 |
< |
|
99 |
< |
function EditIBDataSet(DataSet: TIBDataSet): boolean; |
100 |
< |
begin |
101 |
< |
Result := false; |
102 |
< |
if assigned(DataSet) and assigned(DataSet.Database) then |
103 |
< |
try |
104 |
< |
DataSet.Database.Connected := true; |
105 |
< |
except on E: Exception do |
106 |
< |
ShowMessage(E.Message) |
107 |
< |
end; |
108 |
< |
|
109 |
< |
with TIBDataSetEditorForm.Create(Application) do |
110 |
< |
try |
111 |
< |
SetDataSet(DataSet); |
112 |
< |
if assigned(DataSet) then |
113 |
< |
GenerateParams.Checked := DataSet.GenerateParamNames; |
114 |
< |
Result := ShowModal = mrOK; |
115 |
< |
if Result and assigned(DataSet) then |
116 |
< |
DataSet.GenerateParamNames := GenerateParams.Checked |
117 |
< |
finally |
118 |
< |
Free |
119 |
< |
end; |
120 |
< |
|
121 |
< |
end; |
122 |
< |
|
123 |
< |
{ TIBDataSetEditorForm } |
124 |
< |
|
125 |
< |
procedure TIBDataSetEditorForm.FormShow(Sender: TObject); |
126 |
< |
var TableName: string; |
127 |
< |
begin |
128 |
< |
PageControl.ActivePage := FieldsPage; |
129 |
< |
FModifySQL.Assign(FDataSet.ModifySQL); |
130 |
< |
FInsertSQL.Assign(FDataSet.InsertSQL); |
131 |
< |
FDeleteSQL.Assign(FDataSet.DeleteSQL); |
132 |
< |
FRefreshSQL.Assign(FDataSet.RefreshSQL); |
133 |
< |
FSelectSQL.Assign(FDataSet.SelectSQL); |
134 |
< |
GenerateButton.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
135 |
< |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
136 |
< |
FCurrentStatement := -1; |
137 |
< |
TableNamesCombo.Items.Clear; |
138 |
< |
FIBSystemTables.GetTableNames(TableNamesCombo.Items); |
139 |
< |
if TableNamesCombo.Items.Count > 0 then |
140 |
< |
begin |
141 |
< |
TableNamesCombo.ItemIndex := 0; |
142 |
< |
if FSelectSQL.Text <> '' then |
143 |
< |
try |
144 |
< |
FIBSystemTables.GetTableAndColumns(FSelectSQL.Text,TableName,nil); |
145 |
< |
TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName); |
146 |
< |
except end;//ignore |
147 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
148 |
< |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
149 |
< |
end; |
150 |
< |
end; |
151 |
< |
|
152 |
< |
procedure TIBDataSetEditorForm.FormClose(Sender: TObject; |
153 |
< |
var CloseAction: TCloseAction); |
154 |
< |
begin |
155 |
< |
if ModalResult = mrOK then |
156 |
< |
begin |
157 |
< |
UpdateSQLMemo; |
158 |
< |
FDataSet.ModifySQL.Assign(FModifySQL); |
159 |
< |
FDataSet.InsertSQL.Assign(FInsertSQL); |
160 |
< |
FDataSet.DeleteSQL.Assign(FDeleteSQL); |
161 |
< |
FDataSet.RefreshSQL.Assign(FRefreshSQL); |
162 |
< |
FDataSet.SelectSQL.Assign(FSelectSQL); |
163 |
< |
end; |
164 |
< |
end; |
165 |
< |
|
166 |
< |
procedure TIBDataSetEditorForm.TestBtnClick(Sender: TObject); |
167 |
< |
begin |
168 |
< |
if SQLMemo.Lines.Text <> '' then |
169 |
< |
FIBSystemTables.TestSQL(SQLMemo.Lines.Text,GenerateParams.Checked); |
170 |
< |
end; |
171 |
< |
|
172 |
< |
procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject); |
173 |
< |
var FieldNames: TStringList; |
174 |
< |
I: integer; |
175 |
< |
begin |
176 |
< |
FieldNames := TStringList.Create; |
177 |
< |
try |
178 |
< |
FRefreshSQL.Clear; |
179 |
< |
FSelectSQL.Clear; |
180 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames); |
181 |
< |
FIBSystemTables.GenerateSelectSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FSelectSQL); |
182 |
< |
FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FRefreshSQL); |
183 |
< |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL); |
184 |
< |
FieldNames.Clear; |
185 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames,true,false); |
186 |
< |
FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked, |
187 |
< |
FieldNames,FInsertSQL); |
188 |
< |
if FieldList.SelCount = 0 then |
189 |
< |
begin |
190 |
< |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
191 |
< |
FieldList.Items,FModifySQL); |
192 |
< |
|
193 |
< |
end |
194 |
< |
else |
195 |
< |
begin |
196 |
< |
FieldNames.Clear; |
197 |
< |
for I := 0 to FieldList.Items.Count - 1 do |
198 |
< |
if FieldList.Selected[I] then |
199 |
< |
FieldNames.Add(FieldList.Items[I]); |
200 |
< |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
201 |
< |
FieldNames,FModifySQL); |
202 |
< |
end; |
203 |
< |
FDirty := false; |
204 |
< |
PageControl.ActivePage := SQLPage; |
205 |
< |
finally |
206 |
< |
FieldNames.Free |
207 |
< |
end; |
208 |
< |
end; |
209 |
< |
|
210 |
< |
procedure TIBDataSetEditorForm.SQLMemoChange(Sender: TObject); |
211 |
< |
begin |
212 |
< |
FDirty := true |
213 |
< |
end; |
214 |
< |
|
215 |
< |
procedure TIBDataSetEditorForm.SQLPageShow(Sender: TObject); |
216 |
< |
begin |
217 |
< |
UpdateSQLMemo |
218 |
< |
end; |
219 |
< |
|
220 |
< |
procedure TIBDataSetEditorForm.StatementTypeClick(Sender: TObject); |
221 |
< |
begin |
222 |
< |
UpdateSQLMemo |
223 |
< |
end; |
224 |
< |
|
225 |
< |
procedure TIBDataSetEditorForm.TableNamesComboCloseUp(Sender: TObject); |
226 |
< |
begin |
227 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
228 |
< |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
229 |
< |
end; |
230 |
< |
|
231 |
< |
procedure TIBDataSetEditorForm.UpdateSQLMemo; |
232 |
< |
begin |
233 |
< |
if FDirty then |
234 |
< |
case FCurrentStatement of |
235 |
< |
0: // Select |
236 |
< |
FSelectSQL.Assign(SQLMemo.Lines); |
237 |
< |
1: //Modify |
238 |
< |
FModifySQL.Assign(SQLMemo.Lines); |
239 |
< |
2: //Insert |
240 |
< |
FInsertSQL.Assign(SQLMemo.Lines); |
241 |
< |
3: // Delete |
242 |
< |
FDeleteSQL.Assign(SQLMemo.Lines); |
243 |
< |
4: //Refresh |
244 |
< |
FRefreshSQL.Assign(SQLMemo.Lines); |
245 |
< |
end; |
246 |
< |
FDirty := false; |
247 |
< |
case StatementType.ItemIndex of |
248 |
< |
0: //Select |
249 |
< |
SQLMemo.Lines.Assign(FSelectSQL); |
250 |
< |
1: // Modify |
251 |
< |
SQLMemo.Lines.Assign(FModifySQL) ; |
252 |
< |
2: //Insert |
253 |
< |
SQLMemo.Lines.Assign(FInsertSQL) ; |
254 |
< |
3: // Delete |
255 |
< |
SQLMemo.Lines.Assign(FDeleteSQL) ; |
256 |
< |
4: //Refresh |
257 |
< |
SQLMemo.Lines.Assign(FRefreshSQL) ; |
258 |
< |
end; |
259 |
< |
FCurrentStatement := StatementType.ItemIndex; |
260 |
< |
end; |
261 |
< |
|
262 |
< |
constructor TIBDataSetEditorForm.Create(TheOwner: TComponent); |
263 |
< |
begin |
264 |
< |
inherited Create(TheOwner); |
265 |
< |
FIBSystemTables := TIBSystemTables.Create; |
266 |
< |
FModifySQL := TStringList.Create; |
267 |
< |
FInsertSQL := TStringList.Create; |
268 |
< |
FDeleteSQL := TStringList.Create; |
269 |
< |
FRefreshSQL := TStringList.Create; |
270 |
< |
FSelectSQL := TStringList.Create; |
271 |
< |
end; |
272 |
< |
|
273 |
< |
destructor TIBDataSetEditorForm.Destroy; |
274 |
< |
begin |
275 |
< |
if assigned(FIBSystemTables) then FIBSystemTables.Free; |
276 |
< |
if assigned(FModifySQL) then FModifySQL.Free; |
277 |
< |
if assigned(FInsertSQL) then FInsertSQL.Free; |
278 |
< |
if assigned(FDeleteSQL) then FDeleteSQL.Free; |
279 |
< |
if assigned(FRefreshSQL) then FRefreshSQL.Free; |
280 |
< |
if assigned(FSelectSQL) then FSelectSQL.Free; |
281 |
< |
inherited Destroy; |
282 |
< |
end; |
283 |
< |
|
284 |
< |
procedure TIBDataSetEditorForm.SetDataSet(AObject: TIBDataSet); |
285 |
< |
begin |
286 |
< |
FDataSet := AObject; |
287 |
< |
IBTransaction1.DefaultDatabase := FDataSet.Database; |
288 |
< |
if assigned(FDataSet) then |
289 |
< |
FIBSystemTables.SelectDatabase(FDataSet.Database,IBTransaction1); |
290 |
< |
end; |
291 |
< |
|
292 |
< |
end. |
293 |
< |
|
1 |
> |
(* |
2 |
> |
* IBX For Lazarus (Firebird Express) |
3 |
> |
* |
4 |
> |
* The contents of this file are subject to the Initial Developer's |
5 |
> |
* Public License Version 1.0 (the "License"); you may not use this |
6 |
> |
* file except in compliance with the License. You may obtain a copy |
7 |
> |
* of the License here: |
8 |
> |
* |
9 |
> |
* http://www.firebirdsql.org/index.php?op=doc&id=idpl |
10 |
> |
* |
11 |
> |
* Software distributed under the License is distributed on an "AS |
12 |
> |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
13 |
> |
* implied. See the License for the specific language governing rights |
14 |
> |
* and limitations under the License. |
15 |
> |
* |
16 |
> |
* The Initial Developer of the Original Code is Tony Whyman. |
17 |
> |
* |
18 |
> |
* The Original Code is (C) 2011 Tony Whyman, MWA Software |
19 |
> |
* (http://www.mwasoftware.co.uk). |
20 |
> |
* |
21 |
> |
* All Rights Reserved. |
22 |
> |
* |
23 |
> |
* Contributor(s): ______________________________________. |
24 |
> |
* |
25 |
> |
*) |
26 |
> |
|
27 |
> |
unit IBDataSetEditor; |
28 |
> |
|
29 |
> |
{$mode objfpc}{$H+} |
30 |
> |
|
31 |
> |
interface |
32 |
> |
|
33 |
> |
uses |
34 |
> |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, |
35 |
> |
ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBCustomDataSet, IBDatabase; |
36 |
> |
|
37 |
> |
type |
38 |
> |
|
39 |
> |
{ TIBDataSetEditorForm } |
40 |
> |
|
41 |
> |
TIBDataSetEditorForm = class(TForm) |
42 |
> |
GenerateParams: TCheckBox; |
43 |
> |
TestBtn: TButton; |
44 |
> |
CancelButton: TButton; |
45 |
> |
FieldsPage: TTabSheet; |
46 |
> |
GenerateButton: TButton; |
47 |
> |
GroupBox1: TGroupBox; |
48 |
> |
IBTransaction1: TIBTransaction; |
49 |
> |
IncludePrimaryKeys: TCheckBox; |
50 |
> |
PrimaryKeyList: TListBox; |
51 |
> |
Label1: TLabel; |
52 |
> |
Label2: TLabel; |
53 |
> |
Label3: TLabel; |
54 |
> |
Label4: TLabel; |
55 |
> |
OkButton: TButton; |
56 |
> |
PageControl: TPageControl; |
57 |
> |
QuoteFields: TCheckBox; |
58 |
> |
SQLMemo: TMemo; |
59 |
> |
SQLPage: TTabSheet; |
60 |
> |
StatementType: TRadioGroup; |
61 |
> |
FieldList: TListBox; |
62 |
> |
TableNamesCombo: TComboBox; |
63 |
> |
procedure TestBtnClick(Sender: TObject); |
64 |
> |
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); |
65 |
> |
procedure FormShow(Sender: TObject); |
66 |
> |
procedure GenerateButtonClick(Sender: TObject); |
67 |
> |
procedure SQLMemoChange(Sender: TObject); |
68 |
> |
procedure SQLPageShow(Sender: TObject); |
69 |
> |
procedure StatementTypeClick(Sender: TObject); |
70 |
> |
procedure TableNamesComboCloseUp(Sender: TObject); |
71 |
> |
private |
72 |
> |
{ private declarations } |
73 |
> |
FDataSet: TIBDataSet; |
74 |
> |
FIBSystemTables: TIBSystemTables; |
75 |
> |
FDirty: boolean; |
76 |
> |
FCurrentStatement: integer; |
77 |
> |
FSelectSQL: TStringList; |
78 |
> |
FModifySQL: TStringList; |
79 |
> |
FInsertSQL: TStringList; |
80 |
> |
FDeleteSQL: TStringList; |
81 |
> |
FRefreshSQL: TStringList; |
82 |
> |
procedure UpdateSQLMemo; |
83 |
> |
public |
84 |
> |
{ public declarations } |
85 |
> |
constructor Create(TheOwner: TComponent); override; |
86 |
> |
destructor Destroy; override; |
87 |
> |
procedure SetDataSet(AObject: TIBDataSet); |
88 |
> |
end; |
89 |
> |
|
90 |
> |
var |
91 |
> |
IBDataSetEditorForm: TIBDataSetEditorForm; |
92 |
> |
|
93 |
> |
function EditIBDataSet(DataSet: TIBDataSet): boolean; |
94 |
> |
|
95 |
> |
implementation |
96 |
> |
|
97 |
> |
{$R *.lfm} |
98 |
> |
|
99 |
> |
function EditIBDataSet(DataSet: TIBDataSet): boolean; |
100 |
> |
begin |
101 |
> |
Result := false; |
102 |
> |
if assigned(DataSet) and assigned(DataSet.Database) then |
103 |
> |
try |
104 |
> |
DataSet.Database.Connected := true; |
105 |
> |
except on E: Exception do |
106 |
> |
ShowMessage(E.Message) |
107 |
> |
end; |
108 |
> |
|
109 |
> |
with TIBDataSetEditorForm.Create(Application) do |
110 |
> |
try |
111 |
> |
SetDataSet(DataSet); |
112 |
> |
if assigned(DataSet) then |
113 |
> |
GenerateParams.Checked := DataSet.GenerateParamNames; |
114 |
> |
Result := ShowModal = mrOK; |
115 |
> |
if Result and assigned(DataSet) then |
116 |
> |
DataSet.GenerateParamNames := GenerateParams.Checked |
117 |
> |
finally |
118 |
> |
Free |
119 |
> |
end; |
120 |
> |
|
121 |
> |
end; |
122 |
> |
|
123 |
> |
{ TIBDataSetEditorForm } |
124 |
> |
|
125 |
> |
procedure TIBDataSetEditorForm.FormShow(Sender: TObject); |
126 |
> |
var TableName: string; |
127 |
> |
begin |
128 |
> |
PageControl.ActivePage := FieldsPage; |
129 |
> |
FModifySQL.Assign(FDataSet.ModifySQL); |
130 |
> |
FInsertSQL.Assign(FDataSet.InsertSQL); |
131 |
> |
FDeleteSQL.Assign(FDataSet.DeleteSQL); |
132 |
> |
FRefreshSQL.Assign(FDataSet.RefreshSQL); |
133 |
> |
FSelectSQL.Assign(FDataSet.SelectSQL); |
134 |
> |
GenerateButton.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
135 |
> |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
136 |
> |
FCurrentStatement := -1; |
137 |
> |
TableNamesCombo.Items.Clear; |
138 |
> |
FIBSystemTables.GetTableNames(TableNamesCombo.Items); |
139 |
> |
if TableNamesCombo.Items.Count > 0 then |
140 |
> |
begin |
141 |
> |
TableNamesCombo.ItemIndex := 0; |
142 |
> |
if FSelectSQL.Text <> '' then |
143 |
> |
try |
144 |
> |
FIBSystemTables.GetTableAndColumns(FSelectSQL.Text,TableName,nil); |
145 |
> |
TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName); |
146 |
> |
except end;//ignore |
147 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
148 |
> |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
149 |
> |
end; |
150 |
> |
end; |
151 |
> |
|
152 |
> |
procedure TIBDataSetEditorForm.FormClose(Sender: TObject; |
153 |
> |
var CloseAction: TCloseAction); |
154 |
> |
begin |
155 |
> |
if ModalResult = mrOK then |
156 |
> |
begin |
157 |
> |
UpdateSQLMemo; |
158 |
> |
FDataSet.ModifySQL.Assign(FModifySQL); |
159 |
> |
FDataSet.InsertSQL.Assign(FInsertSQL); |
160 |
> |
FDataSet.DeleteSQL.Assign(FDeleteSQL); |
161 |
> |
FDataSet.RefreshSQL.Assign(FRefreshSQL); |
162 |
> |
FDataSet.SelectSQL.Assign(FSelectSQL); |
163 |
> |
end; |
164 |
> |
end; |
165 |
> |
|
166 |
> |
procedure TIBDataSetEditorForm.TestBtnClick(Sender: TObject); |
167 |
> |
begin |
168 |
> |
if SQLMemo.Lines.Text <> '' then |
169 |
> |
FIBSystemTables.TestSQL(SQLMemo.Lines.Text,GenerateParams.Checked); |
170 |
> |
end; |
171 |
> |
|
172 |
> |
procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject); |
173 |
> |
var FieldNames: TStringList; |
174 |
> |
I: integer; |
175 |
> |
begin |
176 |
> |
FieldNames := TStringList.Create; |
177 |
> |
try |
178 |
> |
FRefreshSQL.Clear; |
179 |
> |
FSelectSQL.Clear; |
180 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames); |
181 |
> |
FIBSystemTables.GenerateSelectSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FSelectSQL); |
182 |
> |
FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FRefreshSQL); |
183 |
> |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL); |
184 |
> |
FieldNames.Clear; |
185 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames,true,false); |
186 |
> |
FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked, |
187 |
> |
FieldNames,FInsertSQL); |
188 |
> |
if FieldList.SelCount = 0 then |
189 |
> |
begin |
190 |
> |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
191 |
> |
FieldList.Items,FModifySQL); |
192 |
> |
|
193 |
> |
end |
194 |
> |
else |
195 |
> |
begin |
196 |
> |
FieldNames.Clear; |
197 |
> |
for I := 0 to FieldList.Items.Count - 1 do |
198 |
> |
if FieldList.Selected[I] then |
199 |
> |
FieldNames.Add(FieldList.Items[I]); |
200 |
> |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
201 |
> |
FieldNames,FModifySQL); |
202 |
> |
end; |
203 |
> |
FDirty := false; |
204 |
> |
PageControl.ActivePage := SQLPage; |
205 |
> |
finally |
206 |
> |
FieldNames.Free |
207 |
> |
end; |
208 |
> |
end; |
209 |
> |
|
210 |
> |
procedure TIBDataSetEditorForm.SQLMemoChange(Sender: TObject); |
211 |
> |
begin |
212 |
> |
FDirty := true |
213 |
> |
end; |
214 |
> |
|
215 |
> |
procedure TIBDataSetEditorForm.SQLPageShow(Sender: TObject); |
216 |
> |
begin |
217 |
> |
UpdateSQLMemo |
218 |
> |
end; |
219 |
> |
|
220 |
> |
procedure TIBDataSetEditorForm.StatementTypeClick(Sender: TObject); |
221 |
> |
begin |
222 |
> |
UpdateSQLMemo |
223 |
> |
end; |
224 |
> |
|
225 |
> |
procedure TIBDataSetEditorForm.TableNamesComboCloseUp(Sender: TObject); |
226 |
> |
begin |
227 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
228 |
> |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
229 |
> |
end; |
230 |
> |
|
231 |
> |
procedure TIBDataSetEditorForm.UpdateSQLMemo; |
232 |
> |
begin |
233 |
> |
if FDirty then |
234 |
> |
case FCurrentStatement of |
235 |
> |
0: // Select |
236 |
> |
FSelectSQL.Assign(SQLMemo.Lines); |
237 |
> |
1: //Modify |
238 |
> |
FModifySQL.Assign(SQLMemo.Lines); |
239 |
> |
2: //Insert |
240 |
> |
FInsertSQL.Assign(SQLMemo.Lines); |
241 |
> |
3: // Delete |
242 |
> |
FDeleteSQL.Assign(SQLMemo.Lines); |
243 |
> |
4: //Refresh |
244 |
> |
FRefreshSQL.Assign(SQLMemo.Lines); |
245 |
> |
end; |
246 |
> |
FDirty := false; |
247 |
> |
case StatementType.ItemIndex of |
248 |
> |
0: //Select |
249 |
> |
SQLMemo.Lines.Assign(FSelectSQL); |
250 |
> |
1: // Modify |
251 |
> |
SQLMemo.Lines.Assign(FModifySQL) ; |
252 |
> |
2: //Insert |
253 |
> |
SQLMemo.Lines.Assign(FInsertSQL) ; |
254 |
> |
3: // Delete |
255 |
> |
SQLMemo.Lines.Assign(FDeleteSQL) ; |
256 |
> |
4: //Refresh |
257 |
> |
SQLMemo.Lines.Assign(FRefreshSQL) ; |
258 |
> |
end; |
259 |
> |
FCurrentStatement := StatementType.ItemIndex; |
260 |
> |
end; |
261 |
> |
|
262 |
> |
constructor TIBDataSetEditorForm.Create(TheOwner: TComponent); |
263 |
> |
begin |
264 |
> |
inherited Create(TheOwner); |
265 |
> |
FIBSystemTables := TIBSystemTables.Create; |
266 |
> |
FModifySQL := TStringList.Create; |
267 |
> |
FInsertSQL := TStringList.Create; |
268 |
> |
FDeleteSQL := TStringList.Create; |
269 |
> |
FRefreshSQL := TStringList.Create; |
270 |
> |
FSelectSQL := TStringList.Create; |
271 |
> |
end; |
272 |
> |
|
273 |
> |
destructor TIBDataSetEditorForm.Destroy; |
274 |
> |
begin |
275 |
> |
if assigned(FIBSystemTables) then FIBSystemTables.Free; |
276 |
> |
if assigned(FModifySQL) then FModifySQL.Free; |
277 |
> |
if assigned(FInsertSQL) then FInsertSQL.Free; |
278 |
> |
if assigned(FDeleteSQL) then FDeleteSQL.Free; |
279 |
> |
if assigned(FRefreshSQL) then FRefreshSQL.Free; |
280 |
> |
if assigned(FSelectSQL) then FSelectSQL.Free; |
281 |
> |
inherited Destroy; |
282 |
> |
end; |
283 |
> |
|
284 |
> |
procedure TIBDataSetEditorForm.SetDataSet(AObject: TIBDataSet); |
285 |
> |
begin |
286 |
> |
FDataSet := AObject; |
287 |
> |
IBTransaction1.DefaultDatabase := FDataSet.Database; |
288 |
> |
if assigned(FDataSet) then |
289 |
> |
FIBSystemTables.SelectDatabase(FDataSet.Database,IBTransaction1); |
290 |
> |
end; |
291 |
> |
|
292 |
> |
end. |