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, LResources, Forms, Controls, Graphics, Dialogs, |
35 |
StdCtrls, ComCtrls, ibselectsqleditor, IBSQLEditFrame, IBLookupComboEditBox, |
36 |
IBDynamicGrid, IBDatabase, IBSQL, IB; |
37 |
|
38 |
type |
39 |
|
40 |
{ TIBSQLEditorForm } |
41 |
|
42 |
TIBSQLEditorForm = class(TIBSelectSQLEditorForm) |
43 |
IncludePrimaryKeys: TCheckBox; |
44 |
TabControl1: TTabControl; |
45 |
procedure FormShow(Sender: TObject); |
46 |
procedure GenerateBtnClick(Sender: TObject); |
47 |
procedure IncludePrimaryKeysChange(Sender: TObject); |
48 |
procedure TabControl1Change(Sender: TObject); |
49 |
private |
50 |
procedure SetupFlags; |
51 |
protected |
52 |
procedure SetSQLStatementType(aType: TIBSQLStatementTypes); override; |
53 |
public |
54 |
|
55 |
end; |
56 |
|
57 |
function EditSQL(aIBSQL: TIBSQL): boolean; |
58 |
|
59 |
var |
60 |
IBSQLEditorForm: TIBSQLEditorForm; |
61 |
|
62 |
implementation |
63 |
|
64 |
{$R *.lfm} |
65 |
|
66 |
function EditSQL(aIBSQL: TIBSQL): boolean; |
67 |
begin |
68 |
Result := false; |
69 |
if assigned(aIBSQL) and assigned(aIBSQL.Database) then |
70 |
try |
71 |
aIBSQL.Database.Connected := true; |
72 |
except on E: Exception do |
73 |
ShowMessage(E.Message) |
74 |
end; |
75 |
|
76 |
with TIBSQLEditorForm.Create(Application) do |
77 |
try |
78 |
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 |
Result := ShowModal = mrOK; |
92 |
if Result then |
93 |
begin |
94 |
aIBSQL.SQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
95 |
if assigned(aIBSQL) then |
96 |
aIBSQL.GenerateParamNames := GenerateParams.Checked |
97 |
end; |
98 |
finally |
99 |
Free |
100 |
end; |
101 |
end; |
102 |
|
103 |
{ TIBSQLEditorForm } |
104 |
|
105 |
procedure TIBSQLEditorForm.TabControl1Change(Sender: TObject); |
106 |
begin |
107 |
case TabControl1.TabIndex of |
108 |
4: |
109 |
PageControl.ActivePage := ExecutePage; |
110 |
else |
111 |
PageControl.ActivePage := SelectPage; |
112 |
end; |
113 |
SetupFlags; |
114 |
end; |
115 |
|
116 |
procedure TIBSQLEditorForm.FormShow(Sender: TObject); |
117 |
begin |
118 |
inherited; |
119 |
SetupFlags; |
120 |
end; |
121 |
|
122 |
procedure TIBSQLEditorForm.GenerateBtnClick(Sender: TObject); |
123 |
begin |
124 |
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 |
end; |
136 |
end; |
137 |
|
138 |
procedure TIBSQLEditorForm.IncludePrimaryKeysChange(Sender: TObject); |
139 |
begin |
140 |
IBSQLEditFrame1.IncludePrimaryKeys := IncludePrimaryKeys.Checked; |
141 |
end; |
142 |
|
143 |
procedure TIBSQLEditorForm.SetupFlags; |
144 |
begin |
145 |
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 |
end; |
154 |
|
155 |
procedure TIBSQLEditorForm.SetSQLStatementType(aType: TIBSQLStatementTypes); |
156 |
begin |
157 |
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 |
else |
168 |
TabControl1.TabIndex := 4; |
169 |
end; |
170 |
end; |
171 |
|
172 |
end. |
173 |
|