ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/ibsqleditor.pas
Revision: 80
Committed: Mon Jan 1 11:31:07 2018 UTC (6 years, 3 months ago) by tony
Content type: text/x-pascal
File size: 4510 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 tony 80 unit ibsqleditor;
28    
29 tony 33 {$mode objfpc}{$H+}
30    
31     interface
32    
33     uses
34 tony 80 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
35     StdCtrls, ComCtrls, ibselectsqleditor, IBSQLEditFrame, IBLookupComboEditBox,
36     IBDynamicGrid, IBDatabase, IBSQL, IB;
37 tony 33
38     type
39    
40     { TIBSQLEditorForm }
41    
42 tony 80 TIBSQLEditorForm = class(TIBSelectSQLEditorForm)
43 tony 33 IncludePrimaryKeys: TCheckBox;
44 tony 80 TabControl1: TTabControl;
45     procedure FormShow(Sender: TObject);
46 tony 33 procedure GenerateBtnClick(Sender: TObject);
47 tony 80 procedure IncludePrimaryKeysChange(Sender: TObject);
48     procedure TabControl1Change(Sender: TObject);
49 tony 33 private
50 tony 80 procedure SetupFlags;
51 tony 37 protected
52 tony 80 procedure SetSQLStatementType(aType: TIBSQLStatementTypes); override;
53 tony 33 public
54 tony 80
55 tony 33 end;
56    
57 tony 80 function EditSQL(aIBSQL: TIBSQL): boolean;
58    
59 tony 33 var
60     IBSQLEditorForm: TIBSQLEditorForm;
61    
62     implementation
63    
64     {$R *.lfm}
65    
66 tony 80 function EditSQL(aIBSQL: TIBSQL): boolean;
67 tony 33 begin
68     Result := false;
69 tony 80 if assigned(aIBSQL) and assigned(aIBSQL.Database) then
70 tony 33 try
71 tony 80 aIBSQL.Database.Connected := true;
72 tony 33 except on E: Exception do
73     ShowMessage(E.Message)
74     end;
75    
76     with TIBSQLEditorForm.Create(Application) do
77     try
78 tony 80 if assigned(aIBSQL) then
79     begin
80     IBSQLEditFrame1.Database := aIBSQL.Database;
81     GenerateParams.Checked := aIBSQL.GenerateParamNames;
82     end;
83     with IBSQLEditFrame1 do
84     begin
85     IncludePrimaryKeys := true;
86     IncludeReadOnlyFields := true;
87     ExecuteOnlyProcs := false;
88     SQLText.Lines.Assign(aIBSQL.SQL);
89     end;
90     IncludePrimaryKeys.Checked := false;
91 tony 33 Result := ShowModal = mrOK;
92     if Result then
93 tony 80 begin
94     aIBSQL.SQL.Assign(IBSQLEditFrame1.SQLText.Lines);
95     if assigned(aIBSQL) then
96     aIBSQL.GenerateParamNames := GenerateParams.Checked
97     end;
98 tony 33 finally
99     Free
100     end;
101     end;
102    
103     { TIBSQLEditorForm }
104    
105 tony 80 procedure TIBSQLEditorForm.TabControl1Change(Sender: TObject);
106 tony 33 begin
107 tony 80 case TabControl1.TabIndex of
108     4:
109     PageControl.ActivePage := ExecutePage;
110 tony 33 else
111 tony 80 PageControl.ActivePage := SelectPage;
112 tony 33 end;
113 tony 80 SetupFlags;
114 tony 33 end;
115    
116 tony 80 procedure TIBSQLEditorForm.FormShow(Sender: TObject);
117 tony 33 begin
118 tony 80 inherited;
119     SetupFlags;
120 tony 33 end;
121    
122     procedure TIBSQLEditorForm.GenerateBtnClick(Sender: TObject);
123     begin
124 tony 80 case TabControl1.TabIndex of
125     0:
126     IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked);
127     1:
128     IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked);
129     2:
130     IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked);
131     3:
132     IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked);
133     4:
134     IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked);
135 tony 33 end;
136     end;
137    
138 tony 80 procedure TIBSQLEditorForm.IncludePrimaryKeysChange(Sender: TObject);
139 tony 33 begin
140 tony 80 IBSQLEditFrame1.IncludePrimaryKeys := IncludePrimaryKeys.Checked;
141 tony 33 end;
142    
143 tony 80 procedure TIBSQLEditorForm.SetupFlags;
144 tony 33 begin
145 tony 80 IBSQLEditFrame1.IncludePrimaryKeys := (TabControl1.TabIndex <= 1) or ((TabControl1.TabIndex = 2) and IncludePrimaryKeys.Checked);
146     IBSQLEditFrame1.IncludeReadOnlyFields := (TabControl1.TabIndex = 0);
147     IncludePrimaryKeys.Visible := TabControl1.TabIndex = 2;
148     FieldNamesGrid.Visible := TabControl1.TabIndex <> 3;
149     Label2.Visible := TabControl1.TabIndex <> 3;
150     PrimaryKeysGrid.Visible := TabControl1.TabIndex <> 1;
151     Label4.Visible := TabControl1.TabIndex <> 1;
152     SelectSelectAll.Visible := TabControl1.TabIndex <> 3;
153 tony 33 end;
154    
155 tony 80 procedure TIBSQLEditorForm.SetSQLStatementType(aType: TIBSQLStatementTypes);
156 tony 33 begin
157 tony 80 inherited SetSQLStatementType(aType);
158     case aType of
159     SQLSelect:
160     TabControl1.TabIndex := 0;
161     SQLInsert:
162     TabControl1.TabIndex := 1;
163     SQLUpdate:
164     TabControl1.TabIndex := 2;
165     SQLDelete:
166     TabControl1.TabIndex := 3;
167 tony 33 else
168 tony 80 TabControl1.TabIndex := 4;
169 tony 33 end;
170     end;
171    
172 tony 80 end.
173 tony 33