1 |
|
unit Test4; |
2 |
+ |
{$IFDEF MSWINDOWS} |
3 |
+ |
{$DEFINE WINDOWS} |
4 |
+ |
{$ENDIF} |
5 |
|
|
6 |
< |
{$mode objfpc}{$H+} |
6 |
> |
{$IFDEF FPC} |
7 |
> |
{$mode delphi} |
8 |
|
{$codepage utf8} |
9 |
+ |
{$ENDIF} |
10 |
|
|
11 |
|
{Test 4: Update, Insert and Delete Queries} |
12 |
|
|
49 |
|
private |
50 |
|
procedure DoQuery(Attachment: IAttachment); |
51 |
|
public |
52 |
< |
function TestTitle: string; override; |
53 |
< |
procedure RunTest(CharSet: string; SQLDialect: integer); override; |
52 |
> |
function TestTitle: AnsiString; override; |
53 |
> |
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
54 |
|
end; |
55 |
|
|
56 |
|
|
62 |
|
var Transaction, Transaction2, Transaction3: ITransaction; |
63 |
|
Statement: IStatement; |
64 |
|
Rows: IResultSet; |
65 |
+ |
stats: TPerfCounters; |
66 |
|
begin |
67 |
|
Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taRollback); |
68 |
|
Statement := Attachment.Prepare(Transaction,'Update Employee Set Hire_Date = ? Where EMP_NO = ?',3); |
74 |
|
Transaction.Start(TARollback); |
75 |
|
|
76 |
|
Statement := Attachment.PrepareWithNamedParameters(Transaction,'Select * from EMPLOYEE Where EMP_NO = :EMP_NO',3); |
77 |
+ |
Statement.EnableStatistics(true); |
78 |
|
Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 8; |
79 |
|
ReportResults(Statement); |
80 |
+ |
if Statement.GetPerfStatistics(stats) then |
81 |
+ |
WritePerfStats(stats); |
82 |
|
|
83 |
|
Statement := Attachment.PrepareWithNamedParameters(Transaction,'INSERT INTO EMPLOYEE (EMP_NO, FIRST_NAME, LAST_NAME, PHONE_EXT, HIRE_DATE,' + |
84 |
|
'DEPT_NO, JOB_CODE, JOB_GRADE, JOB_COUNTRY, SALARY) '+ |
90 |
|
ByName('FIRST_NAME').AsString := 'John'; |
91 |
|
ByName('LAST_NAME').AsString := 'Doe'; |
92 |
|
ByName('PHONE_EXT').AsString := ''; |
93 |
< |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,1);; |
93 |
> |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,1); |
94 |
|
ByName('DEPT_NO').AsString := '600'; |
95 |
|
ByName('JOB_CODE').AsString := 'Eng'; |
96 |
|
ByName('JOB_GRADE').AsInteger := 4; |
116 |
|
ByName('EMP_NO').AsInteger := 151; |
117 |
|
ByName('FIRST_NAME').AsString := 'Major'; |
118 |
|
ByName('PHONE_EXT').AsString := ''; |
119 |
< |
ByName('HIRE_DATE').AsDateTime := EncodeDate(2015,4,1);; |
119 |
> |
ByName('HIRE_DATE').AsString := '2015-4-1'; |
120 |
|
ByName('DEPT_NO').AsString := '600'; |
121 |
|
ByName('JOB_CODE').AsString := 'Eng'; |
122 |
|
ByName('JOB_GRADE').AsInteger := 4; |
123 |
|
ByName('JOB_COUNTRY').AsString := 'England'; |
124 |
< |
ByName('SALARY').AsFloat := 40000.59; |
124 |
> |
ByName('SALARY').AsString := '40000.59'; |
125 |
|
end; |
126 |
|
Statement.Execute; |
127 |
|
WriteAffectedRows(Statement); |
194 |
|
writeln(OutFile,'Same Statement - updated params'); |
195 |
|
Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 9; |
196 |
|
ReportResults(Statement); |
197 |
+ |
|
198 |
+ |
writeln(outfile,'Test using Execute Block'); |
199 |
+ |
|
200 |
+ |
Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taRollback); |
201 |
+ |
Statement := Attachment.PrepareWithNamedParameters(Transaction, |
202 |
+ |
'Execute Block (Hired Timestamp = :Hire_Date, empno integer = :EMP_NO) '+ |
203 |
+ |
'As Begin ' + |
204 |
+ |
' Update Employee Set Hire_Date = :Hired Where EMP_NO = :empno; '+ |
205 |
+ |
'End' |
206 |
+ |
,3); |
207 |
+ |
Statement.GetSQLParams.ByName('Hire_Date').AsDateTime := EncodeDate(2015,1,31);; |
208 |
+ |
Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 8; |
209 |
+ |
Statement.Execute; |
210 |
+ |
WriteAffectedRows(Statement); |
211 |
+ |
Statement := Attachment.PrepareWithNamedParameters(Transaction,'Select * from EMPLOYEE Where EMP_NO = :EMP_NO',3); |
212 |
+ |
Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 8; |
213 |
+ |
ReportResults(Statement); |
214 |
+ |
|
215 |
|
end; |
216 |
|
|
217 |
< |
function TTest4.TestTitle: string; |
217 |
> |
function TTest4.TestTitle: AnsiString; |
218 |
|
begin |
219 |
|
Result := 'Test 4: Update, Insert and Delete Queries'; |
220 |
|
end; |
221 |
|
|
222 |
< |
procedure TTest4.RunTest(CharSet: string; SQLDialect: integer); |
222 |
> |
procedure TTest4.RunTest(CharSet: AnsiString; SQLDialect: integer); |
223 |
|
var Attachment: IAttachment; |
224 |
|
DPB: IDPB; |
225 |
|
begin |