From 1edf2d3cd029d227f8048676b2d691af8e787d78 Mon Sep 17 00:00:00 2001 From: lacak Date: Wed, 16 May 2018 11:30:37 +0000 Subject: [PATCH] fcl-db: tests: Adjust tests to take into account connection charset and field codepage when testing Size and DataSize git-svn-id: trunk@39003 - --- packages/fcl-db/tests/database.ini.txt | 51 +++++++----------------- packages/fcl-db/tests/testdbbasics.pas | 4 +- packages/fcl-db/tests/testfieldtypes.pas | 4 +- packages/fcl-db/tests/toolsunit.pas | 15 ++++++- 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/packages/fcl-db/tests/database.ini.txt b/packages/fcl-db/tests/database.ini.txt index ec60740b11..2c01e367bd 100644 --- a/packages/fcl-db/tests/database.ini.txt +++ b/packages/fcl-db/tests/database.ini.txt @@ -35,6 +35,9 @@ password=masterkey ; of the database server hostname=localhost +; connection character set +charset= + ; SQL command log file (for sqldb databases) ; will be appended to each run ; uncomment to use @@ -57,42 +60,7 @@ name=fbembedtest.fdb user=sysdba password=masterkey hostname= - -[mysql40] -; MySQL 4.0 database: -connector=sql -connectorparams=mysql40 -name=testdb -user=root -password= -hostname=127.0.0.1 - -[mysql41] -; MySQL 4.1 database: -connector=sql -connectorparams=mysql41 -name=testdb -user=root -password= -hostname=127.0.0.1 - -[mysql50] -; MySQL 5.0 database: -connector=sql -connectorparams=mysql50 -name=testdb -user=root -password= -hostname=127.0.0.1 - -[mysql51] -; MySQL 5.1 database: -connector=sql -connectorparams=mysql51 -name=testdb -user=root -password= -hostname=127.0.0.1 +charset=utf8 [mysql55] ; MySQL 5.5 database: @@ -112,6 +80,16 @@ user=root password= hostname=127.0.0.1 +[mysql57] +; MySQL 5.7 database: +connector=sql +connectorparams=mysql57 +name=testdb +user=root +password= +hostname=127.0.0.1 +charset=utf8mb4 + [mssql] ; MS SQL Server database: connector=sql @@ -161,6 +139,7 @@ hostname=127.0.0.1 connector=sql connectorparams=sqlite3 name=test.db +charset=utf-8 [sybase] ; Sybase ASE database diff --git a/packages/fcl-db/tests/testdbbasics.pas b/packages/fcl-db/tests/testdbbasics.pas index 08c2e2c386..fbd4fc1648 100644 --- a/packages/fcl-db/tests/testdbbasics.pas +++ b/packages/fcl-db/tests/testdbbasics.pas @@ -2684,7 +2684,7 @@ var i : byte; Fld : TField; begin - TestFieldDefinition(ftString,11,ds,Fld); + TestFieldDefinition(ftString, 10*DBConnector.CharSize+1, ds, Fld); for i := 0 to testValuesCount-1 do begin @@ -2872,7 +2872,7 @@ var i : byte; Fld : TField; begin - TestFieldDefinition(ftFixedChar,11,ds,Fld); + TestFieldDefinition(ftFixedChar, 10*DBConnector.CharSize+1, ds, Fld); for i := 0 to testValuesCount-1 do begin diff --git a/packages/fcl-db/tests/testfieldtypes.pas b/packages/fcl-db/tests/testfieldtypes.pas index 97a1c1f010..1890075db2 100644 --- a/packages/fcl-db/tests/testfieldtypes.pas +++ b/packages/fcl-db/tests/testfieldtypes.pas @@ -438,7 +438,7 @@ var begin CreateTableWithFieldType(ftString,'VARCHAR(10)'); - TestFieldDeclaration(ftString,11); + TestFieldDeclaration(ftString,10*DBConnector.CharSize+1); for i := 0 to testValuesCount-1 do TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')'); @@ -935,7 +935,7 @@ var begin CreateTableWithFieldType(ftString,'VARCHAR(9000)'); - TestFieldDeclaration(ftString,9001); + TestFieldDeclaration(ftString,9000*DBConnector.CharSize+1); setlength(s,9000); for i := 1 to 9000 do diff --git a/packages/fcl-db/tests/toolsunit.pas b/packages/fcl-db/tests/toolsunit.pas index 89a9941173..e9ec72f023 100644 --- a/packages/fcl-db/tests/toolsunit.pas +++ b/packages/fcl-db/tests/toolsunit.pas @@ -26,6 +26,7 @@ type FLogTimeFormat: TFormatSettings; //for error logging only FFormatSettings: TFormatSettings; FChangedFieldDataset : boolean; + function GetCharSize: integer; protected FChangedDatasets : array[0..MaxDataSet] of boolean; FUsedDatasets : TFPList; @@ -78,6 +79,7 @@ type procedure StopTest(TestName: string); property TestUniDirectional: boolean read GetTestUniDirectional write SetTestUniDirectional; property FormatSettings: TFormatSettings read FFormatSettings; + property CharSize: integer read GetCharSize; end; { TTestDataLink } @@ -241,6 +243,7 @@ function TimeStringToDateTime(d: String): TDateTime; function StringToByteArray(const s: ansistring): Variant; function StringToBytes(const s: ansistring): TBytes; + implementation uses @@ -292,7 +295,7 @@ begin raise exception.create('Connector does not support tests for unidirectional datasets'); end; -procedure TDBConnector.DataEvent(dataset : tdataset); +procedure TDBConnector.DataEvent(dataset: TDataset); begin DataEvents := DataEvents + 'DataEvent' + ';'; end; @@ -382,6 +385,16 @@ begin end; end; +function TDBConnector.GetCharSize: integer; +begin + case LowerCase(dbcharset) of + 'utf8','utf-8','utf8mb4': + Result := 4; + else + Result := 1; + end; +end; + { TTestDataLink }