ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/ibdataseteditor.pas
Revision: 80
Committed: Mon Jan 1 11:31:07 2018 UTC (6 years, 10 months ago) by tony
Content type: text/x-pascal
File size: 8031 byte(s)
Log Message:
Fixes merged into public release

File Contents

# User Rev Content
1 tony 33 (*
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 tony 80 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
35     StdCtrls, ExtCtrls, IBSQLEditFrame, IBCustomDataSet,
36     IBDatabase, IBLookupComboEditBox, IBDynamicGrid, Types;
37 tony 33
38     type
39    
40     { TIBDataSetEditorForm }
41    
42     TIBDataSetEditorForm = class(TForm)
43 tony 80 FieldNamesGrid: TIBDynamicGrid;
44 tony 33 GenerateParams: TCheckBox;
45 tony 80 IBSQLEditFrame1: TIBSQLEditFrame;
46     IncludeSysTables: TCheckBox;
47     PrimaryKeysGrid: TIBDynamicGrid;
48     SelectSelectAll: TCheckBox;
49     SelectTableNames: TIBLookupComboEditBox;
50 tony 33 TestBtn: TButton;
51     CancelButton: TButton;
52     FieldsPage: TTabSheet;
53     GenerateButton: TButton;
54     GroupBox1: TGroupBox;
55     IncludePrimaryKeys: TCheckBox;
56     Label1: TLabel;
57     Label2: TLabel;
58     Label3: TLabel;
59     Label4: TLabel;
60     OkButton: TButton;
61     PageControl: TPageControl;
62     QuoteFields: TCheckBox;
63     SQLPage: TTabSheet;
64     StatementType: TRadioGroup;
65 tony 80 procedure IncludeSysTablesChange(Sender: TObject);
66     procedure SelectSelectAllClick(Sender: TObject);
67 tony 33 procedure TestBtnClick(Sender: TObject);
68     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
69     procedure FormShow(Sender: TObject);
70     procedure GenerateButtonClick(Sender: TObject);
71     procedure SQLMemoChange(Sender: TObject);
72     procedure SQLPageShow(Sender: TObject);
73     procedure StatementTypeClick(Sender: TObject);
74     private
75     { private declarations }
76     FDataSet: TIBDataSet;
77     FDirty: boolean;
78     FCurrentStatement: integer;
79     FSelectSQL: TStringList;
80     FModifySQL: TStringList;
81     FInsertSQL: TStringList;
82     FDeleteSQL: TStringList;
83     FRefreshSQL: TStringList;
84     procedure UpdateSQLMemo;
85 tony 80 procedure HandleUserTablesOpened(Sender: TObject);
86     protected
87     procedure Loaded; override;
88 tony 33 public
89     { public declarations }
90     constructor Create(TheOwner: TComponent); override;
91     destructor Destroy; override;
92     end;
93    
94     var
95     IBDataSetEditorForm: TIBDataSetEditorForm;
96    
97     function EditIBDataSet(DataSet: TIBDataSet): boolean;
98    
99     implementation
100    
101     {$R *.lfm}
102    
103     function EditIBDataSet(DataSet: TIBDataSet): boolean;
104     begin
105     Result := false;
106     if assigned(DataSet) and assigned(DataSet.Database) then
107     try
108     DataSet.Database.Connected := true;
109     except on E: Exception do
110     ShowMessage(E.Message)
111     end;
112    
113     with TIBDataSetEditorForm.Create(Application) do
114     try
115     if assigned(DataSet) then
116 tony 80 begin
117     IBSQLEditFrame1.Database := DataSet.Database;
118     GenerateParams.Checked := DataSet.GenerateParamNames;
119     end;
120     FDataSet := DataSet;
121 tony 33 Result := ShowModal = mrOK;
122     if Result and assigned(DataSet) then
123     DataSet.GenerateParamNames := GenerateParams.Checked
124     finally
125     Free
126     end;
127    
128     end;
129    
130     { TIBDataSetEditorForm }
131    
132     procedure TIBDataSetEditorForm.FormShow(Sender: TObject);
133     var TableName: string;
134     begin
135     PageControl.ActivePage := FieldsPage;
136     FModifySQL.Assign(FDataSet.ModifySQL);
137     FInsertSQL.Assign(FDataSet.InsertSQL);
138     FDeleteSQL.Assign(FDataSet.DeleteSQL);
139     FRefreshSQL.Assign(FDataSet.RefreshSQL);
140     FSelectSQL.Assign(FDataSet.SelectSQL);
141 tony 80 GenerateButton.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected;
142     TestBtn.Enabled := (IBSQLEditFrame1.Database <> nil) and IBSQLEditFrame1.Database.Connected;
143 tony 33 FCurrentStatement := -1;
144 tony 80 IBSQLEditFrame1.UserTables.Active := true;
145     IBSQLEditFrame1.SyncQueryBuilder(FSelectSQL);
146 tony 33 end;
147    
148     procedure TIBDataSetEditorForm.FormClose(Sender: TObject;
149     var CloseAction: TCloseAction);
150     begin
151     if ModalResult = mrOK then
152     begin
153     UpdateSQLMemo;
154     FDataSet.ModifySQL.Assign(FModifySQL);
155     FDataSet.InsertSQL.Assign(FInsertSQL);
156     FDataSet.DeleteSQL.Assign(FDeleteSQL);
157     FDataSet.RefreshSQL.Assign(FRefreshSQL);
158     FDataSet.SelectSQL.Assign(FSelectSQL);
159     end;
160     end;
161    
162     procedure TIBDataSetEditorForm.TestBtnClick(Sender: TObject);
163     begin
164 tony 80 IBSQLEditFrame1.TestSQL(GenerateParams.Checked);
165 tony 33 end;
166    
167 tony 80 procedure TIBDataSetEditorForm.IncludeSysTablesChange(Sender: TObject);
168 tony 33 begin
169 tony 80 IBSQLEditFrame1.IncludeSystemTables := IncludeSysTables.Checked;
170     end;
171 tony 33
172 tony 80 procedure TIBDataSetEditorForm.SelectSelectAllClick(Sender: TObject);
173     begin
174     IBSQLEditFrame1.SelectAllFields(SelectSelectAll.Checked);
175 tony 33 end;
176    
177 tony 80 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 tony 33 procedure TIBDataSetEditorForm.SQLMemoChange(Sender: TObject);
189     begin
190     FDirty := true
191     end;
192    
193     procedure TIBDataSetEditorForm.SQLPageShow(Sender: TObject);
194     begin
195     UpdateSQLMemo
196     end;
197    
198     procedure TIBDataSetEditorForm.StatementTypeClick(Sender: TObject);
199     begin
200     UpdateSQLMemo
201     end;
202    
203     procedure TIBDataSetEditorForm.UpdateSQLMemo;
204     begin
205     if FDirty then
206     case FCurrentStatement of
207     0: // Select
208 tony 80 FSelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
209 tony 33 1: //Modify
210 tony 80 FModifySQL.Assign(IBSQLEditFrame1.SQLText.Lines);
211 tony 33 2: //Insert
212 tony 80 FInsertSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
213 tony 33 3: // Delete
214 tony 80 FDeleteSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
215 tony 33 4: //Refresh
216 tony 80 FRefreshSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
217 tony 33 end;
218     FDirty := false;
219     case StatementType.ItemIndex of
220     0: //Select
221 tony 80 IBSQLEditFrame1.SQLText.Lines.Assign(FSelectSQL);
222 tony 33 1: // Modify
223 tony 80 IBSQLEditFrame1.SQLText.Lines.Assign(FModifySQL) ;
224 tony 33 2: //Insert
225 tony 80 IBSQLEditFrame1.SQLText.Lines.Assign(FInsertSQL) ;
226 tony 33 3: // Delete
227 tony 80 IBSQLEditFrame1.SQLText.Lines.Assign(FDeleteSQL) ;
228 tony 33 4: //Refresh
229 tony 80 IBSQLEditFrame1.SQLText.Lines.Assign(FRefreshSQL) ;
230 tony 33 end;
231     FCurrentStatement := StatementType.ItemIndex;
232     end;
233    
234 tony 80 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 tony 33 constructor TIBDataSetEditorForm.Create(TheOwner: TComponent);
255     begin
256     inherited Create(TheOwner);
257     FModifySQL := TStringList.Create;
258     FInsertSQL := TStringList.Create;
259     FDeleteSQL := TStringList.Create;
260     FRefreshSQL := TStringList.Create;
261     FSelectSQL := TStringList.Create;
262     end;
263    
264     destructor TIBDataSetEditorForm.Destroy;
265     begin
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 tony 80 if assigned(FSelectSQL) then FSelectSQL.Free;
271 tony 33 inherited Destroy;
272     end;
273    
274     end.