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 IBDataSetEditor; |
28 |
|
|
29 |
|
{$mode objfpc}{$H+} |
31 |
|
interface |
32 |
|
|
33 |
|
uses |
34 |
< |
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, |
35 |
< |
ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBCustomDataSet; |
34 |
> |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, |
35 |
> |
ComCtrls, StdCtrls, ExtCtrls, IBSystemTables, IBCustomDataSet, IBDatabase; |
36 |
|
|
37 |
|
type |
38 |
|
|
39 |
|
{ TIBDataSetEditorForm } |
40 |
|
|
41 |
|
TIBDataSetEditorForm = class(TForm) |
42 |
< |
Button1: TButton; |
42 |
> |
TestBtn: TButton; |
43 |
|
CancelButton: TButton; |
44 |
|
FieldsPage: TTabSheet; |
45 |
|
GenerateButton: TButton; |
46 |
|
GroupBox1: TGroupBox; |
47 |
+ |
IBTransaction1: TIBTransaction; |
48 |
+ |
IncludePrimaryKeys: TCheckBox; |
49 |
|
PrimaryKeyList: TListBox; |
50 |
|
Label1: TLabel; |
51 |
|
Label2: TLabel; |
59 |
|
StatementType: TRadioGroup; |
60 |
|
FieldList: TListBox; |
61 |
|
TableNamesCombo: TComboBox; |
62 |
< |
procedure Button1Click(Sender: TObject); |
62 |
> |
procedure TestBtnClick(Sender: TObject); |
63 |
|
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); |
64 |
|
procedure FormShow(Sender: TObject); |
65 |
|
procedure GenerateButtonClick(Sender: TObject); |
93 |
|
|
94 |
|
implementation |
95 |
|
|
96 |
+ |
{$R *.lfm} |
97 |
+ |
|
98 |
|
function EditIBDataSet(DataSet: TIBDataSet): boolean; |
99 |
|
begin |
100 |
|
Result := false; |
101 |
|
if assigned(DataSet) and assigned(DataSet.Database) then |
102 |
< |
begin |
73 |
< |
if not assigned(DataSet.Transaction) then |
74 |
< |
begin |
75 |
< |
ShowMessage('No Default Transaction!'); |
76 |
< |
Exit |
77 |
< |
end; |
78 |
< |
|
102 |
> |
try |
103 |
|
DataSet.Database.Connected := true; |
104 |
+ |
except on E: Exception do |
105 |
+ |
ShowMessage(E.Message) |
106 |
|
end; |
107 |
|
|
108 |
|
with TIBDataSetEditorForm.Create(Application) do |
126 |
|
FDeleteSQL.Assign(FDataSet.DeleteSQL); |
127 |
|
FRefreshSQL.Assign(FDataSet.RefreshSQL); |
128 |
|
FSelectSQL.Assign(FDataSet.SelectSQL); |
129 |
+ |
GenerateButton.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
130 |
+ |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
131 |
|
FCurrentStatement := -1; |
132 |
|
TableNamesCombo.Items.Clear; |
133 |
|
FIBSystemTables.GetTableNames(TableNamesCombo.Items); |
139 |
|
FIBSystemTables.GetTableAndColumns(FSelectSQL.Text,TableName,nil); |
140 |
|
TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName); |
141 |
|
except end;//ignore |
142 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,false); |
142 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
143 |
|
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
144 |
|
end; |
145 |
|
end; |
158 |
|
end; |
159 |
|
end; |
160 |
|
|
161 |
< |
procedure TIBDataSetEditorForm.Button1Click(Sender: TObject); |
161 |
> |
procedure TIBDataSetEditorForm.TestBtnClick(Sender: TObject); |
162 |
|
begin |
163 |
|
if SQLMemo.Lines.Text <> '' then |
164 |
|
FIBSystemTables.TestSQL(SQLMemo.Lines.Text); |
168 |
|
var FieldNames: TStringList; |
169 |
|
I: integer; |
170 |
|
begin |
171 |
< |
FDataSet.RefreshSQL.Clear; |
172 |
< |
FIBSystemTables.GenerateSelectSQL(TableNamesCombo.Text,QuoteFields.Checked,FSelectSQL); |
173 |
< |
FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FRefreshSQL); |
174 |
< |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL); |
175 |
< |
if FieldList.SelCount = 0 then |
176 |
< |
begin |
177 |
< |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
178 |
< |
FieldList.Items,FModifySQL); |
171 |
> |
FieldNames := TStringList.Create; |
172 |
> |
try |
173 |
> |
FRefreshSQL.Clear; |
174 |
> |
FSelectSQL.Clear; |
175 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames); |
176 |
> |
FIBSystemTables.GenerateSelectSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FSelectSQL); |
177 |
> |
FIBSystemTables.GenerateRefreshSQL(TableNamesCombo.Text,QuoteFields.Checked,FieldNames,FRefreshSQL); |
178 |
> |
FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,FDeleteSQL); |
179 |
> |
FieldNames.Clear; |
180 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldNames,true,false); |
181 |
|
FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked, |
182 |
< |
FieldList.Items,FInsertSQL); |
182 |
> |
FieldNames,FInsertSQL); |
183 |
> |
if FieldList.SelCount = 0 then |
184 |
> |
begin |
185 |
> |
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
186 |
> |
FieldList.Items,FModifySQL); |
187 |
|
|
188 |
< |
end |
189 |
< |
else |
190 |
< |
begin |
191 |
< |
FieldNames := TStringList.Create; |
158 |
< |
try |
188 |
> |
end |
189 |
> |
else |
190 |
> |
begin |
191 |
> |
FieldNames.Clear; |
192 |
|
for I := 0 to FieldList.Items.Count - 1 do |
193 |
|
if FieldList.Selected[I] then |
194 |
|
FieldNames.Add(FieldList.Items[I]); |
195 |
|
FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked, |
196 |
|
FieldNames,FModifySQL); |
164 |
– |
FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked, |
165 |
– |
FieldNames,FInsertSQL); |
166 |
– |
finally |
167 |
– |
FieldNames.Free |
197 |
|
end; |
198 |
+ |
FDirty := false; |
199 |
+ |
PageControl.ActivePage := SQLPage; |
200 |
+ |
finally |
201 |
+ |
FieldNames.Free |
202 |
|
end; |
170 |
– |
FDirty := false; |
171 |
– |
PageControl.ActivePage := SQLPage; |
203 |
|
end; |
204 |
|
|
205 |
|
procedure TIBDataSetEditorForm.SQLMemoChange(Sender: TObject); |
219 |
|
|
220 |
|
procedure TIBDataSetEditorForm.TableNamesComboCloseUp(Sender: TObject); |
221 |
|
begin |
222 |
< |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,false); |
222 |
> |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false); |
223 |
|
FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items); |
224 |
|
end; |
225 |
|
|
279 |
|
procedure TIBDataSetEditorForm.SetDataSet(AObject: TIBDataSet); |
280 |
|
begin |
281 |
|
FDataSet := AObject; |
282 |
+ |
IBTransaction1.DefaultDatabase := FDataSet.Database; |
283 |
|
if assigned(FDataSet) then |
284 |
< |
FIBSystemTables.SelectDatabase(FDataSet.Database,FDataSet.Transaction); |
284 |
> |
FIBSystemTables.SelectDatabase(FDataSet.Database,IBTransaction1); |
285 |
|
end; |
286 |
|
|
255 |
– |
|
256 |
– |
initialization |
257 |
– |
{$I ibdataseteditor.lrs} |
258 |
– |
|
287 |
|
end. |
288 |
|
|