1 |
tony |
37 |
unit Unit1; |
2 |
|
|
|
3 |
|
|
{$mode objfpc}{$H+} |
4 |
|
|
|
5 |
|
|
interface |
6 |
|
|
|
7 |
|
|
uses |
8 |
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, |
9 |
|
|
ComCtrls, ActnList, ExtCtrls, ibxscript, IBDatabase, IBHeader; |
10 |
|
|
|
11 |
|
|
type |
12 |
|
|
|
13 |
|
|
{ TForm1 } |
14 |
|
|
|
15 |
|
|
TForm1 = class(TForm) |
16 |
|
|
EchoInput: TCheckBox; |
17 |
|
|
OpenBlobDialog: TOpenDialog; |
18 |
|
|
StopOnError: TCheckBox; |
19 |
|
|
RunScript: TAction; |
20 |
|
|
LoadScript: TAction; |
21 |
|
|
ActionList1: TActionList; |
22 |
|
|
Button1: TButton; |
23 |
|
|
Button2: TButton; |
24 |
|
|
IBDatabase1: TIBDatabase; |
25 |
|
|
IBTransaction1: TIBTransaction; |
26 |
|
|
IBXScript1: TIBXScript; |
27 |
|
|
Label1: TLabel; |
28 |
|
|
Label2: TLabel; |
29 |
|
|
IBScript: TMemo; |
30 |
|
|
Label3: TLabel; |
31 |
|
|
DBName: TLabel; |
32 |
|
|
OpenDialog1: TOpenDialog; |
33 |
|
|
ProgressBar1: TProgressBar; |
34 |
|
|
ResultsLog: TMemo; |
35 |
|
|
Timer1: TTimer; |
36 |
|
|
procedure EchoInputChange(Sender: TObject); |
37 |
|
|
procedure FormShow(Sender: TObject); |
38 |
|
|
procedure IBXScript1GetParamValue(Sender: TObject; ParamName: string; |
39 |
|
|
var BlobID: TISC_QUAD); |
40 |
|
|
procedure IBXScript1LogProc(Sender: TObject; Msg: string); |
41 |
|
|
procedure IBXScript1ProgressEvent(Sender: TObject; Reset: boolean; |
42 |
|
|
value: integer); |
43 |
|
|
procedure IBXScript1SelectSQL(Sender: TObject; SQLText: string); |
44 |
|
|
procedure LoadScriptExecute(Sender: TObject); |
45 |
|
|
procedure RunScriptExecute(Sender: TObject); |
46 |
|
|
procedure RunScriptUpdate(Sender: TObject); |
47 |
|
|
procedure StopOnErrorChange(Sender: TObject); |
48 |
|
|
procedure Timer1Timer(Sender: TObject); |
49 |
|
|
private |
50 |
|
|
{ private declarations } |
51 |
|
|
procedure DoOpen(Data: PtrInt); |
52 |
|
|
public |
53 |
|
|
{ public declarations } |
54 |
|
|
end; |
55 |
|
|
|
56 |
|
|
var |
57 |
|
|
Form1: TForm1; |
58 |
|
|
|
59 |
|
|
implementation |
60 |
|
|
|
61 |
|
|
uses IBBlob, DB, Unit2; |
62 |
|
|
|
63 |
|
|
{$R *.lfm} |
64 |
|
|
|
65 |
|
|
{ TForm1 } |
66 |
|
|
|
67 |
|
|
procedure TForm1.FormShow(Sender: TObject); |
68 |
|
|
begin |
69 |
|
|
ResultsLog.Lines.Clear; |
70 |
|
|
IBScript.Lines.Clear; |
71 |
|
|
DBName.Caption := IBDatabase1.DatabaseName; |
72 |
|
|
StopOnError.Checked := IBXScript1.StopOnFirstError; |
73 |
|
|
EchoInput.Checked := IBXScript1.Echo; |
74 |
|
|
Application.QueueAsyncCall(@DoOpen,0); |
75 |
|
|
end; |
76 |
|
|
|
77 |
|
|
procedure TForm1.EchoInputChange(Sender: TObject); |
78 |
|
|
begin |
79 |
|
|
IBXScript1.Echo := EchoInput.Checked; |
80 |
|
|
end; |
81 |
|
|
|
82 |
|
|
procedure TForm1.IBXScript1GetParamValue(Sender: TObject; ParamName: string; |
83 |
|
|
var BlobID: TISC_QUAD); |
84 |
|
|
var Blob: TIBBlobStream; |
85 |
|
|
Source: TStream; |
86 |
|
|
begin |
87 |
|
|
OpenBlobDialog.Title := 'Resolve Query Parameter: ''' + ParamName + ''''; |
88 |
|
|
if OpenBlobDialog.Execute then |
89 |
|
|
begin |
90 |
|
|
ResultsLog.Lines.Add('Loading ' + ParamName + ' from ' + OpenBlobDialog.FileName); |
91 |
|
|
Blob := TIBBlobStream.Create; |
92 |
|
|
try |
93 |
|
|
Blob.Database := (Sender as TIBXScript).Database; |
94 |
|
|
Blob.Mode := bmWrite; |
95 |
|
|
Source := TFileStream.Create(OpenBlobDialog.FileName,fmOpenRead or fmShareDenyNone); |
96 |
|
|
try |
97 |
|
|
Blob.CopyFrom(Source,0) |
98 |
|
|
finally |
99 |
|
|
Source.Free; |
100 |
|
|
end; |
101 |
|
|
Blob.Finalize; |
102 |
|
|
BlobID := Blob.BlobID; |
103 |
|
|
finally |
104 |
|
|
Blob.Free; |
105 |
|
|
end; |
106 |
|
|
end |
107 |
|
|
else |
108 |
|
|
raise Exception.Create('Unable to resolve statement parameter'); |
109 |
|
|
end; |
110 |
|
|
|
111 |
|
|
procedure TForm1.IBXScript1LogProc(Sender: TObject; Msg: string); |
112 |
|
|
begin |
113 |
|
|
ResultsLog.Lines.Add(Msg); |
114 |
|
|
end; |
115 |
|
|
|
116 |
|
|
procedure TForm1.IBXScript1ProgressEvent(Sender: TObject; Reset: boolean; |
117 |
|
|
value: integer); |
118 |
|
|
begin |
119 |
|
|
if Reset then |
120 |
|
|
begin |
121 |
|
|
ProgressBar1.Position := 0; |
122 |
|
|
ProgressBar1.Max := value; |
123 |
|
|
end |
124 |
|
|
else |
125 |
|
|
ProgressBar1.StepIt; |
126 |
|
|
end; |
127 |
|
|
|
128 |
|
|
procedure TForm1.IBXScript1SelectSQL(Sender: TObject; SQLText: string); |
129 |
|
|
begin |
130 |
|
|
with TSelectSQLResults.Create(Application) do |
131 |
|
|
Show(SQLText); |
132 |
|
|
end; |
133 |
|
|
|
134 |
|
|
procedure TForm1.LoadScriptExecute(Sender: TObject); |
135 |
|
|
begin |
136 |
|
|
if OpenDialog1.Execute then |
137 |
|
|
IBScript.Lines.LoadFromFile(OpenDialog1.FileName); |
138 |
|
|
end; |
139 |
|
|
|
140 |
|
|
procedure TForm1.RunScriptExecute(Sender: TObject); |
141 |
|
|
var S: TMemoryStream; |
142 |
|
|
begin |
143 |
|
|
ResultsLog.Lines.Clear; |
144 |
|
|
S := TMemoryStream.Create; |
145 |
|
|
try |
146 |
|
|
IBScript.Lines.SaveToStream(S); |
147 |
|
|
S.Position := 0; |
148 |
|
|
IBXScript1.PerformUpdate(S,true); |
149 |
|
|
finally |
150 |
|
|
S.Free; |
151 |
|
|
end; |
152 |
|
|
Timer1.Interval := 1000; |
153 |
|
|
end; |
154 |
|
|
|
155 |
|
|
procedure TForm1.RunScriptUpdate(Sender: TObject); |
156 |
|
|
begin |
157 |
|
|
(Sender as TAction).Enabled := IBScript.Lines.Text <> ''; |
158 |
|
|
end; |
159 |
|
|
|
160 |
|
|
procedure TForm1.StopOnErrorChange(Sender: TObject); |
161 |
|
|
begin |
162 |
|
|
IBXScript1.StopOnFirstError := StopOnError.Checked; |
163 |
|
|
end; |
164 |
|
|
|
165 |
|
|
procedure TForm1.Timer1Timer(Sender: TObject); |
166 |
|
|
begin |
167 |
|
|
Timer1.Interval := 0; |
168 |
|
|
ProgressBar1.Position := 0; |
169 |
|
|
end; |
170 |
|
|
|
171 |
|
|
procedure TForm1.DoOpen(Data: PtrInt); |
172 |
|
|
begin |
173 |
|
|
try |
174 |
|
|
IBDatabase1.Connected := true; |
175 |
|
|
except on E: Exception do |
176 |
|
|
begin |
177 |
|
|
MessageDlg(E.Message,mtError,[mbOK],0); |
178 |
|
|
Application.Terminate; |
179 |
|
|
end; |
180 |
|
|
end; |
181 |
|
|
end; |
182 |
|
|
|
183 |
|
|
end. |
184 |
|
|
|