ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/ibdataseteditor.pas
(Generate patch)

Comparing ibx/trunk/design/ibdataseteditor.pas (file contents):
Revision 33 by tony, Sat Jul 18 12:30:52 2015 UTC vs.
Revision 209 by tony, Wed Mar 14 12:48:51 2018 UTC

# Line 31 | Line 31 | unit IBDataSetEditor;
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;
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;
48    IBTransaction1: TIBTransaction;
59      IncludePrimaryKeys: TCheckBox;
50    PrimaryKeyList: TListBox;
60      Label1: TLabel;
61      Label2: TLabel;
62      Label3: TLabel;
# Line 55 | Line 64 | type
64      OkButton: TButton;
65      PageControl: TPageControl;
66      QuoteFields: TCheckBox;
58    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);
# Line 67 | Line 75 | type
75      procedure SQLMemoChange(Sender: TObject);
76      procedure SQLPageShow(Sender: TObject);
77      procedure StatementTypeClick(Sender: TObject);
70    procedure TableNamesComboCloseUp(Sender: TObject);
78    private
79      { private declarations }
80      FDataSet: TIBDataSet;
74    FIBSystemTables: TIBSystemTables;
81      FDirty: boolean;
82      FCurrentStatement: integer;
83      FSelectSQL: TStringList;
# Line 80 | Line 86 | type
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;
87    procedure SetDataSet(AObject: TIBDataSet);
96    end;
97  
98   var
# Line 108 | Line 116 | begin
116  
117    with TIBDataSetEditorForm.Create(Application) do
118    try
111    SetDataSet(DataSet);
119      if assigned(DataSet) then
120 <        GenerateParams.Checked := DataSet.GenerateParamNames;
120 >    begin
121 >      IBSQLEditFrame1.Database := DataSet.Database;
122 >      GenerateParams.Checked := DataSet.GenerateParamNames;
123 >    end;
124 >    FDataSet := DataSet;
125 >    with IBSQLEditFrame1 do
126 >    begin
127 >      IncludeReadOnlyFields := false;
128 >    end;
129      Result := ShowModal = mrOK;
130      if Result and assigned(DataSet) then
131        DataSet.GenerateParamNames := GenerateParams.Checked
# Line 123 | Line 138 | end;
138   { TIBDataSetEditorForm }
139  
140   procedure TIBDataSetEditorForm.FormShow(Sender: TObject);
126 var TableName: string;
141   begin
142    PageControl.ActivePage := FieldsPage;
143    FModifySQL.Assign(FDataSet.ModifySQL);
# Line 131 | Line 145 | begin
145    FDeleteSQL.Assign(FDataSet.DeleteSQL);
146    FRefreshSQL.Assign(FDataSet.RefreshSQL);
147    FSelectSQL.Assign(FDataSet.SelectSQL);
148 <  GenerateButton.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
149 <  TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
148 >  GenerateButton.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected;
149 >  TestBtn.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected;
150    FCurrentStatement := -1;
151 <  TableNamesCombo.Items.Clear;
138 <  FIBSystemTables.GetTableNames(TableNamesCombo.Items);
139 <  if TableNamesCombo.Items.Count > 0 then
151 >  if (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected then
152    begin
153 <    TableNamesCombo.ItemIndex := 0;
154 <    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);
153 >    IBSQLEditFrame1.UserTables.Active := true;
154 >    IBSQLEditFrame1.SyncQueryBuilder(FSelectSQL);
155    end;
156   end;
157  
# Line 165 | Line 171 | end;
171  
172   procedure TIBDataSetEditorForm.TestBtnClick(Sender: TObject);
173   begin
174 <  if SQLMemo.Lines.Text <> '' then
169 <    FIBSystemTables.TestSQL(SQLMemo.Lines.Text,GenerateParams.Checked);
174 >  IBSQLEditFrame1.TestSQL(GenerateParams.Checked);
175   end;
176  
177 < procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject);
173 < var FieldNames: TStringList;
174 <    I: integer;
177 > procedure TIBDataSetEditorForm.IncludeSysTablesChange(Sender: TObject);
178   begin
179 <  FieldNames := TStringList.Create;
180 <  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);
179 >  IBSQLEditFrame1.IncludeSystemTables := IncludeSysTables.Checked;
180 > end;
181  
182 <    end
183 <    else
184 <    begin
185 <      FieldNames.Clear;
186 <      for I := 0 to FieldList.Items.Count - 1 do
187 <        if FieldList.Selected[I] then
188 <          FieldNames.Add(FieldList.Items[I]);
189 <      FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked,
190 <        FieldNames,FModifySQL);
191 <    end;
192 <    FDirty := false;
193 <    PageControl.ActivePage := SQLPage;
194 <  finally
195 <    FieldNames.Free
207 <  end;
182 > procedure TIBDataSetEditorForm.SelectSelectAllClick(Sender: TObject);
183 > begin
184 >  IBSQLEditFrame1.SelectAllFields(SelectSelectAll.Checked);
185 > end;
186 >
187 > procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject);
188 > begin
189 >  IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked,FSelectSQL,true);
190 >  IBSQLEditFrame1.GenerateRefreshSQL(QuoteFields.Checked,FRefreshSQL,true);
191 >  IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked,FDeleteSQL);
192 >  IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked,FInsertSQL);
193 >  IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked,FModifySQL, IncludePrimaryKeys.Checked);
194 >  FDirty := false;
195 >  PageControl.ActivePage := SQLPage;
196   end;
197  
198   procedure TIBDataSetEditorForm.SQLMemoChange(Sender: TObject);
# Line 222 | Line 210 | begin
210    UpdateSQLMemo
211   end;
212  
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
213   procedure TIBDataSetEditorForm.UpdateSQLMemo;
214   begin
215    if FDirty then
216      case FCurrentStatement of
217      0: // Select
218 <        FSelectSQL.Assign(SQLMemo.Lines);
218 >        FSelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
219      1: //Modify
220 <        FModifySQL.Assign(SQLMemo.Lines);
220 >        FModifySQL.Assign(IBSQLEditFrame1.SQLText.Lines);
221      2: //Insert
222 <        FInsertSQL.Assign(SQLMemo.Lines);
222 >        FInsertSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
223      3: // Delete
224 <        FDeleteSQL.Assign(SQLMemo.Lines);
224 >        FDeleteSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
225      4: //Refresh
226 <        FRefreshSQL.Assign(SQLMemo.Lines);
226 >        FRefreshSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
227      end;
228    FDirty := false;
229    case StatementType.ItemIndex of
230    0: //Select
231 <     SQLMemo.Lines.Assign(FSelectSQL);
231 >     IBSQLEditFrame1.SQLText.Lines.Assign(FSelectSQL);
232    1: // Modify
233 <    SQLMemo.Lines.Assign(FModifySQL)  ;
233 >    IBSQLEditFrame1.SQLText.Lines.Assign(FModifySQL)  ;
234    2: //Insert
235 <    SQLMemo.Lines.Assign(FInsertSQL)  ;
235 >    IBSQLEditFrame1.SQLText.Lines.Assign(FInsertSQL)  ;
236    3: // Delete
237 <    SQLMemo.Lines.Assign(FDeleteSQL)  ;
237 >    IBSQLEditFrame1.SQLText.Lines.Assign(FDeleteSQL)  ;
238    4: //Refresh
239 <    SQLMemo.Lines.Assign(FRefreshSQL)  ;
239 >    IBSQLEditFrame1.SQLText.Lines.Assign(FRefreshSQL)  ;
240    end;
241    FCurrentStatement := StatementType.ItemIndex;
242   end;
243  
244 + procedure TIBDataSetEditorForm.HandleUserTablesOpened(Sender: TObject);
245 + begin
246 +  SelectSelectAll.Checked := true;
247 + end;
248 +
249 + procedure TIBDataSetEditorForm.Loaded;
250 + begin
251 +  inherited Loaded;
252 +  if IBSQLEditFrame1 <> nil then
253 +  begin
254 +    IBSQLEditFrame1.OnUserTablesOpened := @HandleUserTablesOpened;
255 +    if SelectTableNames <> nil then
256 +      SelectTableNames.ListSource :=  IBSQLEditFrame1.UserTableSource;
257 +    if FieldNamesGrid <> nil then
258 +      FieldNamesGrid.DataSource := IBSQLEditFrame1.FieldsSource;
259 +    if PrimaryKeysGrid <> nil then
260 +      PrimaryKeysGrid.DataSource := IBSQLEditFrame1.PrimaryKeySource;
261 +    if IdentityGrid <> nil then
262 +      IdentityGrid.DataSource := IBSQLEditFrame1.IdentityColsSource;
263 +    if ReadOnlyGrid <> nil then
264 +      ReadOnlyGrid.DataSource := IBSQLEditFrame1.ReadOnlyFieldsSource;
265 +  end;
266 + end;
267 +
268   constructor TIBDataSetEditorForm.Create(TheOwner: TComponent);
269   begin
270    inherited Create(TheOwner);
265  FIBSystemTables := TIBSystemTables.Create;
271    FModifySQL := TStringList.Create;
272    FInsertSQL := TStringList.Create;
273    FDeleteSQL := TStringList.Create;
# Line 272 | Line 277 | end;
277  
278   destructor TIBDataSetEditorForm.Destroy;
279   begin
275  if assigned(FIBSystemTables) then FIBSystemTables.Free;
280    if assigned(FModifySQL) then FModifySQL.Free;
281    if assigned(FInsertSQL) then FInsertSQL.Free;
282    if assigned(FDeleteSQL) then FDeleteSQL.Free;
283    if assigned(FRefreshSQL) then FRefreshSQL.Free;
284 < if assigned(FSelectSQL) then FSelectSQL.Free;
284 >  if assigned(FSelectSQL) then FSelectSQL.Free;
285    inherited Destroy;
286   end;
287  
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
288   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines