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

Comparing ibx/trunk/design/ibupdatesqleditor.pas (file contents):
Revision 5 by tony, Fri Feb 18 16:26:16 2011 UTC vs.
Revision 7 by tony, Sun Aug 5 18:28:19 2012 UTC

# Line 1 | Line 1
1 < unit IBUpdateSQLEditor;
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 > unit IBUpdateSQLEditor;
27  
28   {$mode objfpc}{$H+}
29  
30   interface
31  
32   uses
33 <  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
34 <  ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBUpdateSQL;
33 >  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
34 >  ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBUpdateSQL, IBDatabase;
35  
36   type
37  
38    { TIBUpdateSQLEditorForm }
39  
40    TIBUpdateSQLEditorForm = class(TForm)
41 <    Button1: TButton;
41 >    TestBtn: TButton;
42      CancelButton: TButton;
43      FieldsPage: TTabSheet;
44 <    GenerateButton: TButton;
44 >    GenerateBtn: TButton;
45      GroupBox1: TGroupBox;
46 +    IBTransaction1: TIBTransaction;
47 +    IncludePrimaryKeys: TCheckBox;
48      PrimaryKeyList: TListBox;
49      Label1: TLabel;
50      Label2: TLabel;
# Line 31 | Line 58 | type
58      StatementType: TRadioGroup;
59      FieldList: TListBox;
60      TableNamesCombo: TComboBox;
61 <    procedure Button1Click(Sender: TObject);
61 >    procedure TestBtnClick(Sender: TObject);
62      procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
63      procedure FormShow(Sender: TObject);
64 <    procedure GenerateButtonClick(Sender: TObject);
64 >    procedure GenerateBtnClick(Sender: TObject);
65      procedure SQLMemoChange(Sender: TObject);
66      procedure SQLPageShow(Sender: TObject);
67      procedure StatementTypeClick(Sender: TObject);
# Line 66 | Line 93 | implementation
93  
94   uses IBQuery;
95  
96 + {$R *.lfm}
97 +
98   function EditIBUpdateSQL(UpdateObject: TIBUpdateSQL): boolean;
99   begin
100    Result := false;
101    if assigned(UpdateObject.DataSet) and assigned(UpdateObject.DataSet.Database) then
102 <  begin
103 <    if not assigned(UpdateObject.DataSet.Transaction) then
104 <    begin
105 <      ShowMessage('No Default Transaction!');
77 <      Exit
102 >    try
103 >      UpdateObject.DataSet.Database.Connected := true;
104 >    except on E: Exception do
105 >      ShowMessage(E.Message)
106      end;
107  
80    UpdateObject.DataSet.Database.Connected := true;
81  end;
82
108    with TIBUpdateSQLEditorForm.Create(Application) do
109    try
110      SetUpdateObject(UpdateObject);
# Line 95 | Line 120 | end;
120   procedure TIBUpdateSQLEditorForm.FormShow(Sender: TObject);
121   var TableName: string;
122   begin
123 +  GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
124 +  TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
125    PageControl.ActivePage := FieldsPage;
126    FModifySQL.Assign(FUpdateObject.ModifySQL);
127    FInsertSQL.Assign(FUpdateObject.InsertSQL);
# Line 113 | Line 140 | begin
140         TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName);
141      except  //ignore
142      end;
143 <    FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,false);
143 >    FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false);
144      FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
145    end;
146   end;
# Line 131 | Line 158 | begin
158    end;
159   end;
160  
161 < procedure TIBUpdateSQLEditorForm.Button1Click(Sender: TObject);
161 > procedure TIBUpdateSQLEditorForm.TestBtnClick(Sender: TObject);
162   begin
163    if SQLMemo.Lines.Text <> '' then
164      FIBSystemTables.TestSQL(SQLMemo.Lines.Text);
165   end;
166  
167 < procedure TIBUpdateSQLEditorForm.GenerateButtonClick(Sender: TObject);
167 > procedure TIBUpdateSQLEditorForm.GenerateBtnClick(Sender: TObject);
168   var FieldNames: TStringList;
169      I: integer;
170   begin
171 <  FUpdateObject.RefreshSQL.Clear;
172 <  FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FRefreshSQL);
173 <  FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL);
174 <  if FieldList.SelCount = 0 then
175 <  begin
176 <    FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked,
177 <      FieldList.Items,FModifySQL);
171 >  FieldNames := TStringList.Create;
172 >  try
173 >    FUpdateObject.RefreshSQL.Clear;
174 >    FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames);
175 >    FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FRefreshSQL);
176 >    FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL);
177 >    FieldNames.Clear;
178 >    FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames,true,false);
179      FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked,
180 <      FieldList.Items,FInsertSQL);
180 >        FieldNames,FInsertSQL);
181 >    if FieldList.SelCount = 0 then
182 >    begin
183 >      FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked,
184 >        FieldList.Items,FModifySQL);
185  
186 <  end
187 <  else
188 <  begin
189 <    FieldNames := TStringList.Create;
158 <    try
186 >    end
187 >    else
188 >    begin
189 >      FieldNames.Clear;
190        for I := 0 to FieldList.Items.Count - 1 do
191 <        if FieldList.Selected[I] then
192 <          FieldNames.Add(FieldList.Items[I]);
191 >          if FieldList.Selected[I] then
192 >               FieldNames.Add(FieldList.Items[I]);
193        FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked,
194 <        FieldNames,FModifySQL);
164 <    FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked,
165 <      FieldNames,FInsertSQL);
166 <    finally
167 <      FieldNames.Free
194 >           FieldNames,FModifySQL);
195      end;
196 +    FDirty := false;
197 +    PageControl.ActivePage := SQLPage;
198 +  finally
199 +    FieldNames.Free
200    end;
170  FDirty := false;
171  PageControl.ActivePage := SQLPage;
201   end;
202  
203   procedure TIBUpdateSQLEditorForm.SQLMemoChange(Sender: TObject);
# Line 188 | Line 217 | end;
217  
218   procedure TIBUpdateSQLEditorForm.TableNamesComboCloseUp(Sender: TObject);
219   begin
220 <  FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,false);
220 >  FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false);
221    FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
222   end;
223  
# Line 243 | Line 272 | procedure TIBUpdateSQLEditorForm.SetUpda
272   begin
273    FUpdateObject := AObject;
274    if assigned(FUpdateObject.DataSet) then
275 <    FIBSystemTables.SelectDatabase(FUpdateObject.DataSet.Database,FUpdateObject.DataSet.Transaction);
275 >  begin
276 >    IBTransaction1.DefaultDatabase := FUpdateObject.DataSet.Database;
277 >    FIBSystemTables.SelectDatabase(FUpdateObject.DataSet.Database,IBTransaction1);
278 >  end;
279   end;
280  
281  
250 initialization
251  {$I ibupdatesqleditor.lrs}
252
282   end.
283  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines