ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/test2.pas
Revision: 45
Committed: Tue Dec 6 10:33:46 2016 UTC (7 years, 4 months ago) by tony
Content type: text/x-pascal
File size: 3198 byte(s)
Log Message:
Committing updates for Release R2-0-0

File Contents

# Content
1 unit test2;
2
3 {$mode objfpc}{$H+}
4 {$codepage utf8}
5
6 {Test 2: Open the employee database and run a query}
7
8 { This test opens the employee example databases with the supplied user name/password
9 and runs a simple query with no parameters. Note that the password parameter
10 is first supplied empty and then updated.
11
12 Both the output metadata and the query plan are printed out, followed by the results of the query.
13
14 A specific employee record is then queried, first using a positional parameter
15 and then a parameter by name. In each case, the SQL Parameter metadata is also
16 printed followed by the query results.
17
18 Finally, the database is explicitly disconnected.
19 }
20
21 interface
22
23 uses
24 Classes, SysUtils, TestManager, IB;
25
26 type
27
28 { TTest2 }
29
30 TTest2 = class(TTestBase)
31 private
32 procedure DoQuery(Attachment: IAttachment);
33 public
34 function TestTitle: string; override;
35 procedure RunTest(CharSet: string; SQLDialect: integer); override;
36 end;
37
38
39 implementation
40
41 { TTest2 }
42
43 procedure TTest2.DoQuery(Attachment: IAttachment);
44 var Transaction: ITransaction;
45 Statement: IStatement;
46 ResultSet: IResultSet;
47 begin
48 Transaction := Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
49 Statement := Attachment.Prepare(Transaction,'Select First 3 * from EMPLOYEE',3);
50 PrintMetaData(Statement.GetMetaData);
51 writeln(OutFile,'Plan = ' ,Statement.GetPlan);
52 writeln(OutFile,Statement.GetSQLText);
53 writeln(OutFile);
54 ReportResults(Statement);
55 Statement := Attachment.Prepare(Transaction,'Select * from EMPLOYEE Where EMP_NO = ?',3);
56 writeln(OutFile,Statement.GetSQLText);
57 ParamInfo(Statement.SQLParams);
58 Statement.GetSQLParams[0].AsInteger := 8;
59 ReportResults(Statement);
60 writeln(OutFile,'With param names');
61 Statement := Attachment.PrepareWithNamedParameters(Transaction,'Select * from EMPLOYEE Where EMP_NO = :EMP_NO',3);
62 Statement.SetRetainInterfaces(true);
63 try
64 writeln(OutFile,Statement.GetSQLText);
65 ParamInfo(Statement.SQLParams);
66 Statement.GetSQLParams.ByName('EMP_NO').AsInteger := 8;
67 ReportResults(Statement);
68 finally
69 Statement.SetRetainInterfaces(false);
70 end;
71 end;
72
73 function TTest2.TestTitle: string;
74 begin
75 Result := 'Test 2: Open the employee database and run a query';
76 end;
77
78 procedure TTest2.RunTest(CharSet: string; SQLDialect: integer);
79 var Attachment: IAttachment;
80 DPB: IDPB;
81 begin
82 DPB := FirebirdAPI.AllocateDPB;
83 DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
84 DPB.Add(isc_dpb_password).setAsString(' ');
85 DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
86 DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
87 DPB.Find(isc_dpb_password).setAsString(Owner.GetPassword);
88 try
89 Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
90 except on e: Exception do
91 writeln(OutFile,'Open Database fails ',E.Message);
92 end;
93 writeln(OutFile,'Opening ',Owner.GetEmployeeDatabaseName);
94 Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
95 writeln(OutFile,'Database Open');
96 DoQuery(Attachment);
97 Attachment.Disconnect;
98 end;
99
100 initialization
101 RegisterTest(TTest2);
102
103 end.
104