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