ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/ibsqleditor.pas
Revision: 107
Committed: Thu Jan 18 14:37:40 2018 UTC (6 years, 3 months ago) by tony
Content type: text/x-pascal
File size: 4784 byte(s)
Log Message:
Fixes merged

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 106 Classes, SysUtils, FileUtil, SynEdit, LResources, Forms, Controls, Graphics,
35     Dialogs, StdCtrls, ComCtrls, ibinsertsqleditor, IBSQLEditFrame,
36 tony 107 IBLookupComboEditBox, IBDynamicGrid, IBDatabase, IBSQL, IBQuery, IB, Types, db;
37 tony 33
38     type
39    
40     { TIBSQLEditorForm }
41    
42 tony 106 TIBSQLEditorForm = class(TIBInsertSQLEditorForm)
43 tony 33 IncludePrimaryKeys: TCheckBox;
44 tony 107 SelectProcedure: TLabel;
45 tony 80 TabControl1: TTabControl;
46     procedure FormShow(Sender: TObject);
47 tony 33 procedure GenerateBtnClick(Sender: TObject);
48 tony 80 procedure TabControl1Change(Sender: TObject);
49 tony 107 procedure UserProceduresAfterScroll(DataSet: TDataSet);
50 tony 33 private
51 tony 80 procedure SetupFlags;
52 tony 37 protected
53 tony 80 procedure SetSQLStatementType(aType: TIBSQLStatementTypes); override;
54 tony 33 public
55 tony 80
56 tony 33 end;
57    
58 tony 80 function EditSQL(aIBSQL: TIBSQL): boolean;
59    
60 tony 33 var
61     IBSQLEditorForm: TIBSQLEditorForm;
62    
63     implementation
64    
65     {$R *.lfm}
66    
67 tony 80 function EditSQL(aIBSQL: TIBSQL): boolean;
68 tony 33 begin
69     Result := false;
70 tony 80 if assigned(aIBSQL) and assigned(aIBSQL.Database) then
71 tony 33 try
72 tony 80 aIBSQL.Database.Connected := true;
73 tony 33 except on E: Exception do
74     ShowMessage(E.Message)
75     end;
76    
77     with TIBSQLEditorForm.Create(Application) do
78     try
79 tony 80 if assigned(aIBSQL) then
80     begin
81     IBSQLEditFrame1.Database := aIBSQL.Database;
82     GenerateParams.Checked := aIBSQL.GenerateParamNames;
83     end;
84     with IBSQLEditFrame1 do
85     begin
86     IncludeReadOnlyFields := true;
87 tony 107 ExecuteOnlyProcs := true;
88     SelectProcs := true;
89 tony 80 SQLText.Lines.Assign(aIBSQL.SQL);
90     end;
91     IncludePrimaryKeys.Checked := false;
92 tony 33 Result := ShowModal = mrOK;
93     if Result then
94 tony 80 begin
95     aIBSQL.SQL.Assign(IBSQLEditFrame1.SQLText.Lines);
96     if assigned(aIBSQL) then
97     aIBSQL.GenerateParamNames := GenerateParams.Checked
98     end;
99 tony 33 finally
100     Free
101     end;
102     end;
103    
104     { TIBSQLEditorForm }
105    
106 tony 80 procedure TIBSQLEditorForm.TabControl1Change(Sender: TObject);
107 tony 33 begin
108 tony 80 case TabControl1.TabIndex of
109     4:
110     PageControl.ActivePage := ExecutePage;
111 tony 33 else
112 tony 80 PageControl.ActivePage := SelectPage;
113 tony 33 end;
114 tony 80 SetupFlags;
115 tony 33 end;
116    
117 tony 107 procedure TIBSQLEditorForm.UserProceduresAfterScroll(DataSet: TDataSet);
118     begin
119     SelectProcedure.Visible := (DataSet.FieldByName('RDB$PROCEDURE_TYPE').AsInteger = 1)
120     and (Dataset.FieldByName('RDB$PROCEDURE_OUTPUTS').AsInteger > 0);
121     if SelectProcedure.Visible then
122     OutputProcGrid.Columns[0].Width := 30
123     else
124     OutputProcGrid.Columns[0].Width := 0;
125     end;
126    
127 tony 80 procedure TIBSQLEditorForm.FormShow(Sender: TObject);
128 tony 33 begin
129 tony 80 inherited;
130     SetupFlags;
131 tony 33 end;
132    
133     procedure TIBSQLEditorForm.GenerateBtnClick(Sender: TObject);
134     begin
135 tony 80 case TabControl1.TabIndex of
136     0:
137     IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked);
138     1:
139     IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked);
140     2:
141 tony 106 IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked,IncludePrimaryKeys.Checked);
142 tony 80 3:
143     IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked);
144     4:
145     IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked);
146 tony 33 end;
147     end;
148    
149 tony 80 procedure TIBSQLEditorForm.SetupFlags;
150 tony 33 begin
151 tony 80 IBSQLEditFrame1.IncludeReadOnlyFields := (TabControl1.TabIndex = 0);
152     IncludePrimaryKeys.Visible := TabControl1.TabIndex = 2;
153     FieldNamesGrid.Visible := TabControl1.TabIndex <> 3;
154     Label2.Visible := TabControl1.TabIndex <> 3;
155 tony 106 IdentityGrid.Visible := TabControl1.TabIndex <> 3;
156     Label6.Visible := TabControl1.TabIndex <> 3;
157     ReadOnlyGrid.Visible := TabControl1.TabIndex <> 3;
158     Label5.Visible := TabControl1.TabIndex <> 3;
159 tony 80 SelectSelectAll.Visible := TabControl1.TabIndex <> 3;
160 tony 33 end;
161    
162 tony 80 procedure TIBSQLEditorForm.SetSQLStatementType(aType: TIBSQLStatementTypes);
163 tony 33 begin
164 tony 80 inherited SetSQLStatementType(aType);
165     case aType of
166     SQLSelect:
167     TabControl1.TabIndex := 0;
168     SQLInsert:
169     TabControl1.TabIndex := 1;
170     SQLUpdate:
171     TabControl1.TabIndex := 2;
172     SQLDelete:
173     TabControl1.TabIndex := 3;
174 tony 33 else
175 tony 80 TabControl1.TabIndex := 4;
176 tony 33 end;
177     end;
178    
179 tony 80 end.
180 tony 33