ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/design/ibsqleditor.pas
Revision: 209
Committed: Wed Mar 14 12:48:51 2018 UTC (6 years, 9 months ago) by tony
Content type: text/x-pascal
Original Path: ibx/trunk/design/ibsqleditor.pas
File size: 4666 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 209 IBDatabase, IBSQL, IB, 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 tony 142 IncludeReadOnlyFields := false;
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 tony 142 IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked,true);
138 tony 80 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 IncludePrimaryKeys.Visible := TabControl1.TabIndex = 2;
152     FieldNamesGrid.Visible := TabControl1.TabIndex <> 3;
153     Label2.Visible := TabControl1.TabIndex <> 3;
154 tony 106 IdentityGrid.Visible := TabControl1.TabIndex <> 3;
155     Label6.Visible := TabControl1.TabIndex <> 3;
156     ReadOnlyGrid.Visible := TabControl1.TabIndex <> 3;
157     Label5.Visible := TabControl1.TabIndex <> 3;
158 tony 80 SelectSelectAll.Visible := TabControl1.TabIndex <> 3;
159 tony 33 end;
160    
161 tony 80 procedure TIBSQLEditorForm.SetSQLStatementType(aType: TIBSQLStatementTypes);
162 tony 33 begin
163 tony 80 inherited SetSQLStatementType(aType);
164     case aType of
165     SQLSelect:
166     TabControl1.TabIndex := 0;
167     SQLInsert:
168     TabControl1.TabIndex := 1;
169     SQLUpdate:
170     TabControl1.TabIndex := 2;
171     SQLDelete:
172     TabControl1.TabIndex := 3;
173 tony 33 else
174 tony 80 TabControl1.TabIndex := 4;
175 tony 33 end;
176     end;
177    
178 tony 80 end.
179 tony 33