1 |
< |
unit IBUpdateSQLEditor; |
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 |
> |
unit IBUpdateSQLEditor; |
27 |
|
|
28 |
|
{$mode objfpc}{$H+} |
29 |
|
|
30 |
|
interface |
31 |
|
|
32 |
|
uses |
33 |
< |
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, |
34 |
< |
ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBUpdateSQL; |
33 |
> |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, |
34 |
> |
ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBUpdateSQL, IBDatabase; |
35 |
|
|
36 |
|
type |
37 |
|
|
38 |
|
{ TIBUpdateSQLEditorForm } |
39 |
|
|
40 |
|
TIBUpdateSQLEditorForm = class(TForm) |
41 |
< |
Button1: TButton; |
41 |
> |
TestBtn: TButton; |
42 |
|
CancelButton: TButton; |
43 |
|
FieldsPage: TTabSheet; |
44 |
< |
GenerateButton: TButton; |
44 |
> |
GenerateBtn: TButton; |
45 |
|
GroupBox1: TGroupBox; |
46 |
+ |
IBTransaction1: TIBTransaction; |
47 |
+ |
IncludePrimaryKeys: TCheckBox; |
48 |
|
PrimaryKeyList: TListBox; |
49 |
|
Label1: TLabel; |
50 |
|
Label2: TLabel; |
58 |
|
StatementType: TRadioGroup; |
59 |
|
FieldList: TListBox; |
60 |
|
TableNamesCombo: TComboBox; |
61 |
< |
procedure Button1Click(Sender: TObject); |
61 |
> |
procedure TestBtnClick(Sender: TObject); |
62 |
|
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); |
63 |
|
procedure FormShow(Sender: TObject); |
64 |
< |
procedure GenerateButtonClick(Sender: TObject); |
64 |
> |
procedure GenerateBtnClick(Sender: TObject); |
65 |
|
procedure SQLMemoChange(Sender: TObject); |
66 |
|
procedure SQLPageShow(Sender: TObject); |
67 |
|
procedure StatementTypeClick(Sender: TObject); |
93 |
|
|
94 |
|
uses IBQuery; |
95 |
|
|
96 |
+ |
{$R *.lfm} |
97 |
+ |
|
98 |
|
function EditIBUpdateSQL(UpdateObject: TIBUpdateSQL): boolean; |
99 |
|
begin |
100 |
|
Result := false; |
101 |
|
if assigned(UpdateObject.DataSet) and assigned(UpdateObject.DataSet.Database) then |
102 |
< |
begin |
103 |
< |
if not assigned(UpdateObject.DataSet.Transaction) then |
104 |
< |
begin |
105 |
< |
ShowMessage('No Default Transaction!'); |
77 |
< |
Exit |
102 |
> |
try |
103 |
> |
UpdateObject.DataSet.Database.Connected := true; |
104 |
> |
except on E: Exception do |
105 |
> |
ShowMessage(E.Message) |
106 |
|
end; |
107 |
|
|
80 |
– |
UpdateObject.DataSet.Database.Connected := true; |
81 |
– |
end; |
82 |
– |
|
108 |
|
with TIBUpdateSQLEditorForm.Create(Application) do |
109 |
|
try |
110 |
|
SetUpdateObject(UpdateObject); |
120 |
|
procedure TIBUpdateSQLEditorForm.FormShow(Sender: TObject); |
121 |
|
var TableName: string; |
122 |
|
begin |
123 |
+ |
GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
124 |
+ |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
125 |
|
PageControl.ActivePage := FieldsPage; |
126 |
|
FModifySQL.Assign(FUpdateObject.ModifySQL); |
127 |
|
FInsertSQL.Assign(FUpdateObject.InsertSQL); |
140 |
|
TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName); |
141 |
|
except //ignore |
142 |
|
end; |
143 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,false); |
143 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
144 |
|
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
145 |
|
end; |
146 |
|
end; |
158 |
|
end; |
159 |
|
end; |
160 |
|
|
161 |
< |
procedure TIBUpdateSQLEditorForm.Button1Click(Sender: TObject); |
161 |
> |
procedure TIBUpdateSQLEditorForm.TestBtnClick(Sender: TObject); |
162 |
|
begin |
163 |
|
if SQLMemo.Lines.Text <> '' then |
164 |
|
FIBSystemTables.TestSQL(SQLMemo.Lines.Text); |
165 |
|
end; |
166 |
|
|
167 |
< |
procedure TIBUpdateSQLEditorForm.GenerateButtonClick(Sender: TObject); |
167 |
> |
procedure TIBUpdateSQLEditorForm.GenerateBtnClick(Sender: TObject); |
168 |
|
var FieldNames: TStringList; |
169 |
|
I: integer; |
170 |
|
begin |
171 |
< |
FUpdateObject.RefreshSQL.Clear; |
172 |
< |
FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FRefreshSQL); |
173 |
< |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL); |
174 |
< |
if FieldList.SelCount = 0 then |
175 |
< |
begin |
176 |
< |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
177 |
< |
FieldList.Items,FModifySQL); |
171 |
> |
FieldNames := TStringList.Create; |
172 |
> |
try |
173 |
> |
FUpdateObject.RefreshSQL.Clear; |
174 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames); |
175 |
> |
FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FRefreshSQL); |
176 |
> |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL); |
177 |
> |
FieldNames.Clear; |
178 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames,true,false); |
179 |
|
FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked, |
180 |
< |
FieldList.Items,FInsertSQL); |
180 |
> |
FieldNames,FInsertSQL); |
181 |
> |
if FieldList.SelCount = 0 then |
182 |
> |
begin |
183 |
> |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
184 |
> |
FieldList.Items,FModifySQL); |
185 |
|
|
186 |
< |
end |
187 |
< |
else |
188 |
< |
begin |
189 |
< |
FieldNames := TStringList.Create; |
158 |
< |
try |
186 |
> |
end |
187 |
> |
else |
188 |
> |
begin |
189 |
> |
FieldNames.Clear; |
190 |
|
for I := 0 to FieldList.Items.Count - 1 do |
191 |
< |
if FieldList.Selected[I] then |
192 |
< |
FieldNames.Add(FieldList.Items[I]); |
191 |
> |
if FieldList.Selected[I] then |
192 |
> |
FieldNames.Add(FieldList.Items[I]); |
193 |
|
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
194 |
< |
FieldNames,FModifySQL); |
164 |
< |
FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked, |
165 |
< |
FieldNames,FInsertSQL); |
166 |
< |
finally |
167 |
< |
FieldNames.Free |
194 |
> |
FieldNames,FModifySQL); |
195 |
|
end; |
196 |
+ |
FDirty := false; |
197 |
+ |
PageControl.ActivePage := SQLPage; |
198 |
+ |
finally |
199 |
+ |
FieldNames.Free |
200 |
|
end; |
170 |
– |
FDirty := false; |
171 |
– |
PageControl.ActivePage := SQLPage; |
201 |
|
end; |
202 |
|
|
203 |
|
procedure TIBUpdateSQLEditorForm.SQLMemoChange(Sender: TObject); |
217 |
|
|
218 |
|
procedure TIBUpdateSQLEditorForm.TableNamesComboCloseUp(Sender: TObject); |
219 |
|
begin |
220 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,false); |
220 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
221 |
|
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
222 |
|
end; |
223 |
|
|
272 |
|
begin |
273 |
|
FUpdateObject := AObject; |
274 |
|
if assigned(FUpdateObject.DataSet) then |
275 |
< |
FIBSystemTables.SelectDatabase(FUpdateObject.DataSet.Database,FUpdateObject.DataSet.Transaction); |
275 |
> |
begin |
276 |
> |
IBTransaction1.DefaultDatabase := FUpdateObject.DataSet.Database; |
277 |
> |
FIBSystemTables.SelectDatabase(FUpdateObject.DataSet.Database,IBTransaction1); |
278 |
> |
end; |
279 |
|
end; |
280 |
|
|
281 |
|
|
250 |
– |
initialization |
251 |
– |
{$I ibupdatesqleditor.lrs} |
252 |
– |
|
282 |
|
end. |
283 |
|
|