23 |
|
* Contributor(s): ______________________________________. |
24 |
|
* |
25 |
|
*) |
26 |
– |
|
26 |
|
unit ibinsertsqleditor; |
27 |
|
|
28 |
|
{$mode objfpc}{$H+} |
30 |
|
interface |
31 |
|
|
32 |
|
uses |
33 |
< |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, |
34 |
< |
StdCtrls, IBSystemTables, IBDatabase; |
33 |
> |
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, |
34 |
> |
ibselectsqleditor, IBSQLEditFrame, IBDatabase, IBCustomDataset; |
35 |
|
|
36 |
|
type |
37 |
|
|
38 |
|
{ TIBInsertSQLEditorForm } |
39 |
|
|
40 |
< |
TIBInsertSQLEditorForm = class(TForm) |
42 |
< |
Button1: TButton; |
43 |
< |
Button2: TButton; |
44 |
< |
GenerateBtn: TButton; |
45 |
< |
TestBtn: TButton; |
46 |
< |
FieldList: TListBox; |
47 |
< |
IBTransaction1: TIBTransaction; |
48 |
< |
Label1: TLabel; |
49 |
< |
Label2: TLabel; |
50 |
< |
Label3: TLabel; |
51 |
< |
QuoteFields: TCheckBox; |
52 |
< |
SQLText: TMemo; |
53 |
< |
TableNamesCombo: TComboBox; |
40 |
> |
TIBInsertSQLEditorForm = class(TIBSelectSQLEditorForm) |
41 |
|
procedure GenerateBtnClick(Sender: TObject); |
55 |
– |
procedure TestBtnClick(Sender: TObject); |
56 |
– |
procedure FieldListDblClick(Sender: TObject); |
57 |
– |
procedure FormShow(Sender: TObject); |
58 |
– |
procedure TableNamesComboCloseUp(Sender: TObject); |
42 |
|
private |
43 |
< |
{ private declarations } |
61 |
< |
FIBSystemTables: TIBSystemTables; |
43 |
> |
|
44 |
|
public |
45 |
< |
{ public declarations } |
46 |
< |
constructor Create(TheOwner: TComponent); override; |
47 |
< |
destructor Destroy; override; |
48 |
< |
procedure SetDatabase(Database: TIBDatabase); |
67 |
< |
end; |
45 |
> |
|
46 |
> |
end; |
47 |
> |
|
48 |
> |
function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean; |
49 |
|
|
50 |
|
var |
51 |
|
IBInsertSQLEditorForm: TIBInsertSQLEditorForm; |
52 |
|
|
72 |
– |
function EditSQL(Database: TIBDatabase; SelectSQL: TStrings): boolean; |
73 |
– |
|
53 |
|
implementation |
54 |
|
|
55 |
|
{$R *.lfm} |
56 |
|
|
57 |
< |
function EditSQL(Database: TIBDatabase; SelectSQL: TStrings): boolean; |
57 |
> |
function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean; |
58 |
|
begin |
59 |
< |
Result := false; |
60 |
< |
|
82 |
< |
if assigned(Database) then |
59 |
> |
Result := false; |
60 |
> |
if assigned(DataSet) and assigned(DataSet.Database) then |
61 |
|
try |
62 |
< |
Database.Connected := true; |
62 |
> |
DataSet.Database.Connected := true; |
63 |
|
except on E: Exception do |
64 |
|
ShowMessage(E.Message) |
65 |
|
end; |
66 |
|
|
67 |
|
with TIBInsertSQLEditorForm.Create(Application) do |
68 |
|
try |
69 |
< |
SetDatabase(Database); |
70 |
< |
SQLText.Lines.Assign(SelectSQL); |
69 |
> |
if assigned(DataSet) then |
70 |
> |
begin |
71 |
> |
IBSQLEditFrame1.Database := DataSet.Database; |
72 |
> |
GenerateParams.Checked := DataSet.GenerateParamNames; |
73 |
> |
end; |
74 |
> |
with IBSQLEditFrame1 do |
75 |
> |
begin |
76 |
> |
IncludePrimaryKeys := true; |
77 |
> |
IncludeReadOnlyFields := false; |
78 |
> |
ExecuteOnlyProcs := true; |
79 |
> |
SQLText.Lines.Assign(SelectSQL); |
80 |
> |
end; |
81 |
|
Result := ShowModal = mrOK; |
82 |
|
if Result then |
83 |
< |
SelectSQL.Assign(SQLText.Lines) |
83 |
> |
begin |
84 |
> |
SelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines); |
85 |
> |
if assigned(DataSet) then |
86 |
> |
DataSet.GenerateParamNames := GenerateParams.Checked |
87 |
> |
end; |
88 |
|
finally |
89 |
|
Free |
90 |
|
end; |
92 |
|
|
93 |
|
{ TIBInsertSQLEditorForm } |
94 |
|
|
103 |
– |
procedure TIBInsertSQLEditorForm.FormShow(Sender: TObject); |
104 |
– |
var TableName: string; |
105 |
– |
begin |
106 |
– |
GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
107 |
– |
TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected; |
108 |
– |
TableNamesCombo.Items.Clear; |
109 |
– |
try |
110 |
– |
FIBSystemTables.GetTableNames(TableNamesCombo.Items); |
111 |
– |
if TableNamesCombo.Items.Count > 0 then |
112 |
– |
begin |
113 |
– |
TableNamesCombo.ItemIndex := 0; |
114 |
– |
if Trim(SQLText.Text) <> '' then |
115 |
– |
begin |
116 |
– |
FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil); |
117 |
– |
TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName) |
118 |
– |
end; |
119 |
– |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,true,false); |
120 |
– |
end; |
121 |
– |
except {ignore} |
122 |
– |
end; |
123 |
– |
end; |
124 |
– |
|
125 |
– |
procedure TIBInsertSQLEditorForm.FieldListDblClick(Sender: TObject); |
126 |
– |
begin |
127 |
– |
SQLText.SelText := FieldList.Items[FieldList.ItemIndex]; |
128 |
– |
SQLText.SetFocus |
129 |
– |
end; |
130 |
– |
|
95 |
|
procedure TIBInsertSQLEditorForm.GenerateBtnClick(Sender: TObject); |
132 |
– |
var FieldNames: TStrings; |
133 |
– |
begin |
134 |
– |
FieldNames := FIBSystemTables.GetFieldNames(FieldList); |
135 |
– |
try |
136 |
– |
FIBSystemTables.GenerateInsertSQL(TableNamesCombo.Text,QuoteFields.Checked, |
137 |
– |
FieldNames,SQLText.Lines) |
138 |
– |
finally |
139 |
– |
FieldNames.Free |
140 |
– |
end; |
141 |
– |
end; |
142 |
– |
|
143 |
– |
procedure TIBInsertSQLEditorForm.TestBtnClick(Sender: TObject); |
144 |
– |
begin |
145 |
– |
FIBSystemTables.TestSQL(SQLText.Lines.Text) |
146 |
– |
end; |
147 |
– |
|
148 |
– |
procedure TIBInsertSQLEditorForm.TableNamesComboCloseUp(Sender: TObject); |
149 |
– |
begin |
150 |
– |
FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,true,false); |
151 |
– |
end; |
152 |
– |
|
153 |
– |
constructor TIBInsertSQLEditorForm.Create(TheOwner: TComponent); |
96 |
|
begin |
97 |
< |
inherited Create(TheOwner); |
98 |
< |
FIBSystemTables := TIBSystemTables.Create; |
97 |
> |
if PageControl.ActivePage = ExecutePage then |
98 |
> |
IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked) |
99 |
> |
else |
100 |
> |
IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked); |
101 |
|
end; |
102 |
|
|
159 |
– |
destructor TIBInsertSQLEditorForm.Destroy; |
160 |
– |
begin |
161 |
– |
if assigned(FIBSystemTables) then FIBSystemTables.Free; |
162 |
– |
inherited Destroy; |
163 |
– |
end; |
164 |
– |
|
165 |
– |
procedure TIBInsertSQLEditorForm.SetDatabase(Database: TIBDatabase); |
166 |
– |
begin |
167 |
– |
IBTransaction1.DefaultDatabase := Database; |
168 |
– |
FIBSystemTables.SelectDatabase(Database,IBTransaction1) |
169 |
– |
end; |
103 |
|
|
104 |
|
end. |
105 |
|
|