1 |
(* |
2 |
* Firebird Interface (fbintf) Test suite. This program is used to |
3 |
* test the Firebird Pascal Interface and provide a semi-automated |
4 |
* pass/fail check for each test. |
5 |
* |
6 |
* The contents of this file are subject to the Initial Developer's |
7 |
* Public License Version 1.0 (the "License"); you may not use this |
8 |
* file except in compliance with the License. You may obtain a copy |
9 |
* of the License here: |
10 |
* |
11 |
* http://www.firebirdsql.org/index.php?op=doc&id=idpl |
12 |
* |
13 |
* Software distributed under the License is distributed on an "AS |
14 |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
15 |
* implied. See the License for the specific language governing rights |
16 |
* and limitations under the License. |
17 |
* |
18 |
* The Initial Developer of the Original Code is Tony Whyman. |
19 |
* |
20 |
* The Original Code is (C) 2016 Tony Whyman, MWA Software |
21 |
* (http://www.mwasoftware.co.uk). |
22 |
* |
23 |
* All Rights Reserved. |
24 |
* |
25 |
* Contributor(s): ______________________________________. |
26 |
* |
27 |
*) |
28 |
|
29 |
unit Test19; |
30 |
|
31 |
{$IFDEF MSWINDOWS} |
32 |
{$DEFINE WINDOWS} |
33 |
{$ENDIF} |
34 |
|
35 |
{$IFDEF FPC} |
36 |
{$mode delphi} |
37 |
{$codepage utf8} |
38 |
{$ENDIF} |
39 |
|
40 |
{Test 19: Batch Update and Insert Queries} |
41 |
|
42 |
{ This test opens the employee example databases with the supplied user name/password |
43 |
and runs several queries: |
44 |
|
45 |
1. Update two employee records in a single operation and report affected rows. |
46 |
|
47 |
2. Show Changed Records |
48 |
|
49 |
3. Repeat update above but add a dummy row and ignore on execute. |
50 |
|
51 |
4. Insert new employee records and report affected rows. |
52 |
|
53 |
5. Show inserted records and total records |
54 |
|
55 |
6. Repeat above insert but add a dumn row and ignore on execute |
56 |
|
57 |
7. Insert with inline blob |
58 |
|
59 |
8. Insert with explicit blob |
60 |
|
61 |
9. Implicit Rollback and disconnect. |
62 |
|
63 |
} |
64 |
|
65 |
interface |
66 |
|
67 |
uses |
68 |
Classes, SysUtils, TestApplication, FBTestApp, IB; |
69 |
|
70 |
type |
71 |
|
72 |
{ TTest19 } |
73 |
|
74 |
TTest19 = class(TFBTestBase) |
75 |
private |
76 |
procedure DoQuery(Attachment: IAttachment); |
77 |
procedure WriteBatchCompletion(bc: IBatchCompletion); |
78 |
procedure ErrorHandlingTests(Attachment: IAttachment); |
79 |
public |
80 |
function TestTitle: AnsiString; override; |
81 |
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
82 |
end; |
83 |
|
84 |
|
85 |
implementation |
86 |
|
87 |
{ TTest19 } |
88 |
|
89 |
procedure TTest19.DoQuery(Attachment: IAttachment); |
90 |
var Transaction: ITransaction; |
91 |
Statement: IStatement; |
92 |
ar: IArray; |
93 |
BC: IBatchCompletion; |
94 |
begin |
95 |
Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taRollback); |
96 |
Statement := Attachment.Prepare(Transaction,'Select * from EMPLOYEE Where EMP_NO in (8,2)',3); |
97 |
writeln(Outfile,'Rows before update'); |
98 |
ReportResults(Statement); |
99 |
Statement := Attachment.Prepare(Transaction,'Update Employee Set HIRE_DATE = ? Where EMP_NO = ?',3); |
100 |
Statement.GetSQLParams[0].AsDateTime := EncodeDate(2016,1,31);; |
101 |
Statement.GetSQLParams[1].AsInteger := 8; |
102 |
Statement.AddToBatch; |
103 |
Statement.GetSQLParams[0].AsDateTime := EncodeDate(2018,5,28);; |
104 |
Statement.GetSQLParams[1].AsInteger := 2; |
105 |
Statement.AddToBatch; |
106 |
BC := Statement.ExecuteBatch; |
107 |
WriteAffectedRows(Statement); |
108 |
WriteBatchCompletion(BC); |
109 |
Statement := Attachment.Prepare(Transaction,'Select * from EMPLOYEE Where EMP_NO in (8,2)',3); |
110 |
writeln(Outfile,'Rows after update'); |
111 |
ReportResults(Statement); |
112 |
Transaction.Rollback; |
113 |
Transaction.Start(taRollback); |
114 |
|
115 |
writeln(Outfile); |
116 |
writeln(Outfile,'Repeat but with a last dummy row that is ignored'); |
117 |
Statement := Attachment.Prepare(Transaction,'Update Employee Set HIRE_DATE = ? Where EMP_NO = ?',3); |
118 |
Statement.GetSQLParams[0].AsDateTime := EncodeDate(2016,1,31);; |
119 |
Statement.GetSQLParams[1].AsInteger := 8; |
120 |
Statement.AddToBatch; |
121 |
Statement.GetSQLParams[0].AsDateTime := EncodeDate(2018,5,28);; |
122 |
Statement.GetSQLParams[1].AsInteger := 2; |
123 |
Statement.AddToBatch; |
124 |
Statement.GetSQLParams[0].AsDateTime := EncodeDate(2019,5,28);; |
125 |
Statement.GetSQLParams[1].AsInteger := 2; |
126 |
BC := Statement.ExecuteBatch; |
127 |
WriteAffectedRows(Statement); |
128 |
WriteBatchCompletion(BC); |
129 |
Statement := Attachment.Prepare(Transaction,'Select * from EMPLOYEE Where EMP_NO in (8,2)',3); |
130 |
writeln(Outfile,'Rows after update'); |
131 |
ReportResults(Statement); |
132 |
Transaction.Rollback; |
133 |
Transaction.Start(taRollback); |
134 |
|
135 |
writeln(Outfile); |
136 |
writeln(Outfile,'Insert rows'); |
137 |
Statement := Attachment.PrepareWithNamedParameters(Transaction,'INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE,' + |
138 |
'DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) '+ |
139 |
'VALUES (:EMP_NO, :FIRST_NAME, :LAST_NAME, :PHONE_EXT, :HIRE_DATE,' + |
140 |
':DEPT_NO, :JOB_CODE, :JOB_GRADE, :JOB_COUNTRY, :SALARY)',3); |
141 |
with Statement.GetSQLParams do |
142 |
begin |
143 |
ByName('EMP_NO').AsInteger := 150; |
144 |
ByName('FIRST_NAME').AsString := 'John'; |
145 |
ByName('LAST_NAME').AsString := 'Doe'; |
146 |
ByName('PHONE_EXT').AsString := ''; |
147 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,1); |
148 |
ByName('DEPT_NO').AsString := '600'; |
149 |
ByName('JOB_CODE').AsString := 'Eng'; |
150 |
ByName('JOB_GRADE').AsInteger := 4; |
151 |
ByName('JOB_COUNTRY').AsString := 'England'; |
152 |
ByName('SALARY').AsFloat := 41000.89; |
153 |
end; |
154 |
Statement.AddToBatch; |
155 |
with Statement.GetSQLParams do |
156 |
begin |
157 |
ByName('EMP_NO').AsInteger := 151; |
158 |
ByName('FIRST_NAME').AsString := 'Jane'; |
159 |
ByName('LAST_NAME').AsString := 'Doe'; |
160 |
ByName('PHONE_EXT').AsString := ''; |
161 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,2); |
162 |
ByName('DEPT_NO').AsString := '600'; |
163 |
ByName('JOB_CODE').AsString := 'Eng'; |
164 |
ByName('JOB_GRADE').AsInteger := 4; |
165 |
ByName('JOB_COUNTRY').AsString := 'England'; |
166 |
ByName('SALARY').AsFloat := 42000.89; |
167 |
end; |
168 |
Statement.AddToBatch; |
169 |
with Statement.GetSQLParams do |
170 |
begin |
171 |
ByName('EMP_NO').AsInteger := 152; |
172 |
ByName('FIRST_NAME').AsString := 'John'; |
173 |
ByName('LAST_NAME').AsString := 'SmithAndJonesFamily1'; //Longest Name |
174 |
ByName('PHONE_EXT').AsString := ''; |
175 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,3); |
176 |
ByName('DEPT_NO').AsString := '600'; |
177 |
ByName('JOB_CODE').AsString := 'Eng'; |
178 |
ByName('JOB_GRADE').AsInteger := 4; |
179 |
ByName('JOB_COUNTRY').AsString := 'England'; |
180 |
ByName('SALARY').AsFloat := 41000.99; |
181 |
end; |
182 |
Statement.AddToBatch; |
183 |
BC := Statement.ExecuteBatch; |
184 |
WriteAffectedRows(Statement); |
185 |
WriteBatchCompletion(BC); |
186 |
Statement := Attachment.Prepare(Transaction,'Select * from EMPLOYEE Where EMP_NO >= 150',3); |
187 |
writeln(Outfile,'Rows after insert'); |
188 |
ReportResults(Statement); |
189 |
Transaction.Rollback; |
190 |
Transaction.Start(taRollback); |
191 |
writeln(Outfile); |
192 |
writeln(Outfile,'Insert rows - and then cancel'); |
193 |
Statement := Attachment.PrepareWithNamedParameters(Transaction,'INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE,' + |
194 |
'DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) '+ |
195 |
'VALUES (:EMP_NO, :FIRST_NAME, :LAST_NAME, :PHONE_EXT, :HIRE_DATE,' + |
196 |
':DEPT_NO, :JOB_CODE, :JOB_GRADE, :JOB_COUNTRY, :SALARY)',3); |
197 |
with Statement.GetSQLParams do |
198 |
begin |
199 |
ByName('EMP_NO').AsInteger := 150; |
200 |
ByName('FIRST_NAME').AsString := 'John'; |
201 |
ByName('LAST_NAME').AsString := 'Doe'; |
202 |
ByName('PHONE_EXT').AsString := ''; |
203 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,1); |
204 |
ByName('DEPT_NO').AsString := '600'; |
205 |
ByName('JOB_CODE').AsString := 'Eng'; |
206 |
ByName('JOB_GRADE').AsInteger := 4; |
207 |
ByName('JOB_COUNTRY').AsString := 'England'; |
208 |
ByName('SALARY').AsFloat := 41000.89; |
209 |
end; |
210 |
Statement.AddToBatch; |
211 |
with Statement.GetSQLParams do |
212 |
begin |
213 |
ByName('EMP_NO').AsInteger := 151; |
214 |
ByName('FIRST_NAME').AsString := 'Jane'; |
215 |
ByName('LAST_NAME').AsString := 'Doe'; |
216 |
ByName('PHONE_EXT').AsString := ''; |
217 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,2); |
218 |
ByName('DEPT_NO').AsString := '600'; |
219 |
ByName('JOB_CODE').AsString := 'Eng'; |
220 |
ByName('JOB_GRADE').AsInteger := 4; |
221 |
ByName('JOB_COUNTRY').AsString := 'England'; |
222 |
ByName('SALARY').AsFloat := 42000.89; |
223 |
end; |
224 |
Statement.AddToBatch; |
225 |
writeln(Outfile,'Cancel Batch - note - next step will fail with a duplicate key if cancel fails'); |
226 |
Statement.CancelBatch; |
227 |
writeln(Outfile); |
228 |
writeln(Outfile,'Insert rows - ignore last row'); |
229 |
Statement := Attachment.PrepareWithNamedParameters(Transaction,'INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE,' + |
230 |
'DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) '+ |
231 |
'VALUES (:EMP_NO, :FIRST_NAME, :LAST_NAME, :PHONE_EXT, :HIRE_DATE,' + |
232 |
':DEPT_NO, :JOB_CODE, :JOB_GRADE, :JOB_COUNTRY, :SALARY)',3); |
233 |
with Statement.GetSQLParams do |
234 |
begin |
235 |
ByName('EMP_NO').AsInteger := 150; |
236 |
ByName('FIRST_NAME').AsString := 'John'; |
237 |
ByName('LAST_NAME').AsString := 'Doe'; |
238 |
ByName('PHONE_EXT').AsString := ''; |
239 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,1); |
240 |
ByName('DEPT_NO').AsString := '600'; |
241 |
ByName('JOB_CODE').AsString := 'Eng'; |
242 |
ByName('JOB_GRADE').AsInteger := 4; |
243 |
ByName('JOB_COUNTRY').AsString := 'England'; |
244 |
ByName('SALARY').AsFloat := 41000.89; |
245 |
end; |
246 |
Statement.AddToBatch; |
247 |
with Statement.GetSQLParams do |
248 |
begin |
249 |
ByName('EMP_NO').AsInteger := 151; |
250 |
ByName('FIRST_NAME').AsString := 'Jane'; |
251 |
ByName('LAST_NAME').AsString := 'Doe'; |
252 |
ByName('PHONE_EXT').AsString := ''; |
253 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,2); |
254 |
ByName('DEPT_NO').AsString := '600'; |
255 |
ByName('JOB_CODE').AsString := 'Eng'; |
256 |
ByName('JOB_GRADE').AsInteger := 4; |
257 |
ByName('JOB_COUNTRY').AsString := 'England'; |
258 |
ByName('SALARY').AsFloat := 42000.89; |
259 |
end; |
260 |
Statement.AddToBatch; |
261 |
with Statement.GetSQLParams do |
262 |
begin |
263 |
ByName('EMP_NO').AsInteger := 152; |
264 |
ByName('FIRST_NAME').AsString := 'John'; |
265 |
ByName('LAST_NAME').AsString := 'SmithAndJonesFamily1'; //Longest Name |
266 |
ByName('PHONE_EXT').AsString := ''; |
267 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,3); |
268 |
ByName('DEPT_NO').AsString := '600'; |
269 |
ByName('JOB_CODE').AsString := 'Eng'; |
270 |
ByName('JOB_GRADE').AsInteger := 4; |
271 |
ByName('JOB_COUNTRY').AsString := 'England'; |
272 |
ByName('SALARY').AsFloat := 41000.99; |
273 |
end; |
274 |
BC := Statement.ExecuteBatch; |
275 |
WriteAffectedRows(Statement); |
276 |
WriteBatchCompletion(BC); |
277 |
Statement := Attachment.Prepare(Transaction,'Select * from EMPLOYEE Where EMP_NO >= 150',3); |
278 |
writeln(Outfile,'Rows after insert'); |
279 |
ReportResults(Statement); |
280 |
Transaction.Rollback; |
281 |
Transaction.Start(taRollback); |
282 |
|
283 |
writeln(Outfile,'Insert with inline blob'); |
284 |
Statement := Attachment.Prepare(Transaction, |
285 |
'INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY,' + |
286 |
'MAX_SALARY, JOB_REQUIREMENT, LANGUAGE_REQ) Values(?,?,?,?,?,?,?,?)'); |
287 |
with Statement.GetSQLParams do |
288 |
begin |
289 |
Params[0].AsString := 'ABC'; |
290 |
Params[1].AsInteger := 3; |
291 |
Params[2].AsString := 'England'; |
292 |
Params[3].AsString := 'Chief Tester'; |
293 |
Params[4].AsFloat := 21000; |
294 |
Params[5].AsString := '24000.99'; |
295 |
Params[6].AsString := 'The quick brown fox jumped over the lazy dog'; |
296 |
ar := Attachment.CreateArray(Transaction,'JOB','LANGUAGE_REQ'); |
297 |
ar.SetAsString([1],'Eng'); |
298 |
Params[7].AsArray := ar; |
299 |
end; |
300 |
Statement.AddToBatch; |
301 |
with Statement.GetSQLParams do |
302 |
begin |
303 |
Params[0].AsString := 'DEF'; |
304 |
Params[1].AsInteger := 3; |
305 |
Params[2].AsString := 'England'; |
306 |
Params[3].AsString := 'Deputy Tester'; |
307 |
Params[4].AsFloat := 21000; |
308 |
Params[5].AsString := '24000.99'; |
309 |
Params[6].AsString := 'The quick brown fox jumped over the running dog'; |
310 |
ar := Attachment.CreateArray(Transaction,'JOB','LANGUAGE_REQ'); |
311 |
ar.SetAsString([1],'Eng'); |
312 |
ar.SetAsString([2],'Fra'); |
313 |
Params[7].AsArray := ar; |
314 |
end; |
315 |
Statement.AddToBatch; |
316 |
BC := Statement.ExecuteBatch; |
317 |
WriteAffectedRows(Statement); |
318 |
WriteBatchCompletion(BC); |
319 |
Statement := Attachment.Prepare(Transaction,'Select * from JOB Where JOB_CODE in (''ABC'',''DEF'')',3); |
320 |
writeln(Outfile,'Rows after insert'); |
321 |
ReportResults(Statement); |
322 |
Transaction.Rollback; |
323 |
Transaction.Start(taRollback); |
324 |
writeln(Outfile); |
325 |
writeln(Outfile,'Insert with explicit blob'); |
326 |
Statement := Attachment.Prepare(Transaction, |
327 |
'INSERT INTO JOB (JOB_CODE, JOB_GRADE, JOB_COUNTRY, JOB_TITLE, MIN_SALARY,' + |
328 |
'MAX_SALARY, JOB_REQUIREMENT, LANGUAGE_REQ) Values(?,?,?,?,?,?,?,?)'); |
329 |
with Statement.GetSQLParams do |
330 |
begin |
331 |
Params[0].AsString := 'ABC'; |
332 |
Params[1].AsInteger := 3; |
333 |
Params[2].AsString := 'England'; |
334 |
Params[3].AsString := 'Chief Tester'; |
335 |
Params[4].AsFloat := 21000; |
336 |
Params[5].AsString := '24000.99'; |
337 |
Params[6].AsBlob := Attachment.CreateBlob(Transaction,'JOB','JOB_REQUIREMENT').SetString( |
338 |
'The quick brown fox jumped over the lazy dog'); |
339 |
ar := Attachment.CreateArray(Transaction,'JOB','LANGUAGE_REQ'); |
340 |
ar.SetAsString([1],'Eng'); |
341 |
Params[7].AsArray := ar; |
342 |
end; |
343 |
Statement.AddToBatch; |
344 |
with Statement.GetSQLParams do |
345 |
begin |
346 |
Params[0].AsString := 'DEF'; |
347 |
Params[1].AsInteger := 3; |
348 |
Params[2].AsString := 'England'; |
349 |
Params[3].AsString := 'Deputy Tester'; |
350 |
Params[4].AsFloat := 21000; |
351 |
Params[5].AsString := '24000.99'; |
352 |
Params[6].AsBlob := Attachment.CreateBlob(Transaction,'JOB','JOB_REQUIREMENT').SetString( |
353 |
'The quick brown fox jumped over the running dog'); |
354 |
ar := Attachment.CreateArray(Transaction,'JOB','LANGUAGE_REQ'); |
355 |
ar.SetAsString([1],'Eng'); |
356 |
ar.SetAsString([2],'Fra'); |
357 |
Params[7].AsArray := ar; |
358 |
end; |
359 |
Statement.AddToBatch; |
360 |
BC := Statement.ExecuteBatch; |
361 |
WriteAffectedRows(Statement); |
362 |
WriteBatchCompletion(BC); |
363 |
Statement := Attachment.Prepare(Transaction,'Select * from JOB Where JOB_CODE in (''ABC'',''DEF'')',3); |
364 |
writeln(Outfile,'Rows after insert'); |
365 |
ReportResults(Statement); |
366 |
Transaction.Rollback; |
367 |
end; |
368 |
|
369 |
procedure TTest19.WriteBatchCompletion(bc: IBatchCompletion); |
370 |
var i: integer; |
371 |
begin |
372 |
if bc <> nil then |
373 |
with bc do |
374 |
begin |
375 |
writeln(OutFile,'Batch Completion Info'); |
376 |
writeln(OutFile,'Total rows processed = ',getTotalProcessed); |
377 |
writeln(Outfile,'Updated Records = ',getUpdated); |
378 |
for i := 0 to getTotalProcessed -1 do |
379 |
{$IFDEF FPC} |
380 |
writeln(Outfile,'Row ',i+1,' State = ',getState(i),' Msg = ',getStatusMessage(i)); |
381 |
{$ELSE} |
382 |
writeln(Outfile,'Row ',i+1,' State = ',ord(getState(i)),' Msg = ',getStatusMessage(i)); |
383 |
{$ENDIF} |
384 |
end; |
385 |
end; |
386 |
|
387 |
procedure TTest19.ErrorHandlingTests(Attachment: IAttachment); |
388 |
var Transaction: ITransaction; |
389 |
Statement: IStatement; |
390 |
BC: IBatchCompletion; |
391 |
begin |
392 |
Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taRollback); |
393 |
writeln(Outfile,'Test Error Handling'); |
394 |
try |
395 |
Statement := Attachment.Prepare(Transaction,'Update Employee Set HIRE_DATE = ? Where EMP_NO = ?',3); |
396 |
Statement.GetSQLParams[0].AsDateTime := EncodeDate(2016,1,31); |
397 |
Statement.GetSQLParams[1].AsInteger := 8; |
398 |
Statement.AddToBatch; |
399 |
Statement.GetSQLParams[0].AsString := '2018.5.28'; |
400 |
Statement.GetSQLParams[1].AsInteger := 2; |
401 |
Statement.AddToBatch; |
402 |
Statement.ExecuteBatch; |
403 |
except on E:Exception do |
404 |
writeln(Outfile,'Error reported (as expected) when changing param type: ' + E.Message); |
405 |
end; |
406 |
writeln(Outfile,'Test Error Handling - Update returning should fail'); |
407 |
try |
408 |
Statement := Attachment.Prepare(Transaction,'Update Employee Set HIRE_DATE = ? Where EMP_NO = ? Returning EMP_NO',3); |
409 |
Statement.GetSQLParams[0].AsDateTime := EncodeDate(2016,1,31); |
410 |
Statement.GetSQLParams[1].AsInteger := 8; |
411 |
Statement.AddToBatch; |
412 |
Statement.ExecuteBatch; |
413 |
except on E:Exception do |
414 |
writeln(Outfile,'Error reported (as expected) when defering update returning query: ' + E.Message); |
415 |
end; |
416 |
try |
417 |
writeln(Outfile,'Error handling when Insert rows - duplicate key'); |
418 |
Statement := Attachment.PrepareWithNamedParameters(Transaction,'INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE,' + |
419 |
'DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) '+ |
420 |
'VALUES (:EMP_NO, :FIRST_NAME, :LAST_NAME, :PHONE_EXT, :HIRE_DATE,' + |
421 |
':DEPT_NO, :JOB_CODE, :JOB_GRADE, :JOB_COUNTRY, :SALARY)',3); |
422 |
with Statement.GetSQLParams do |
423 |
begin |
424 |
ByName('EMP_NO').AsInteger := 150; |
425 |
ByName('FIRST_NAME').AsString := 'John'; |
426 |
ByName('LAST_NAME').AsString := 'Doe'; |
427 |
ByName('PHONE_EXT').AsString := ''; |
428 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,1); |
429 |
ByName('DEPT_NO').AsString := '600'; |
430 |
ByName('JOB_CODE').AsString := 'Eng'; |
431 |
ByName('JOB_GRADE').AsInteger := 4; |
432 |
ByName('JOB_COUNTRY').AsString := 'England'; |
433 |
ByName('SALARY').AsFloat := 41000.89; |
434 |
end; |
435 |
Statement.AddToBatch; |
436 |
with Statement.GetSQLParams do |
437 |
begin |
438 |
ByName('EMP_NO').AsInteger := 150; {duplicate key} |
439 |
ByName('FIRST_NAME').AsString := 'Jane'; |
440 |
ByName('LAST_NAME').AsString := 'Doe'; |
441 |
ByName('PHONE_EXT').AsString := ''; |
442 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,2); |
443 |
// ByName('DEPT_NO').AsString := '600'; |
444 |
ByName('JOB_CODE').AsString := 'Eng'; |
445 |
ByName('JOB_GRADE').AsInteger := 4; |
446 |
ByName('JOB_COUNTRY').AsString := 'England'; |
447 |
ByName('SALARY').AsFloat := 42000.89; |
448 |
end; |
449 |
Statement.AddToBatch; |
450 |
with Statement.GetSQLParams do |
451 |
begin |
452 |
ByName('EMP_NO').AsInteger := 152; |
453 |
ByName('FIRST_NAME').AsString := 'John'; |
454 |
ByName('LAST_NAME').AsString := 'SmithAndJonesFamily1'; //Longest Name |
455 |
ByName('PHONE_EXT').AsString := ''; |
456 |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,3); |
457 |
// ByName('DEPT_NO').AsString := '600'; |
458 |
ByName('JOB_CODE').AsString := 'Eng'; |
459 |
ByName('JOB_GRADE').AsInteger := 4; |
460 |
ByName('JOB_COUNTRY').AsString := 'England'; |
461 |
ByName('SALARY').AsFloat := 41000.99; |
462 |
end; |
463 |
Statement.AddToBatch; |
464 |
Statement.ExecuteBatch; |
465 |
except on E:Exception do |
466 |
writeln(Outfile,'Error reported when inserting: ' + E.Message); |
467 |
end; |
468 |
WriteAffectedRows(Statement); |
469 |
BC := Statement.GetBatchCompletion; |
470 |
if BC <> nil then |
471 |
WriteBatchCompletion(BC); |
472 |
Transaction.Rollback; |
473 |
end; |
474 |
|
475 |
function TTest19.TestTitle: AnsiString; |
476 |
begin |
477 |
Result := 'Test 19: Batch Update and Insert Queries'; |
478 |
end; |
479 |
|
480 |
procedure TTest19.RunTest(CharSet: AnsiString; SQLDialect: integer); |
481 |
var Attachment: IAttachment; |
482 |
DPB: IDPB; |
483 |
S: TStrings; |
484 |
i: integer; |
485 |
begin |
486 |
DPB := FirebirdAPI.AllocateDPB; |
487 |
DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName); |
488 |
DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword); |
489 |
DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet); |
490 |
DPB.Add(isc_dpb_config).SetAsString('WireCompression=true'); |
491 |
|
492 |
writeln(OutFile,'Opening ',Owner.GetEmployeeDatabaseName); |
493 |
Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB); |
494 |
|
495 |
if not Attachment.HasBatchMode then |
496 |
writeln(OutFile,'Skipping test for Firebird 4 and later') |
497 |
else |
498 |
begin |
499 |
writeln(OutFile,'Database Open'); |
500 |
S := TStringList.Create; |
501 |
try |
502 |
Attachment.getFBVersion(S); |
503 |
for i := 0 to S.Count -1 do |
504 |
writeln(OutFile,S[i]); |
505 |
finally |
506 |
S.Free; |
507 |
end; |
508 |
DoQuery(Attachment); |
509 |
ErrorHandlingTests(Attachment); |
510 |
end; |
511 |
end; |
512 |
|
513 |
initialization |
514 |
RegisterTest(TTest19); |
515 |
|
516 |
end. |
517 |
|