31 |
|
interface |
32 |
|
|
33 |
|
uses |
34 |
< |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, |
35 |
< |
ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBCustomDataSet, IBDatabase; |
34 |
> |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, |
35 |
> |
StdCtrls, ExtCtrls, IBSQLEditFrame, IBCustomDataSet, |
36 |
> |
IBDatabase, IBLookupComboEditBox, IBDynamicGrid, Types; |
37 |
|
|
38 |
|
type |
39 |
|
|
40 |
|
{ TIBDataSetEditorForm } |
41 |
|
|
42 |
|
TIBDataSetEditorForm = class(TForm) |
43 |
+ |
FieldNamesGrid: TIBDynamicGrid; |
44 |
+ |
GenerateParams: TCheckBox; |
45 |
+ |
IBSQLEditFrame1: TIBSQLEditFrame; |
46 |
+ |
IncludeSysTables: TCheckBox; |
47 |
+ |
Label5: TLabel; |
48 |
+ |
Label6: TLabel; |
49 |
+ |
PrimaryKeysGrid: TIBDynamicGrid; |
50 |
+ |
IdentityGrid: TIBDynamicGrid; |
51 |
+ |
ReadOnlyGrid: TIBDynamicGrid; |
52 |
+ |
SelectSelectAll: TCheckBox; |
53 |
+ |
SelectTableNames: TIBLookupComboEditBox; |
54 |
|
TestBtn: TButton; |
55 |
|
CancelButton: TButton; |
56 |
|
FieldsPage: TTabSheet; |
57 |
|
GenerateButton: TButton; |
58 |
|
GroupBox1: TGroupBox; |
47 |
– |
IBTransaction1: TIBTransaction; |
59 |
|
IncludePrimaryKeys: TCheckBox; |
49 |
– |
PrimaryKeyList: TListBox; |
60 |
|
Label1: TLabel; |
61 |
|
Label2: TLabel; |
62 |
|
Label3: TLabel; |
64 |
|
OkButton: TButton; |
65 |
|
PageControl: TPageControl; |
66 |
|
QuoteFields: TCheckBox; |
57 |
– |
SQLMemo: TMemo; |
67 |
|
SQLPage: TTabSheet; |
68 |
|
StatementType: TRadioGroup; |
69 |
< |
FieldList: TListBox; |
70 |
< |
TableNamesCombo: TComboBox; |
69 |
> |
procedure IncludeSysTablesChange(Sender: TObject); |
70 |
> |
procedure SelectSelectAllClick(Sender: TObject); |
71 |
|
procedure TestBtnClick(Sender: TObject); |
72 |
|
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); |
73 |
|
procedure FormShow(Sender: TObject); |
75 |
|
procedure SQLMemoChange(Sender: TObject); |
76 |
|
procedure SQLPageShow(Sender: TObject); |
77 |
|
procedure StatementTypeClick(Sender: TObject); |
69 |
– |
procedure TableNamesComboCloseUp(Sender: TObject); |
78 |
|
private |
79 |
|
{ private declarations } |
80 |
|
FDataSet: TIBDataSet; |
73 |
– |
FIBSystemTables: TIBSystemTables; |
81 |
|
FDirty: boolean; |
82 |
|
FCurrentStatement: integer; |
83 |
|
FSelectSQL: TStringList; |
86 |
|
FDeleteSQL: TStringList; |
87 |
|
FRefreshSQL: TStringList; |
88 |
|
procedure UpdateSQLMemo; |
89 |
+ |
procedure HandleUserTablesOpened(Sender: TObject); |
90 |
+ |
protected |
91 |
+ |
procedure Loaded; override; |
92 |
|
public |
93 |
|
{ public declarations } |
94 |
|
constructor Create(TheOwner: TComponent); override; |
95 |
|
destructor Destroy; override; |
86 |
– |
procedure SetDataSet(AObject: TIBDataSet); |
96 |
|
end; |
97 |
|
|
98 |
|
var |
116 |
|
|
117 |
|
with TIBDataSetEditorForm.Create(Application) do |
118 |
|
try |
119 |
< |
SetDataSet(DataSet); |
120 |
< |
Result := ShowModal = mrOK |
119 |
> |
if assigned(DataSet) then |
120 |
> |
begin |
121 |
> |
IBSQLEditFrame1.Database := DataSet.Database; |
122 |
> |
GenerateParams.Checked := DataSet.GenerateParamNames; |
123 |
> |
end; |
124 |
> |
FDataSet := DataSet; |
125 |
> |
with IBSQLEditFrame1 do |
126 |
> |
begin |
127 |
> |
IncludePrimaryKeys := false; |
128 |
> |
IncludeReadOnlyFields := false; |
129 |
> |
end; |
130 |
> |
Result := ShowModal = mrOK; |
131 |
> |
if Result and assigned(DataSet) then |
132 |
> |
DataSet.GenerateParamNames := GenerateParams.Checked |
133 |
|
finally |
134 |
|
Free |
135 |
|
end; |
147 |
|
FDeleteSQL.Assign(FDataSet.DeleteSQL); |
148 |
|
FRefreshSQL.Assign(FDataSet.RefreshSQL); |
149 |
|
FSelectSQL.Assign(FDataSet.SelectSQL); |
150 |
< |
GenerateButton.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
151 |
< |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
150 |
> |
GenerateButton.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected; |
151 |
> |
TestBtn.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected; |
152 |
|
FCurrentStatement := -1; |
153 |
< |
TableNamesCombo.Items.Clear; |
133 |
< |
FIBSystemTables.GetTableNames(TableNamesCombo.Items); |
134 |
< |
if TableNamesCombo.Items.Count > 0 then |
153 |
> |
if (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected then |
154 |
|
begin |
155 |
< |
TableNamesCombo.ItemIndex := 0; |
156 |
< |
if FSelectSQL.Text <> '' then |
138 |
< |
try |
139 |
< |
FIBSystemTables.GetTableAndColumns(FSelectSQL.Text,TableName,nil); |
140 |
< |
TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName); |
141 |
< |
except end;//ignore |
142 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
143 |
< |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
155 |
> |
IBSQLEditFrame1.UserTables.Active := true; |
156 |
> |
IBSQLEditFrame1.SyncQueryBuilder(FSelectSQL); |
157 |
|
end; |
158 |
|
end; |
159 |
|
|
173 |
|
|
174 |
|
procedure TIBDataSetEditorForm.TestBtnClick(Sender: TObject); |
175 |
|
begin |
176 |
< |
if SQLMemo.Lines.Text <> '' then |
164 |
< |
FIBSystemTables.TestSQL(SQLMemo.Lines.Text); |
176 |
> |
IBSQLEditFrame1.TestSQL(GenerateParams.Checked); |
177 |
|
end; |
178 |
|
|
179 |
< |
procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject); |
168 |
< |
var FieldNames: TStringList; |
169 |
< |
I: integer; |
179 |
> |
procedure TIBDataSetEditorForm.IncludeSysTablesChange(Sender: TObject); |
180 |
|
begin |
181 |
< |
FieldNames := TStringList.Create; |
182 |
< |
try |
173 |
< |
FRefreshSQL.Clear; |
174 |
< |
FSelectSQL.Clear; |
175 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames); |
176 |
< |
FIBSystemTables.GenerateSelectSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FSelectSQL); |
177 |
< |
FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FRefreshSQL); |
178 |
< |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL); |
179 |
< |
FieldNames.Clear; |
180 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames,true,false); |
181 |
< |
FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked, |
182 |
< |
FieldNames,FInsertSQL); |
183 |
< |
if FieldList.SelCount = 0 then |
184 |
< |
begin |
185 |
< |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
186 |
< |
FieldList.Items,FModifySQL); |
181 |
> |
IBSQLEditFrame1.IncludeSystemTables := IncludeSysTables.Checked; |
182 |
> |
end; |
183 |
|
|
184 |
< |
end |
185 |
< |
else |
186 |
< |
begin |
187 |
< |
FieldNames.Clear; |
188 |
< |
for I := 0 to FieldList.Items.Count - 1 do |
189 |
< |
if FieldList.Selected[I] then |
190 |
< |
FieldNames.Add(FieldList.Items[I]); |
191 |
< |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
192 |
< |
FieldNames,FModifySQL); |
193 |
< |
end; |
194 |
< |
FDirty := false; |
195 |
< |
PageControl.ActivePage := SQLPage; |
196 |
< |
finally |
197 |
< |
FieldNames.Free |
202 |
< |
end; |
184 |
> |
procedure TIBDataSetEditorForm.SelectSelectAllClick(Sender: TObject); |
185 |
> |
begin |
186 |
> |
IBSQLEditFrame1.SelectAllFields(SelectSelectAll.Checked); |
187 |
> |
end; |
188 |
> |
|
189 |
> |
procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject); |
190 |
> |
begin |
191 |
> |
IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked,FSelectSQL); |
192 |
> |
IBSQLEditFrame1.GenerateRefreshSQL(QuoteFields.Checked,FRefreshSQL); |
193 |
> |
IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked,FDeleteSQL); |
194 |
> |
IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked,FInsertSQL); |
195 |
> |
IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked,FModifySQL, not IncludePrimaryKeys.Checked); |
196 |
> |
FDirty := false; |
197 |
> |
PageControl.ActivePage := SQLPage; |
198 |
|
end; |
199 |
|
|
200 |
|
procedure TIBDataSetEditorForm.SQLMemoChange(Sender: TObject); |
212 |
|
UpdateSQLMemo |
213 |
|
end; |
214 |
|
|
220 |
– |
procedure TIBDataSetEditorForm.TableNamesComboCloseUp(Sender: TObject); |
221 |
– |
begin |
222 |
– |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
223 |
– |
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
224 |
– |
end; |
225 |
– |
|
215 |
|
procedure TIBDataSetEditorForm.UpdateSQLMemo; |
216 |
|
begin |
217 |
|
if FDirty then |
218 |
|
case FCurrentStatement of |
219 |
|
0: // Select |
220 |
< |
FSelectSQL.Assign(SQLMemo.Lines); |
220 |
> |
FSelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
221 |
|
1: //Modify |
222 |
< |
FModifySQL.Assign(SQLMemo.Lines); |
222 |
> |
FModifySQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
223 |
|
2: //Insert |
224 |
< |
FInsertSQL.Assign(SQLMemo.Lines); |
224 |
> |
FInsertSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
225 |
|
3: // Delete |
226 |
< |
FDeleteSQL.Assign(SQLMemo.Lines); |
226 |
> |
FDeleteSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
227 |
|
4: //Refresh |
228 |
< |
FRefreshSQL.Assign(SQLMemo.Lines); |
228 |
> |
FRefreshSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
229 |
|
end; |
230 |
|
FDirty := false; |
231 |
|
case StatementType.ItemIndex of |
232 |
|
0: //Select |
233 |
< |
SQLMemo.Lines.Assign(FSelectSQL); |
233 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FSelectSQL); |
234 |
|
1: // Modify |
235 |
< |
SQLMemo.Lines.Assign(FModifySQL) ; |
235 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FModifySQL) ; |
236 |
|
2: //Insert |
237 |
< |
SQLMemo.Lines.Assign(FInsertSQL) ; |
237 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FInsertSQL) ; |
238 |
|
3: // Delete |
239 |
< |
SQLMemo.Lines.Assign(FDeleteSQL) ; |
239 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FDeleteSQL) ; |
240 |
|
4: //Refresh |
241 |
< |
SQLMemo.Lines.Assign(FRefreshSQL) ; |
241 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FRefreshSQL) ; |
242 |
|
end; |
243 |
|
FCurrentStatement := StatementType.ItemIndex; |
244 |
|
end; |
245 |
|
|
246 |
+ |
procedure TIBDataSetEditorForm.HandleUserTablesOpened(Sender: TObject); |
247 |
+ |
begin |
248 |
+ |
SelectSelectAll.Checked := true; |
249 |
+ |
end; |
250 |
+ |
|
251 |
+ |
procedure TIBDataSetEditorForm.Loaded; |
252 |
+ |
begin |
253 |
+ |
inherited Loaded; |
254 |
+ |
if IBSQLEditFrame1 <> nil then |
255 |
+ |
begin |
256 |
+ |
IBSQLEditFrame1.OnUserTablesOpened := @HandleUserTablesOpened; |
257 |
+ |
if SelectTableNames <> nil then |
258 |
+ |
SelectTableNames.ListSource := IBSQLEditFrame1.UserTableSource; |
259 |
+ |
if FieldNamesGrid <> nil then |
260 |
+ |
FieldNamesGrid.DataSource := IBSQLEditFrame1.FieldsSource; |
261 |
+ |
if PrimaryKeysGrid <> nil then |
262 |
+ |
PrimaryKeysGrid.DataSource := IBSQLEditFrame1.PrimaryKeySource; |
263 |
+ |
if IdentityGrid <> nil then |
264 |
+ |
IdentityGrid.DataSource := IBSQLEditFrame1.IdentityColsSource; |
265 |
+ |
if ReadOnlyGrid <> nil then |
266 |
+ |
ReadOnlyGrid.DataSource := IBSQLEditFrame1.ReadOnlyFieldsSource; |
267 |
+ |
end; |
268 |
+ |
end; |
269 |
+ |
|
270 |
|
constructor TIBDataSetEditorForm.Create(TheOwner: TComponent); |
271 |
|
begin |
272 |
|
inherited Create(TheOwner); |
260 |
– |
FIBSystemTables := TIBSystemTables.Create; |
273 |
|
FModifySQL := TStringList.Create; |
274 |
|
FInsertSQL := TStringList.Create; |
275 |
|
FDeleteSQL := TStringList.Create; |
279 |
|
|
280 |
|
destructor TIBDataSetEditorForm.Destroy; |
281 |
|
begin |
270 |
– |
if assigned(FIBSystemTables) then FIBSystemTables.Free; |
282 |
|
if assigned(FModifySQL) then FModifySQL.Free; |
283 |
|
if assigned(FInsertSQL) then FInsertSQL.Free; |
284 |
|
if assigned(FDeleteSQL) then FDeleteSQL.Free; |
285 |
|
if assigned(FRefreshSQL) then FRefreshSQL.Free; |
286 |
< |
if assigned(FSelectSQL) then FSelectSQL.Free; |
286 |
> |
if assigned(FSelectSQL) then FSelectSQL.Free; |
287 |
|
inherited Destroy; |
288 |
|
end; |
289 |
|
|
279 |
– |
procedure TIBDataSetEditorForm.SetDataSet(AObject: TIBDataSet); |
280 |
– |
begin |
281 |
– |
FDataSet := AObject; |
282 |
– |
IBTransaction1.DefaultDatabase := FDataSet.Database; |
283 |
– |
if assigned(FDataSet) then |
284 |
– |
FIBSystemTables.SelectDatabase(FDataSet.Database,IBTransaction1); |
285 |
– |
end; |
286 |
– |
|
290 |
|
end. |
288 |
– |
|