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

File Contents

# User Rev Content
1 tony 315 unit Test06;
2    
3     {$mode objfpc}{$H+}
4    
5     {Test 6: Multi-Database Transaction}
6    
7     { creates two databases and adds a record to each as a multi-database transaction.
8     Commit and print results.
9     }
10    
11     interface
12    
13     uses
14     Classes, SysUtils, TestApplication, IBXTestBase, IB, IBDatabase, IBSQL;
15    
16     const
17     aTestID = '06';
18     aTestTitle = 'Multi-Database Transaction';
19    
20     type
21    
22     { TTest6 }
23    
24     TTest6 = class(TIBXTestBase)
25     private
26     FIBDatabase2: TIBDatabase;
27     FIBTransaction2: TIBTransaction;
28     FIBMultiTransaction: TIBTransaction;
29     FIBSQL: TIBSQL;
30     procedure HandleCreateDatebase(Sender: TObject);
31     protected
32     procedure CreateObjects(Application: TTestApplication); override;
33     function GetTestID: AnsiString; override;
34     function GetTestTitle: AnsiString; override;
35     procedure InitTest; override;
36     public
37     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
38     end;
39    
40    
41     implementation
42    
43     const
44     InsertSQL = 'Insert into IBXTEST(TABLEKEY, F1) VALUES(GEN_ID(IBXGEN,1),?) Returning TABLEKEY';
45     SelectSQL = 'Select TABLEKEY, F1 From IBXTest';
46    
47     { TTest6 }
48    
49     procedure TTest6.HandleCreateDatebase(Sender: TObject);
50     begin
51     InitialiseDatabase(FIBDatabase2);
52     end;
53    
54     procedure TTest6.CreateObjects(Application: TTestApplication);
55     begin
56     inherited CreateObjects(Application);
57     FIBDatabase2 := TIBDatabase.Create(Application);
58     FIBDatabase2.FirebirdLibraryPathName := Owner.ClientLibraryPath;
59     FIBDatabase2.LoginPrompt := false;
60     FIBDatabase2.Params.Add('user_name=' + Owner.GetUserName);
61     FIBDatabase2.Params.Add('password=' + Owner.GetPassword);
62     FIBDatabase2.Params.Add('lc_ctype=UTF8');
63     FIBDatabase2.OnCreateDatabase := @HandleCreateDatebase;
64     FIBDatabase2.Name := 'Test_Database2_' + GetTestID;
65     FIBTransaction2 := TIBTransaction.Create(Application);
66     FIBTransaction2.DefaultDatabase := FIBDatabase2;
67     FIBDatabase2.DefaultTransaction := FIBTransaction2;
68     FIBTransaction2.Name := 'Test_Transaction2_' + GetTestID;
69     FIBTransaction2.Params.Add('concurrency');
70     FIBTransaction2.Params.Add('wait');
71     FIBTransaction2.Params.Add('write');
72     FIBMultiTransaction := TIBTransaction.Create(Application);
73     FIBMultiTransaction.AddDatabase(IBDatabase);
74     FIBMultiTransaction.AddDatabase(FIBDatabase2);
75     FIBMultiTransaction.Name := 'Multi_Transaction';
76     FIBMultiTransaction.Params.Add('concurrency');
77     FIBMultiTransaction.Params.Add('wait');
78     FIBMultiTransaction.Params.Add('write');
79     FIBSQL := TIBSQL.Create(Application);
80     FIBSQL.ParamCheck := false;
81     end;
82    
83     function TTest6.GetTestID: AnsiString;
84     begin
85     Result := aTestID;
86     end;
87    
88     function TTest6.GetTestTitle: AnsiString;
89     begin
90     Result := aTestTitle;
91     end;
92    
93     procedure TTest6.InitTest;
94     begin
95     IBDatabase.DatabaseName := Owner.GetNewDatabaseName;
96     IBDatabase.CreateIfNotExists := true;
97     ReadWriteTransaction;
98     FIBDatabase2.DatabaseName := Owner.GetSecondNewDatabaseName;
99     FIBDatabase2.CreateIfNotExists := true;
100     end;
101    
102     procedure TTest6.RunTest(CharSet: AnsiString; SQLDialect: integer);
103     begin
104     try
105     IBDatabase.Connected := true;
106     FIBDatabase2.Connected := true;
107     FIBMultiTransaction.Active := true;
108     FIBSQL.Database := IBDatabase;
109     FIBSQL.Transaction := FIBMultiTransaction;
110     FIBSQL.SQL.Text := InsertSQL;
111     FIBSQL.Params[0].AsInteger := 1;
112     writeln(OutFile,'Add Row to First Database');
113     FIBSQL.ExecQuery;
114     ReportResult(FIBSQL.Current);
115     FIBSQL.Database := FIBDatabase2;
116     FIBSQL.Params[0].AsInteger := 2;
117     writeln(OutFile,'Add Row to Second Database');
118     FIBSQL.ExecQuery;
119     ReportResult(FIBSQL.Current);
120     FIBMultiTransaction.Commit;
121     FIBSQL.Database := IBDatabase;
122     FIBSQL.Transaction := IBTransaction;
123     FIBSQL.SQL.Text := SelectSQL;
124     IBTransaction.Active := true;
125     FIBSQL.Prepare;
126     writeln(OutFile,'Query First Database');
127     ReportResults(FIBSQL.Statement);
128     FIBSQL.Database := FIBDatabase2;
129     FIBSQL.Transaction := FIBTransaction2;
130     FIBTransaction2.Active := true;
131     FIBSQL.Prepare;
132     writeln(OutFile,'Query Second Database');
133     ReportResults(FIBSQL.Statement);
134     finally
135     IBDatabase.DropDatabase;
136     FIBDatabase2.DropDatabase;
137     end;
138     end;
139    
140     initialization
141     RegisterTest(TTest6);
142    
143     end.
144