ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test12.pas
Revision: 421
Committed: Sat Oct 21 14:22:28 2023 UTC (13 months ago) by tony
Content type: text/x-pascal
File size: 10452 byte(s)
Log Message:
Release 2.6.3 Merged

File Contents

# User Rev Content
1 tony 315 (*
2     * Firebird Interface (fbintf) Test suite. This program is used to
3     * test the Firebird Pascal Interface and provide a semi-automated
4     * pass/fail check for each test.
5     *
6     * The contents of this file are subject to the Initial Developer's
7     * Public License Version 1.0 (the "License"); you may not use this
8     * file except in compliance with the License. You may obtain a copy
9     * of the License here:
10     *
11     * http://www.firebirdsql.org/index.php?op=doc&id=idpl
12     *
13     * Software distributed under the License is distributed on an "AS
14     * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15     * implied. See the License for the specific language governing rights
16     * and limitations under the License.
17     *
18     * The Initial Developer of the Original Code is Tony Whyman.
19     *
20     * The Original Code is (C) 2016 Tony Whyman, MWA Software
21     * (http://www.mwasoftware.co.uk).
22     *
23     * All Rights Reserved.
24     *
25     * Contributor(s): ______________________________________.
26     *
27     *)
28    
29     unit Test12;
30 tony 56 {$IFDEF MSWINDOWS}
31     {$DEFINE WINDOWS}
32     {$ENDIF}
33 tony 45
34 tony 56 {$IFDEF FPC}
35     {$mode delphi}
36 tony 45
37     {$codepage UTF8}
38 tony 56 {$ENDIF}
39 tony 45
40     interface
41    
42     { Test 12: Character Sets
43    
44     This test creates strings in a database with various code pages and then
45     reads them back with different connection character sets. The result is
46     displayed as hex strings so that the actual encoding can be checked in
47     each case.
48     }
49    
50     uses
51 tony 315 Classes, SysUtils, TestApplication, FBTestApp, IB;
52 tony 45
53     type
54    
55     { TTest12 }
56    
57 tony 315 TTest12 = class(TFBTestBase)
58 tony 45 private
59     procedure UpdateDatabase(Attachment: IAttachment);
60     procedure QueryDatabase(Attachment: IAttachment);
61 tony 421 procedure TransliterationTest;
62 tony 45 public
63 tony 56 function TestTitle: AnsiString; override;
64     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
65 tony 45 end;
66    
67     implementation
68    
69 tony 421 uses IBUtils;
70    
71 tony 45 const
72     sqlCreateTable =
73     'Create Table TestData ('+
74     'RowID Integer not null,'+
75     'Title VarChar(32) Character Set UTF8,'+
76 tony 60 'Notes VarChar(64) Character Set ISO8859_1 collate FR_FR,'+
77 tony 45 'BlobData Blob sub_type 1 Character Set WIN1252, '+
78     'BlobData2 Blob sub_type 1 Character Set UTF8, '+
79 tony 47 'InClear VarChar(16) Character Set OCTETS, '+
80 tony 309 'FixedWidth Char(4) Character set UTF8, '+
81 tony 45 'Primary Key(RowID)'+
82     ')';
83    
84 tony 421 sqlCreateException = 'Create Exception CharSetTest ''Some German Special Characters like ÖÄÜöäüß''';
85    
86     sqlCreateProc = 'Create Procedure DoException As Begin Exception CharSetTest; End';
87    
88 tony 45 sqlGetCharSets = 'Select RDB$CHARACTER_SET_NAME,RDB$CHARACTER_SET_ID from RDB$CHARACTER_SETS order by 2';
89    
90 tony 309 sqlInsert = 'Insert into TestData(RowID,Title,Notes, BlobData,BlobData2,InClear,FixedWidth) '+
91     'Values(:RowID,:Title,:Notes,:BlobData,:BlobData2,:InClear,:FixedWidth)';
92 tony 45
93    
94     { TTest12 }
95    
96     procedure TTest12.UpdateDatabase(Attachment: IAttachment);
97     var Transaction: ITransaction;
98     Statement: IStatement;
99     begin
100     Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
101    
102     Statement := Attachment.PrepareWithNamedParameters(Transaction,sqlInsert);
103     ParamInfo(Statement.SQLParams);
104     with Statement.GetSQLParams do
105     begin
106     ByName('rowid').AsInteger := 1;
107 tony 56 {$IFDEF DCC}
108     ByName('title').AsString := UTF8Encode('Blob Test ©€');
109     ByName('Notes').AsString := UTF8Encode('Écoute moi');
110 tony 315 ByName('FixedWidth').AsString := UTF8Encode('É');
111 tony 56 {$ELSE}
112 tony 45 ByName('title').AsString := 'Blob Test ©€';
113     ByName('Notes').AsString := 'Écoute moi';
114 tony 315 ByName('FixedWidth').AsString := 'É';
115 tony 56 {$ENDIF}
116 tony 45 ByName('BlobData').AsString := 'Some German Special Characters like ÖÄÜöäüß';
117     ByName('BlobData2').AsBlob := Attachment.CreateBlob(Transaction,'TestData','BlobData').SetString('Some German Special Characters like ÖÄÜöäüß');
118     ByName('InClear').AsString := #$01'Test'#$0D#$C3;
119     end;
120 tony 345 writeln(Outfile,'Show Param Values');
121     ParamInfo(Statement.SQLParams);
122 tony 45 Statement.Execute;
123     end;
124    
125     procedure TTest12.QueryDatabase(Attachment: IAttachment);
126     var Transaction: ITransaction;
127     Statement: IStatement;
128     ResultSet: IResultSet;
129     begin
130     Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
131     Statement := Attachment.Prepare(Transaction,'Select * from TestData');
132     ReportResults(Statement);
133 tony 421 write(Outfile,'Test Exception Message = ');
134     PrintHexString(Attachment.OpenCursorAtStart(Transaction,'Select RDB$MESSAGE From RDB$EXCEPTIONS Where RDB$EXCEPTION_NAME = ''CHARSETTEST''',[])[0].AsString);
135     writeln(OutFile);
136     try
137     Attachment.ExecuteSQL([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],'Execute Procedure DoException',[]);
138     except On E:Exception do
139     writeln(Outfile,'Exception returned: ',E.Message);
140     end;
141 tony 45 end;
142    
143 tony 421 procedure TTest12.TransliterationTest;
144     const
145     Win1252Test1: UTF8String = 'WIN1252 Characters ÖÄÜöäüß';
146     Win1252Test2: UTF8String = 'Я Écoute moi';
147    
148     var
149     str: AnsiString;
150     begin
151     writeln(Outfile,'Transliteration Tests');
152     writeln(Outfile,'Default System Code Page = ',DefaultSystemCodePage);
153     writeln(Outfile,'Actual System Code Page = ',FBGetSystemCodePage);
154     writeln(Outfile,'Input String = ', Win1252Test1,', Character Set = ',StringCodePage(Win1252Test1),' Hex Values:');
155     PrintHexString(Win1252Test1);
156     writeln(OutFile);
157     str := TransliterateToCodePage(Win1252Test1,1252);
158     writeln(Outfile,'Code Page = ',StringCodePage(str));
159     PrintHexString(str);
160     writeln(OutFile);
161     writeln(Outfile,'Back to UTF8');
162     str := TransliterateToCodePage(str,CP_UTF8);
163     writeln(Outfile,'Code Page = ',StringCodePage(str));
164     writeln(Outfile,str);
165     PrintHexString(str);
166     writeln(OutFile);
167     writeln(Outfile,'ANSI(1252) to ANSI(1251) Test');
168     writeln(Outfile,'Input String = ', Win1252Test2,', Character Set = ',StringCodePage(Win1252Test2),' Hex Values:');
169     PrintHexString(Win1252Test2);
170     writeln(OutFile);
171     str := TransliterateToCodePage(Win1252Test2,1251);
172     writeln(Outfile,'After conversion to 1251');
173     writeln(Outfile,'Code Page = ',StringCodePage(str));
174     PrintHexString(str);
175     writeln(OutFile);
176     writeln(Outfile,'Now Transliterate to WIN1252');
177     str := TransliterateToCodePage(str,1252);
178     writeln(Outfile,'Code Page = ',StringCodePage(str));
179     PrintHexString(str);
180     writeln(OutFile);
181     end;
182    
183 tony 56 function TTest12.TestTitle: AnsiString;
184 tony 45 begin
185     Result := 'Test 12: Character Sets';
186     end;
187    
188 tony 56 procedure TTest12.RunTest(CharSet: AnsiString; SQLDialect: integer);
189 tony 45 var DPB: IDPB;
190     Attachment: IAttachment;
191     begin
192 tony 421 TransliterationTest;
193 tony 45 FHexStrings := true;
194     DPB := FirebirdAPI.AllocateDPB;
195     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
196     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
197     DPB.Add(isc_dpb_lc_ctype).setAsString('UTF8');
198     DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
199     Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
200     Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
201 tony 421 Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateException);
202     Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateProc);
203     Attachment.Disconnect;
204 tony 45
205 tony 421 {Query with UTF8}
206     DPB := FirebirdAPI.AllocateDPB;
207     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
208     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
209     DPB.Add(isc_dpb_lc_ctype).setAsString('UTF8');
210     Attachment := FirebirdAPI.OpenDatabase(Owner.GetNewDatabaseName,DPB);
211 tony 45 UpdateDatabase(Attachment);
212    
213     writeln(OutFile,'Connection Character Set UTF8');
214 tony 421 QueryDatabase(Attachment);
215     Attachment.Disconnect;
216    
217     writeln(OutFile,'Connection Character Set NONE');
218     {Query with No character set}
219     DPB := FirebirdAPI.AllocateDPB;
220     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
221     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
222     Attachment := FirebirdAPI.OpenDatabase(Owner.GetNewDatabaseName,DPB);
223     QueryDatabase(Attachment);
224     Attachment.Disconnect;
225    
226     writeln(OutFile,'Connection Character Set WIN1252');
227     {Query with WIN1252}
228     DPB := FirebirdAPI.AllocateDPB;
229     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
230     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
231     DPB.Add(isc_dpb_lc_ctype).setAsString('WIN1252');
232     Attachment := FirebirdAPI.OpenDatabase(Owner.GetNewDatabaseName,DPB);
233     QueryDatabase(Attachment);
234    
235     Attachment.DropDatabase;
236    
237     writeln(Outfile,'Recreate Database with WIN1252 as the connection character set');
238     DPB := FirebirdAPI.AllocateDPB;
239     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
240     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
241     DPB.Add(isc_dpb_lc_ctype).setAsString('WIN1252');
242     DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
243     Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
244     Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
245     Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateException);
246     Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateProc);
247     Attachment.Disconnect;
248    
249     writeln(OutFile,'Query Database with UTF8, NONE and WIN1252 connections');
250    
251 tony 45 {Query with UTF8}
252 tony 421 DPB := FirebirdAPI.AllocateDPB;
253     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
254     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
255     DPB.Add(isc_dpb_lc_ctype).setAsString('UTF8');
256     Attachment := FirebirdAPI.OpenDatabase(Owner.GetNewDatabaseName,DPB);
257     UpdateDatabase(Attachment);
258    
259     writeln(OutFile,'Connection Character Set UTF8');
260 tony 45 QueryDatabase(Attachment);
261     Attachment.Disconnect;
262    
263     writeln(OutFile,'Connection Character Set NONE');
264     {Query with No character set}
265     DPB := FirebirdAPI.AllocateDPB;
266     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
267     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
268     Attachment := FirebirdAPI.OpenDatabase(Owner.GetNewDatabaseName,DPB);
269     QueryDatabase(Attachment);
270     Attachment.Disconnect;
271    
272     writeln(OutFile,'Connection Character Set WIN1252');
273     {Query with WIN1252}
274     DPB := FirebirdAPI.AllocateDPB;
275     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
276     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
277     DPB.Add(isc_dpb_lc_ctype).setAsString('WIN1252');
278     Attachment := FirebirdAPI.OpenDatabase(Owner.GetNewDatabaseName,DPB);
279     QueryDatabase(Attachment);
280    
281     Attachment.DropDatabase;
282    
283     end;
284    
285     initialization
286     RegisterTest(TTest12);
287     end.
288    

Properties

Name Value
svn:eol-style native