ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/design/ibsqleditor.pas
Revision: 142
Committed: Thu Jan 25 16:48:38 2018 UTC (6 years, 10 months ago) by tony
Content type: text/x-pascal
Original Path: ibx/trunk/design/ibsqleditor.pas
File size: 4719 byte(s)
Log Message:
Fixes Merged

File Contents

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