ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/testsuite/Test15.pas
Revision: 315
Committed: Thu Feb 25 11:56:36 2021 UTC (3 years, 9 months ago) by tony
Content type: text/x-pascal
File size: 3262 byte(s)
Log Message:
Updated for IBX 4 release

File Contents

# User Rev Content
1 tony 315 unit Test15;
2    
3     {$mode objfpc}{$H+}
4    
5     { Test 15: IBStored Proc with packages}
6    
7     {
8     This demonstrates the use of TIBStoredProc with the Firebird 3 packages example
9     provided with the Firebird 3 source code. A database is created in a temporary
10     location when the application is first run. Once this completes, IBStoredProc2 calls
11     the global stored procedure "test", which populates the temporary table FB$OUT.
12    
13     IBStoredProc1 then calls the GET_LINES procedure in the FB$OUT package. It returns
14     a text blob which is then printed out.
15    
16     }
17    
18    
19     interface
20    
21     uses
22     Classes, SysUtils, TestApplication, IBXTestBase, IB, IBStoredProc,
23     IBDatabase;
24    
25     const
26     aTestID = '15';
27     aTestTitle = 'IBStored Proc with packages';
28    
29     type
30    
31     { TTest15 }
32    
33     TTest15 = class(TIBXTestBase)
34     private
35     FIBStoredProc1: TIBStoredProc;
36     FIBStoredProc2: TIBStoredProc;
37     protected
38     procedure CreateObjects(Application: TTestApplication); override;
39     function GetTestID: AnsiString; override;
40     function GetTestTitle: AnsiString; override;
41     procedure InitTest; override;
42     procedure InitialiseDatabase(aDatabase: TIBDatabase); override;
43     function SkipTest: boolean; override;
44     public
45     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
46     end;
47    
48    
49     implementation
50    
51     { TTest15 }
52    
53     procedure TTest15.CreateObjects(Application: TTestApplication);
54     begin
55     inherited CreateObjects(Application);
56     IBQuery.SQL.Text := 'Select A.LINE_NUM, A.CONTENT From FB$OUT_TABLE A';
57     FIBStoredProc1 := TIBStoredProc.Create(Application);
58     FIBStoredProc1.Database := IBDatabase;
59     FIBStoredProc2 := TIBStoredProc.Create(Application);
60     FIBStoredProc2.Database := IBDatabase;
61     end;
62    
63     function TTest15.GetTestID: AnsiString;
64     begin
65     Result := aTestID;
66     end;
67    
68     function TTest15.GetTestTitle: AnsiString;
69     begin
70     Result := aTestTitle;
71     end;
72    
73     procedure TTest15.InitTest;
74     begin
75     IBDatabase.DatabaseName := Owner.GetNewDatabaseName;
76     IBDatabase.CreateIfNotExists := true;
77     FIBStoredProc1.PackageName := 'FB$OUT';
78     FIBStoredProc1.StoredProcName := 'GET_LINES';
79     FIBStoredProc2.StoredProcName := 'TEST';
80     ReadWriteTransaction;
81     end;
82    
83     procedure TTest15.InitialiseDatabase(aDatabase: TIBDatabase);
84     begin
85     if aDatabase.attachment.GetODSMajorVersion < 12 then
86     begin
87     aDatabase.DropDatabase;
88     raise ESkipException.Create('This test requires Firebird 3');
89     end;
90     RunScript(aDatabase,'resources/fbout-header.sql');
91     RunScript(aDatabase,'resources/fbout-body.sql');
92     RunScript(aDatabase,'resources/fbout-test.sql');
93     IBTransaction.Commit;
94     end;
95    
96     function TTest15.SkipTest: boolean;
97     begin
98     Result := FirebirdAPI.GetClientMajor < 3;
99     end;
100    
101     procedure TTest15.RunTest(CharSet: AnsiString; SQLDialect: integer);
102     begin
103     IBDatabase.Connected := true;
104     try
105     IBTransaction.Active := true;
106     writeln(Outfile,'-------------------------------------------------------');
107     writeln(Outfile,'Exec TEST proc');
108     FIBStoredProc2.ExecProc;
109     IBTransaction.Commit;
110     IBTransaction.Active := true;
111     writeln(Outfile,'Show FB$OUT_TABLE');
112     IBQuery.Active := true;
113     PrintDataSet(IBQuery);
114     FIBStoredProc1.ExecProc;
115     writeln(OutFile,FIBStoredProc1.ParamByName('LINES').AsString);
116     finally
117     IBDatabase.DropDatabase;
118     end;
119     end;
120    
121     initialization
122     RegisterTest(TTest15);
123    
124     end.
125