ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test4.pas
(Generate patch)

Comparing ibx/trunk/fbintf/testsuite/Test4.pas (file contents):
Revision 47 by tony, Mon Jan 9 15:31:51 2017 UTC vs.
Revision 270 by tony, Fri Jan 18 11:10:37 2019 UTC

# Line 1 | Line 1
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  
# Line 44 | Line 49 | type
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  
# Line 55 | Line 60 | implementation
60  
61   procedure TTest4.DoQuery(Attachment: IAttachment);
62   var Transaction, Transaction2, Transaction3: ITransaction;
63 <    Statement: IStatement;
63 >    Statement, Statement2: IStatement;
64      Rows: IResultSet;
65      stats: TPerfCounters;
66   begin
# Line 68 | Line 73 | begin
73    Transaction.Rollback;
74    Transaction.Start(TARollback);
75  
76 <  Statement := Attachment.PrepareWithNamedParameters(Transaction,'Select * from EMPLOYEE Where EMP_NO = :EMP_NO',3);
76 >  Statement := Attachment.PrepareWithNamedParameters(Transaction,'Select * from EMPLOYEE Where EMP_NO = :F1',3);
77    Statement.EnableStatistics(true);
78 <  Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 8;
78 >  Statement.GetSQLParams.ByName('F1').AsInteger := 8;
79    ReportResults(Statement);
80    if Statement.GetPerfStatistics(stats) then
81      WritePerfStats(stats);
# Line 111 | Line 116 | begin
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);
# Line 163 | Line 168 | begin
168    writeln(OutFile,'Employee Count = ', Attachment.OpenCursorAtStart(Transaction,
169           'Select count(*) from EMPLOYEE',3)[0].AsInteger);
170  
171 +  Statement2 := Attachment.PrepareWithNamedParameters(Transaction,'Update EMPLOYEE Set FIRST_NAME = ''Jayne''''s'' Where EMP_NO = :EMP_NO',3);
172 +  Statement2.GetSQLParams.ByName('EMP_NO').AsInteger := 150;
173 +  writeln(OutFile,'Updating');
174 +  Statement2.Execute;
175 +  WriteAffectedRows(Statement);
176 +
177    writeln(OutFile,'Prepare Query again');
178    writeln(OutFile);
179    Statement.Prepare;
# Line 189 | Line 200 | begin
200    writeln(OutFile,'Same Statement - updated params');
201    Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 9;
202    ReportResults(Statement);
203 +
204 +  writeln(outfile,'Test using Execute Block');
205 +
206 +  Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taRollback);
207 +  Statement := Attachment.PrepareWithNamedParameters(Transaction,
208 +    'Execute Block (Hired Timestamp = :Hire_Date, empno integer = :EMP_NO) '+
209 +    'As Begin ' +
210 +    '  Update Employee Set Hire_Date = :Hired Where EMP_NO = :empno; '+
211 +    'End'
212 +    ,3);
213 +  Statement.GetSQLParams.ByName('Hire_Date').AsDateTime := EncodeDate(2015,1,31);;
214 +  Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 8;
215 +  Statement.Execute;
216 +  WriteAffectedRows(Statement);
217 +  Statement := Attachment.PrepareWithNamedParameters(Transaction,'Select * from EMPLOYEE Where EMP_NO = :EMP_NO',3);
218 +  Statement.GetSQLParams.ByName('emp_no').AsInteger := 8;
219 +  ReportResults(Statement);
220 +
221   end;
222  
223 < function TTest4.TestTitle: string;
223 > function TTest4.TestTitle: AnsiString;
224   begin
225    Result := 'Test 4: Update, Insert and Delete Queries';
226   end;
227  
228 < procedure TTest4.RunTest(CharSet: string; SQLDialect: integer);
228 > procedure TTest4.RunTest(CharSet: AnsiString; SQLDialect: integer);
229   var Attachment: IAttachment;
230      DPB: IDPB;
231 +    S: TStrings;
232 +    i: integer;
233   begin
234    DPB := FirebirdAPI.AllocateDPB;
235    DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
236    DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
237    DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
238    DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
239 +  DPB.Add(isc_dpb_config).SetAsString('WireCompression=true');
240  
241    writeln(OutFile,'Opening ',Owner.GetEmployeeDatabaseName);
242    Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
243    writeln(OutFile,'Database Open');
244 +  S := TStringList.Create;
245 +  try
246 +    Attachment.getFBVersion(S);
247 +    for i := 0 to S.Count -1 do
248 +      writeln(OutFile,S[i]);
249 +  finally
250 +    S.Free;
251 +  end;
252    DoQuery(Attachment);
253   end;
254  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines