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 |
|
|
IBLookupComboEditBox, IBDynamicGrid, IBDatabase, IBSQL, IBQuery, IB; |
37 |
tony |
33 |
|
38 |
|
|
type |
39 |
|
|
|
40 |
|
|
{ TIBSQLEditorForm } |
41 |
|
|
|
42 |
tony |
106 |
TIBSQLEditorForm = class(TIBInsertSQLEditorForm) |
43 |
tony |
33 |
IncludePrimaryKeys: TCheckBox; |
44 |
tony |
80 |
TabControl1: TTabControl; |
45 |
|
|
procedure FormShow(Sender: TObject); |
46 |
tony |
33 |
procedure GenerateBtnClick(Sender: TObject); |
47 |
tony |
80 |
procedure TabControl1Change(Sender: TObject); |
48 |
tony |
33 |
private |
49 |
tony |
80 |
procedure SetupFlags; |
50 |
tony |
37 |
protected |
51 |
tony |
80 |
procedure SetSQLStatementType(aType: TIBSQLStatementTypes); override; |
52 |
tony |
33 |
public |
53 |
tony |
80 |
|
54 |
tony |
33 |
end; |
55 |
|
|
|
56 |
tony |
80 |
function EditSQL(aIBSQL: TIBSQL): boolean; |
57 |
|
|
|
58 |
tony |
33 |
var |
59 |
|
|
IBSQLEditorForm: TIBSQLEditorForm; |
60 |
|
|
|
61 |
|
|
implementation |
62 |
|
|
|
63 |
|
|
{$R *.lfm} |
64 |
|
|
|
65 |
tony |
80 |
function EditSQL(aIBSQL: TIBSQL): boolean; |
66 |
tony |
33 |
begin |
67 |
|
|
Result := false; |
68 |
tony |
80 |
if assigned(aIBSQL) and assigned(aIBSQL.Database) then |
69 |
tony |
33 |
try |
70 |
tony |
80 |
aIBSQL.Database.Connected := true; |
71 |
tony |
33 |
except on E: Exception do |
72 |
|
|
ShowMessage(E.Message) |
73 |
|
|
end; |
74 |
|
|
|
75 |
|
|
with TIBSQLEditorForm.Create(Application) do |
76 |
|
|
try |
77 |
tony |
80 |
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 |
tony |
33 |
Result := ShowModal = mrOK; |
90 |
|
|
if Result then |
91 |
tony |
80 |
begin |
92 |
|
|
aIBSQL.SQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
93 |
|
|
if assigned(aIBSQL) then |
94 |
|
|
aIBSQL.GenerateParamNames := GenerateParams.Checked |
95 |
|
|
end; |
96 |
tony |
33 |
finally |
97 |
|
|
Free |
98 |
|
|
end; |
99 |
|
|
end; |
100 |
|
|
|
101 |
|
|
{ TIBSQLEditorForm } |
102 |
|
|
|
103 |
tony |
80 |
procedure TIBSQLEditorForm.TabControl1Change(Sender: TObject); |
104 |
tony |
33 |
begin |
105 |
tony |
80 |
case TabControl1.TabIndex of |
106 |
|
|
4: |
107 |
|
|
PageControl.ActivePage := ExecutePage; |
108 |
tony |
33 |
else |
109 |
tony |
80 |
PageControl.ActivePage := SelectPage; |
110 |
tony |
33 |
end; |
111 |
tony |
80 |
SetupFlags; |
112 |
tony |
33 |
end; |
113 |
|
|
|
114 |
tony |
80 |
procedure TIBSQLEditorForm.FormShow(Sender: TObject); |
115 |
tony |
33 |
begin |
116 |
tony |
80 |
inherited; |
117 |
|
|
SetupFlags; |
118 |
tony |
33 |
end; |
119 |
|
|
|
120 |
|
|
procedure TIBSQLEditorForm.GenerateBtnClick(Sender: TObject); |
121 |
|
|
begin |
122 |
tony |
80 |
case TabControl1.TabIndex of |
123 |
|
|
0: |
124 |
|
|
IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked); |
125 |
|
|
1: |
126 |
|
|
IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked); |
127 |
|
|
2: |
128 |
tony |
106 |
IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked,IncludePrimaryKeys.Checked); |
129 |
tony |
80 |
3: |
130 |
|
|
IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked); |
131 |
|
|
4: |
132 |
|
|
IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked); |
133 |
tony |
33 |
end; |
134 |
|
|
end; |
135 |
|
|
|
136 |
tony |
80 |
procedure TIBSQLEditorForm.SetupFlags; |
137 |
tony |
33 |
begin |
138 |
tony |
80 |
IBSQLEditFrame1.IncludeReadOnlyFields := (TabControl1.TabIndex = 0); |
139 |
|
|
IncludePrimaryKeys.Visible := TabControl1.TabIndex = 2; |
140 |
|
|
FieldNamesGrid.Visible := TabControl1.TabIndex <> 3; |
141 |
|
|
Label2.Visible := TabControl1.TabIndex <> 3; |
142 |
tony |
106 |
IdentityGrid.Visible := TabControl1.TabIndex <> 3; |
143 |
|
|
Label6.Visible := TabControl1.TabIndex <> 3; |
144 |
|
|
ReadOnlyGrid.Visible := TabControl1.TabIndex <> 3; |
145 |
|
|
Label5.Visible := TabControl1.TabIndex <> 3; |
146 |
tony |
80 |
SelectSelectAll.Visible := TabControl1.TabIndex <> 3; |
147 |
tony |
33 |
end; |
148 |
|
|
|
149 |
tony |
80 |
procedure TIBSQLEditorForm.SetSQLStatementType(aType: TIBSQLStatementTypes); |
150 |
tony |
33 |
begin |
151 |
tony |
80 |
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 |
tony |
33 |
else |
162 |
tony |
80 |
TabControl1.TabIndex := 4; |
163 |
tony |
33 |
end; |
164 |
|
|
end; |
165 |
|
|
|
166 |
tony |
80 |
end. |
167 |
tony |
33 |
|