ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/test2.pas
Revision: 287
Committed: Thu Apr 11 08:51:23 2019 UTC (5 years ago) by tony
Content type: text/x-pascal
File size: 3416 byte(s)
Log Message:
Fixes Merged

File Contents

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