ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/testsuite/Test28.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: 4910 byte(s)
Log Message:
Updated for IBX 4 release

File Contents

# User Rev Content
1 tony 315 unit Test28;
2    
3     {$mode objfpc}{$H+}
4    
5     {Test 28: Create Local Database from Script}
6    
7     { Description
8     }
9    
10     interface
11    
12     uses
13     Classes, SysUtils, TestApplication, IBXTestBase, IB, IBCMLocalDBSupport,
14     IBExtract, IBSQL;
15    
16     const
17     aTestID = '28';
18     aTestTitle = 'Create Local Database from Script';
19    
20     type
21    
22     { TTest28 }
23    
24     TTest28 = class(TIBXTestBase)
25     private
26     FLocalDB: TIBCMLocalDBSupport;
27     FExtract: TIBExtract;
28     procedure HandleExtractLine(Sender: TObject; start, count: integer);
29     procedure HandleGetDBVersionNo(Sender: TObject; var VersionNo: integer);
30     procedure HandleLogMessage(Sender: TObject; Msg: string);
31     procedure GetSharedDirectory(Sender: TObject; var SharedDataDir: string);
32     procedure InsertRecord;
33     protected
34     procedure CreateObjects(Application: TTestApplication); override;
35     function GetTestID: AnsiString; override;
36     function GetTestTitle: AnsiString; override;
37     procedure InitTest; override;
38     public
39     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
40     end;
41    
42    
43     implementation
44    
45     { TTest28 }
46    
47     procedure TTest28.HandleExtractLine(Sender: TObject; start, count: integer);
48     var i: integer;
49     begin
50     for i := 0 to count - 1 do
51     writeln(OutFile,FExtract.Items[start + i]);
52     end;
53    
54     procedure TTest28.HandleGetDBVersionNo(Sender: TObject; var VersionNo: integer);
55     begin
56     VersionNo := 0;
57     IBTransaction.Active := true;
58     try
59     with TIBSQL.Create(nil) do
60     try
61     Database := IBDatabase;
62     Transaction := IBTransaction;
63     SQL.Text := 'Select * From RDB$RELATIONS Where RDB$RELATION_NAME = ''DBVERSIONINFO''';
64     ExecQuery;
65     try
66     if EOF then Exit;
67     finally
68     Close;
69     end;
70     finally
71     Free
72     end;
73    
74     with TIBSQL.Create(nil) do
75     try
76     Database := IBDatabase;
77     Transaction := IBTransaction;
78     SQL.Text := 'Select VersionNo From DBVersionInfo';
79     ExecQuery;
80     try
81     VersionNo := FieldByName('VersionNo').AsInteger;
82     finally
83     Close;
84     end;
85     finally
86     Free;
87     end;
88     finally
89     IBTransaction.Commit;
90     end;
91     end;
92    
93     procedure TTest28.HandleLogMessage(Sender: TObject; Msg: string);
94     begin
95     writeln(OutFile,Msg);
96     end;
97    
98     procedure TTest28.GetSharedDirectory(Sender: TObject; var SharedDataDir: string
99     );
100     begin
101     SharedDataDir := 'resources/Test28';
102     end;
103    
104     procedure TTest28.InsertRecord;
105     begin
106     with TIBSQL.Create(nil) do
107     try
108     Database := IBDatabase;
109     Transaction := IBTransaction;
110     Transaction.Active := true;
111     SQL.Text := 'INSERT INTO IBDATASETTEST (KeyField,PlainText) Values(Gen_ID(AGenerator,1),''Test'')';
112     ExecQuery;
113     Transaction.Commit;
114     finally
115     Free;
116     end;
117     end;
118    
119     procedure TTest28.CreateObjects(Application: TTestApplication);
120     begin
121     inherited CreateObjects(Application);
122     FLocalDB := TIBCMLocalDBSupport.Create(Application);
123     FLocalDB.Database := IBDatabase;
124     FLocalDB.VendorName := 'MWA Software';
125     FLocalDB.OnGetDBVersionNo := @HandleGetDBVersionNo;
126     FLocalDB.OnLogMessage := @HandleLogMessage;
127     FLocalDB.OnGetSharedDataDir := @GetSharedDirectory;
128     FExtract := TIBExtract.Create(Application);
129     FExtract.Database := IBDatabase;
130     FExtract.Transaction := IBTransaction;
131     FExtract.OnExtractLines := @HandleExtractLine;
132     end;
133    
134     function TTest28.GetTestID: AnsiString;
135     begin
136     Result := aTestID;
137     end;
138    
139     function TTest28.GetTestTitle: AnsiString;
140     begin
141     Result := aTestTitle;
142     end;
143    
144     procedure TTest28.InitTest;
145     begin
146     IBDatabase.DatabaseName := 'nemo';
147     FLocalDB.DatabaseName := ExtractDBName(Owner.GetNewDatabaseName);
148     FLocalDB.EmptyDBArchive := 'schema.sql';
149     FLocalDB.RequiredVersionNo := 1;
150     ReadWriteTransaction;
151     end;
152    
153     procedure TTest28.RunTest(CharSet: AnsiString; SQLDialect: integer);
154     var BackupFileName: string;
155     begin
156     IBDatabase.Connected := true;
157     try
158     writeln(Outfile,'Show schema for ',IBDatabase.DatabaseName);
159     FExtract.ExtractObject(eoDatabase,'',[etGrantsToUser,etData]);
160    
161     InsertRecord;
162     writeln(Outfile,'Now test out an upgrade failure');
163     IBDatabase.connected := false;
164     FLocalDB.RequiredVersionNo := 2;
165     FLocalDB.UpgradeConfFile := 'upgrade.conf';
166     try
167     IBDatabase.connected := true;
168     except on E:Exception do
169     begin
170     writeln(Outfile,'Upgrade failed (as expected): ',E.Message);
171     FLocalDB.RequiredVersionNo := 1;
172     IBDatabase.Connected := true;
173     end;
174     end;
175     writeln(Outfile,'Schema after failed upgrade is');
176     FExtract.ExtractObject(eoDatabase,'',[etGrantsToUser,etData]);
177     writeln(Outfile,'Save and Restore Tests');
178     InsertRecord;
179     BackupFileName := Owner.GetBackupFileName;
180     FLocalDB.SaveDatabase(BackupFileName);
181     InsertRecord;
182     FLocalDB.RestoreDatabase(BackupFileName);
183     writeln(Outfile,'Database after restore');
184     FExtract.ExtractObject(eoDatabase,'',[etGrantsToUser,etData]);
185     finally
186     IBDatabase.DropDatabase;
187     end;
188     end;
189    
190     initialization
191     RegisterTest(TTest28);
192    
193     end.
194