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 5 by tony, Fri Feb 18 16:26:16 2011 UTC vs.
Revision 107 by tony, Thu Jan 18 14:37:40 2018 UTC

# Line 1 | Line 1
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+}
# Line 5 | Line 31 | unit IBDataSetEditor;
31   interface
32  
33   uses
34 <  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
35 <  ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBCustomDataSet;
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 <    Button1: TButton;
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;
59 <    PrimaryKeyList: TListBox;
59 >    IncludePrimaryKeys: TCheckBox;
60      Label1: TLabel;
61      Label2: TLabel;
62      Label3: TLabel;
# Line 26 | Line 64 | type
64      OkButton: TButton;
65      PageControl: TPageControl;
66      QuoteFields: TCheckBox;
29    SQLMemo: TMemo;
67      SQLPage: TTabSheet;
68      StatementType: TRadioGroup;
69 <    FieldList: TListBox;
70 <    TableNamesCombo: TComboBox;
71 <    procedure Button1Click(Sender: TObject);
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);
74      procedure GenerateButtonClick(Sender: TObject);
75      procedure SQLMemoChange(Sender: TObject);
76      procedure SQLPageShow(Sender: TObject);
77      procedure StatementTypeClick(Sender: TObject);
41    procedure TableNamesComboCloseUp(Sender: TObject);
78    private
79      { private declarations }
80      FDataSet: TIBDataSet;
45    FIBSystemTables: TIBSystemTables;
81      FDirty: boolean;
82      FCurrentStatement: integer;
83      FSelectSQL: TStringList;
# Line 51 | 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;
58    procedure SetDataSet(AObject: TIBDataSet);
96    end;
97  
98   var
# Line 65 | Line 102 | function EditIBDataSet(DataSet: TIBDataS
102  
103   implementation
104  
105 + {$R *.lfm}
106 +
107   function EditIBDataSet(DataSet: TIBDataSet): boolean;
108   begin
109    Result := false;
110    if assigned(DataSet) and assigned(DataSet.Database) then
111 <  begin
73 <    if not assigned(DataSet.Transaction) then
74 <    begin
75 <      ShowMessage('No Default Transaction!');
76 <      Exit
77 <    end;
78 <
111 >  try
112      DataSet.Database.Connected := true;
113 +  except on E: Exception do
114 +    ShowMessage(E.Message)
115    end;
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 >      IncludeReadOnlyFields := false;
128 >    end;
129 >    Result := ShowModal = mrOK;
130 >    if Result and assigned(DataSet) then
131 >      DataSet.GenerateParamNames := GenerateParams.Checked
132    finally
133      Free
134    end;
# Line 100 | Line 146 | begin
146    FDeleteSQL.Assign(FDataSet.DeleteSQL);
147    FRefreshSQL.Assign(FDataSet.RefreshSQL);
148    FSelectSQL.Assign(FDataSet.SelectSQL);
149 +  GenerateButton.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected;
150 +  TestBtn.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected;
151    FCurrentStatement := -1;
152 <  TableNamesCombo.Items.Clear;
105 <  FIBSystemTables.GetTableNames(TableNamesCombo.Items);
106 <  if TableNamesCombo.Items.Count > 0 then
152 >  if (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected then
153    begin
154 <    TableNamesCombo.ItemIndex := 0;
155 <    if FSelectSQL.Text <> '' then
110 <    try
111 <       FIBSystemTables.GetTableAndColumns(FSelectSQL.Text,TableName,nil);
112 <       TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName);
113 <    except end;//ignore
114 <    FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,false);
115 <    FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
154 >    IBSQLEditFrame1.UserTables.Active := true;
155 >    IBSQLEditFrame1.SyncQueryBuilder(FSelectSQL);
156    end;
157   end;
158  
# Line 130 | Line 170 | begin
170    end;
171   end;
172  
173 < procedure TIBDataSetEditorForm.Button1Click(Sender: TObject);
173 > procedure TIBDataSetEditorForm.TestBtnClick(Sender: TObject);
174   begin
175 <  if SQLMemo.Lines.Text <> '' then
136 <    FIBSystemTables.TestSQL(SQLMemo.Lines.Text);
175 >  IBSQLEditFrame1.TestSQL(GenerateParams.Checked);
176   end;
177  
178 < procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject);
140 < var FieldNames: TStringList;
141 <    I: integer;
178 > procedure TIBDataSetEditorForm.IncludeSysTablesChange(Sender: TObject);
179   begin
180 <  FDataSet.RefreshSQL.Clear;
181 <  FIBSystemTables.GenerateSelectSQL(TableNamesCombo.Text,QuoteFields.Checked,FSelectSQL);
145 <  FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FRefreshSQL);
146 <  FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL);
147 <  if FieldList.SelCount = 0 then
148 <  begin
149 <    FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked,
150 <      FieldList.Items,FModifySQL);
151 <    FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked,
152 <      FieldList.Items,FInsertSQL);
180 >  IBSQLEditFrame1.IncludeSystemTables := IncludeSysTables.Checked;
181 > end;
182  
183 <  end
184 <  else
185 <  begin
186 <    FieldNames := TStringList.Create;
187 <    try
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 <    FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked,
194 <      FieldNames,FInsertSQL);
166 <    finally
167 <      FieldNames.Free
168 <    end;
169 <  end;
183 > procedure TIBDataSetEditorForm.SelectSelectAllClick(Sender: TObject);
184 > begin
185 >  IBSQLEditFrame1.SelectAllFields(SelectSelectAll.Checked);
186 > end;
187 >
188 > procedure TIBDataSetEditorForm.GenerateButtonClick(Sender: TObject);
189 > begin
190 >  IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked,FSelectSQL,true);
191 >  IBSQLEditFrame1.GenerateRefreshSQL(QuoteFields.Checked,FRefreshSQL,true);
192 >  IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked,FDeleteSQL);
193 >  IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked,FInsertSQL);
194 >  IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked,FModifySQL, IncludePrimaryKeys.Checked);
195    FDirty := false;
196    PageControl.ActivePage := SQLPage;
197   end;
# Line 186 | Line 211 | begin
211    UpdateSQLMemo
212   end;
213  
189 procedure TIBDataSetEditorForm.TableNamesComboCloseUp(Sender: TObject);
190 begin
191  FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,false);
192  FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
193 end;
194
214   procedure TIBDataSetEditorForm.UpdateSQLMemo;
215   begin
216    if FDirty then
217      case FCurrentStatement of
218      0: // Select
219 <        FSelectSQL.Assign(SQLMemo.Lines);
219 >        FSelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
220      1: //Modify
221 <        FModifySQL.Assign(SQLMemo.Lines);
221 >        FModifySQL.Assign(IBSQLEditFrame1.SQLText.Lines);
222      2: //Insert
223 <        FInsertSQL.Assign(SQLMemo.Lines);
223 >        FInsertSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
224      3: // Delete
225 <        FDeleteSQL.Assign(SQLMemo.Lines);
225 >        FDeleteSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
226      4: //Refresh
227 <        FRefreshSQL.Assign(SQLMemo.Lines);
227 >        FRefreshSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
228      end;
229    FDirty := false;
230    case StatementType.ItemIndex of
231    0: //Select
232 <     SQLMemo.Lines.Assign(FSelectSQL);
232 >     IBSQLEditFrame1.SQLText.Lines.Assign(FSelectSQL);
233    1: // Modify
234 <    SQLMemo.Lines.Assign(FModifySQL)  ;
234 >    IBSQLEditFrame1.SQLText.Lines.Assign(FModifySQL)  ;
235    2: //Insert
236 <    SQLMemo.Lines.Assign(FInsertSQL)  ;
236 >    IBSQLEditFrame1.SQLText.Lines.Assign(FInsertSQL)  ;
237    3: // Delete
238 <    SQLMemo.Lines.Assign(FDeleteSQL)  ;
238 >    IBSQLEditFrame1.SQLText.Lines.Assign(FDeleteSQL)  ;
239    4: //Refresh
240 <    SQLMemo.Lines.Assign(FRefreshSQL)  ;
240 >    IBSQLEditFrame1.SQLText.Lines.Assign(FRefreshSQL)  ;
241    end;
242    FCurrentStatement := StatementType.ItemIndex;
243   end;
244  
245 + procedure TIBDataSetEditorForm.HandleUserTablesOpened(Sender: TObject);
246 + begin
247 +  SelectSelectAll.Checked := true;
248 + end;
249 +
250 + procedure TIBDataSetEditorForm.Loaded;
251 + begin
252 +  inherited Loaded;
253 +  if IBSQLEditFrame1 <> nil then
254 +  begin
255 +    IBSQLEditFrame1.OnUserTablesOpened := @HandleUserTablesOpened;
256 +    if SelectTableNames <> nil then
257 +      SelectTableNames.ListSource :=  IBSQLEditFrame1.UserTableSource;
258 +    if FieldNamesGrid <> nil then
259 +      FieldNamesGrid.DataSource := IBSQLEditFrame1.FieldsSource;
260 +    if PrimaryKeysGrid <> nil then
261 +      PrimaryKeysGrid.DataSource := IBSQLEditFrame1.PrimaryKeySource;
262 +    if IdentityGrid <> nil then
263 +      IdentityGrid.DataSource := IBSQLEditFrame1.IdentityColsSource;
264 +    if ReadOnlyGrid <> nil then
265 +      ReadOnlyGrid.DataSource := IBSQLEditFrame1.ReadOnlyFieldsSource;
266 +  end;
267 + end;
268 +
269   constructor TIBDataSetEditorForm.Create(TheOwner: TComponent);
270   begin
271    inherited Create(TheOwner);
229  FIBSystemTables := TIBSystemTables.Create;
272    FModifySQL := TStringList.Create;
273    FInsertSQL := TStringList.Create;
274    FDeleteSQL := TStringList.Create;
# Line 236 | Line 278 | end;
278  
279   destructor TIBDataSetEditorForm.Destroy;
280   begin
239  if assigned(FIBSystemTables) then FIBSystemTables.Free;
281    if assigned(FModifySQL) then FModifySQL.Free;
282    if assigned(FInsertSQL) then FInsertSQL.Free;
283    if assigned(FDeleteSQL) then FDeleteSQL.Free;
284    if assigned(FRefreshSQL) then FRefreshSQL.Free;
285 < if assigned(FSelectSQL) then FSelectSQL.Free;
285 >  if assigned(FSelectSQL) then FSelectSQL.Free;
286    inherited Destroy;
287   end;
288  
248 procedure TIBDataSetEditorForm.SetDataSet(AObject: TIBDataSet);
249 begin
250  FDataSet := AObject;
251  if assigned(FDataSet) then
252    FIBSystemTables.SelectDatabase(FDataSet.Database,FDataSet.Transaction);
253 end;
254
255
256 initialization
257  {$I ibdataseteditor.lrs}
258
289   end.
260

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines