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 |
+ |
PrimaryKeysGrid: TIBDynamicGrid; |
48 |
+ |
SelectSelectAll: TCheckBox; |
49 |
+ |
SelectTableNames: TIBLookupComboEditBox; |
50 |
|
TestBtn: TButton; |
51 |
|
CancelButton: TButton; |
52 |
|
FieldsPage: TTabSheet; |
53 |
|
GenerateButton: TButton; |
54 |
|
GroupBox1: TGroupBox; |
48 |
– |
IBTransaction1: TIBTransaction; |
55 |
|
IncludePrimaryKeys: TCheckBox; |
50 |
– |
PrimaryKeyList: TListBox; |
56 |
|
Label1: TLabel; |
57 |
|
Label2: TLabel; |
58 |
|
Label3: TLabel; |
60 |
|
OkButton: TButton; |
61 |
|
PageControl: TPageControl; |
62 |
|
QuoteFields: TCheckBox; |
58 |
– |
SQLMemo: TMemo; |
63 |
|
SQLPage: TTabSheet; |
64 |
|
StatementType: TRadioGroup; |
65 |
< |
FieldList: TListBox; |
66 |
< |
TableNamesCombo: TComboBox; |
65 |
> |
procedure IncludeSysTablesChange(Sender: TObject); |
66 |
> |
procedure SelectSelectAllClick(Sender: TObject); |
67 |
|
procedure TestBtnClick(Sender: TObject); |
68 |
|
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); |
69 |
|
procedure FormShow(Sender: TObject); |
71 |
|
procedure SQLMemoChange(Sender: TObject); |
72 |
|
procedure SQLPageShow(Sender: TObject); |
73 |
|
procedure StatementTypeClick(Sender: TObject); |
70 |
– |
procedure TableNamesComboCloseUp(Sender: TObject); |
74 |
|
private |
75 |
|
{ private declarations } |
76 |
|
FDataSet: TIBDataSet; |
74 |
– |
FIBSystemTables: TIBSystemTables; |
77 |
|
FDirty: boolean; |
78 |
|
FCurrentStatement: integer; |
79 |
|
FSelectSQL: TStringList; |
82 |
|
FDeleteSQL: TStringList; |
83 |
|
FRefreshSQL: TStringList; |
84 |
|
procedure UpdateSQLMemo; |
85 |
+ |
procedure HandleUserTablesOpened(Sender: TObject); |
86 |
+ |
protected |
87 |
+ |
procedure Loaded; override; |
88 |
|
public |
89 |
|
{ public declarations } |
90 |
|
constructor Create(TheOwner: TComponent); override; |
91 |
|
destructor Destroy; override; |
87 |
– |
procedure SetDataSet(AObject: TIBDataSet); |
92 |
|
end; |
93 |
|
|
94 |
|
var |
112 |
|
|
113 |
|
with TIBDataSetEditorForm.Create(Application) do |
114 |
|
try |
111 |
– |
SetDataSet(DataSet); |
115 |
|
if assigned(DataSet) then |
116 |
< |
GenerateParams.Checked := DataSet.GenerateParamNames; |
116 |
> |
begin |
117 |
> |
IBSQLEditFrame1.Database := DataSet.Database; |
118 |
> |
GenerateParams.Checked := DataSet.GenerateParamNames; |
119 |
> |
end; |
120 |
> |
FDataSet := DataSet; |
121 |
|
Result := ShowModal = mrOK; |
122 |
|
if Result and assigned(DataSet) then |
123 |
|
DataSet.GenerateParamNames := GenerateParams.Checked |
138 |
|
FDeleteSQL.Assign(FDataSet.DeleteSQL); |
139 |
|
FRefreshSQL.Assign(FDataSet.RefreshSQL); |
140 |
|
FSelectSQL.Assign(FDataSet.SelectSQL); |
141 |
< |
GenerateButton.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
142 |
< |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
141 |
> |
GenerateButton.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected; |
142 |
> |
TestBtn.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected; |
143 |
|
FCurrentStatement := -1; |
144 |
< |
TableNamesCombo.Items.Clear; |
145 |
< |
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; |
144 |
> |
IBSQLEditFrame1.UserTables.Active := true; |
145 |
> |
IBSQLEditFrame1.SyncQueryBuilder(FSelectSQL); |
146 |
|
end; |
147 |
|
|
148 |
|
procedure TIBDataSetEditorForm.FormClose(Sender: TObject; |
161 |
|
|
162 |
|
procedure TIBDataSetEditorForm.TestBtnClick(Sender: TObject); |
163 |
|
begin |
164 |
< |
if SQLMemo.Lines.Text <> '' then |
169 |
< |
FIBSystemTables.TestSQL(SQLMemo.Lines.Text,GenerateParams.Checked); |
164 |
> |
IBSQLEditFrame1.TestSQL(GenerateParams.Checked); |
165 |
|
end; |
166 |
|
|
167 |
< |
procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject); |
173 |
< |
var FieldNames: TStringList; |
174 |
< |
I: integer; |
167 |
> |
procedure TIBDataSetEditorForm.IncludeSysTablesChange(Sender: TObject); |
168 |
|
begin |
169 |
< |
FieldNames := TStringList.Create; |
170 |
< |
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); |
169 |
> |
IBSQLEditFrame1.IncludeSystemTables := IncludeSysTables.Checked; |
170 |
> |
end; |
171 |
|
|
172 |
< |
end |
173 |
< |
else |
174 |
< |
begin |
175 |
< |
FieldNames.Clear; |
176 |
< |
for I := 0 to FieldList.Items.Count - 1 do |
177 |
< |
if FieldList.Selected[I] then |
178 |
< |
FieldNames.Add(FieldList.Items[I]); |
179 |
< |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
180 |
< |
FieldNames,FModifySQL); |
181 |
< |
end; |
182 |
< |
FDirty := false; |
183 |
< |
PageControl.ActivePage := SQLPage; |
184 |
< |
finally |
185 |
< |
FieldNames.Free |
207 |
< |
end; |
172 |
> |
procedure TIBDataSetEditorForm.SelectSelectAllClick(Sender: TObject); |
173 |
> |
begin |
174 |
> |
IBSQLEditFrame1.SelectAllFields(SelectSelectAll.Checked); |
175 |
> |
end; |
176 |
> |
|
177 |
> |
procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject); |
178 |
> |
begin |
179 |
> |
IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked,FSelectSQL); |
180 |
> |
IBSQLEditFrame1.GenerateRefreshSQL(QuoteFields.Checked,FRefreshSQL); |
181 |
> |
IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked,FDeleteSQL); |
182 |
> |
IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked,FInsertSQL); |
183 |
> |
IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked,FModifySQL, not IncludePrimaryKeys.Checked); |
184 |
> |
FDirty := false; |
185 |
> |
PageControl.ActivePage := SQLPage; |
186 |
|
end; |
187 |
|
|
188 |
|
procedure TIBDataSetEditorForm.SQLMemoChange(Sender: TObject); |
200 |
|
UpdateSQLMemo |
201 |
|
end; |
202 |
|
|
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 |
– |
|
203 |
|
procedure TIBDataSetEditorForm.UpdateSQLMemo; |
204 |
|
begin |
205 |
|
if FDirty then |
206 |
|
case FCurrentStatement of |
207 |
|
0: // Select |
208 |
< |
FSelectSQL.Assign(SQLMemo.Lines); |
208 |
> |
FSelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
209 |
|
1: //Modify |
210 |
< |
FModifySQL.Assign(SQLMemo.Lines); |
210 |
> |
FModifySQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
211 |
|
2: //Insert |
212 |
< |
FInsertSQL.Assign(SQLMemo.Lines); |
212 |
> |
FInsertSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
213 |
|
3: // Delete |
214 |
< |
FDeleteSQL.Assign(SQLMemo.Lines); |
214 |
> |
FDeleteSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
215 |
|
4: //Refresh |
216 |
< |
FRefreshSQL.Assign(SQLMemo.Lines); |
216 |
> |
FRefreshSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
217 |
|
end; |
218 |
|
FDirty := false; |
219 |
|
case StatementType.ItemIndex of |
220 |
|
0: //Select |
221 |
< |
SQLMemo.Lines.Assign(FSelectSQL); |
221 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FSelectSQL); |
222 |
|
1: // Modify |
223 |
< |
SQLMemo.Lines.Assign(FModifySQL) ; |
223 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FModifySQL) ; |
224 |
|
2: //Insert |
225 |
< |
SQLMemo.Lines.Assign(FInsertSQL) ; |
225 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FInsertSQL) ; |
226 |
|
3: // Delete |
227 |
< |
SQLMemo.Lines.Assign(FDeleteSQL) ; |
227 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FDeleteSQL) ; |
228 |
|
4: //Refresh |
229 |
< |
SQLMemo.Lines.Assign(FRefreshSQL) ; |
229 |
> |
IBSQLEditFrame1.SQLText.Lines.Assign(FRefreshSQL) ; |
230 |
|
end; |
231 |
|
FCurrentStatement := StatementType.ItemIndex; |
232 |
|
end; |
233 |
|
|
234 |
+ |
procedure TIBDataSetEditorForm.HandleUserTablesOpened(Sender: TObject); |
235 |
+ |
begin |
236 |
+ |
SelectSelectAll.Checked := true; |
237 |
+ |
end; |
238 |
+ |
|
239 |
+ |
procedure TIBDataSetEditorForm.Loaded; |
240 |
+ |
begin |
241 |
+ |
inherited Loaded; |
242 |
+ |
if IBSQLEditFrame1 <> nil then |
243 |
+ |
begin |
244 |
+ |
IBSQLEditFrame1.OnUserTablesOpened := @HandleUserTablesOpened; |
245 |
+ |
if SelectTableNames <> nil then |
246 |
+ |
SelectTableNames.ListSource := IBSQLEditFrame1.UserTableSource; |
247 |
+ |
if FieldNamesGrid <> nil then |
248 |
+ |
FieldNamesGrid.DataSource := IBSQLEditFrame1.FieldsSource; |
249 |
+ |
if PrimaryKeysGrid <> nil then |
250 |
+ |
PrimaryKeysGrid.DataSource := IBSQLEditFrame1.PrimaryKeySource; |
251 |
+ |
end; |
252 |
+ |
end; |
253 |
+ |
|
254 |
|
constructor TIBDataSetEditorForm.Create(TheOwner: TComponent); |
255 |
|
begin |
256 |
|
inherited Create(TheOwner); |
265 |
– |
FIBSystemTables := TIBSystemTables.Create; |
257 |
|
FModifySQL := TStringList.Create; |
258 |
|
FInsertSQL := TStringList.Create; |
259 |
|
FDeleteSQL := TStringList.Create; |
263 |
|
|
264 |
|
destructor TIBDataSetEditorForm.Destroy; |
265 |
|
begin |
275 |
– |
if assigned(FIBSystemTables) then FIBSystemTables.Free; |
266 |
|
if assigned(FModifySQL) then FModifySQL.Free; |
267 |
|
if assigned(FInsertSQL) then FInsertSQL.Free; |
268 |
|
if assigned(FDeleteSQL) then FDeleteSQL.Free; |
269 |
|
if assigned(FRefreshSQL) then FRefreshSQL.Free; |
270 |
< |
if assigned(FSelectSQL) then FSelectSQL.Free; |
270 |
> |
if assigned(FSelectSQL) then FSelectSQL.Free; |
271 |
|
inherited Destroy; |
272 |
|
end; |
273 |
|
|
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 |
– |
|
274 |
|
end. |