From 02551d7129bb33c0f799d3ca5cf9a5019b66901a Mon Sep 17 00:00:00 2001 From: lacak Date: Fri, 14 Mar 2014 07:23:08 +0000 Subject: [PATCH] fcl-db: tests: PostgreSQL stores unquoted identifiers in lower-case which is not compliant with SQL standard. (and causes some tests fail) Introduce sql server type identifier char case formating function. git-svn-id: trunk@27129 - --- packages/fcl-db/tests/sqldbtoolsunit.pas | 16 +++++++++++++++- packages/fcl-db/tests/testfieldtypes.pas | 10 +++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/fcl-db/tests/sqldbtoolsunit.pas b/packages/fcl-db/tests/sqldbtoolsunit.pas index 349a69ddbc..a6778d2971 100644 --- a/packages/fcl-db/tests/sqldbtoolsunit.pas +++ b/packages/fcl-db/tests/sqldbtoolsunit.pas @@ -64,7 +64,9 @@ type var SQLConnType : TSQLConnType; SQLServerType : TSQLServerType; FieldtypeDefinitions : Array [TFieldType] of String[20]; - + +function IdentifierCase(const s: string): string; + implementation uses StrUtils; @@ -137,6 +139,18 @@ const (ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssPostgreSQL,ssFirebird,ssUnknown,ssOracle,ssSQLite,ssMSSQL,ssSybase); +function IdentifierCase(const s: string): string; +begin + // format unquoted identifier name as required by sql servers + case SQLServerType of + ssPostgreSQL: Result := LowerCase(s); // PostgreSQL stores unquoted identifiers in lowercase (incompatible with the SQL standard) + ssInterbase, + ssFirebird : Result := UpperCase(s); + else + Result := s; // mixed case + end; +end; + { TSQLDBConnector } procedure TSQLDBConnector.CreateFConnection; diff --git a/packages/fcl-db/tests/testfieldtypes.pas b/packages/fcl-db/tests/testfieldtypes.pas index baadeba09e..df6edb19fa 100644 --- a/packages/fcl-db/tests/testfieldtypes.pas +++ b/packages/fcl-db/tests/testfieldtypes.pas @@ -477,7 +477,7 @@ var i : byte; begin - if SQLConnType<>postgresql then Ignore('This test does only apply to Postgres, since others don''t support varchars without length given'); + if SQLServerType<>ssPostgreSQL then Ignore('This test does only apply to Postgres, since others don''t support varchars without length given'); CreateTableWithFieldType(ftString,'VARCHAR'); TestFieldDeclaration(ftString,dsMaxStringSize+1); @@ -1341,12 +1341,12 @@ begin with ds do begin AFld1 := TIntegerField.Create(ds); - AFld1.FieldName := 'ID'; + AFld1.FieldName := IdentifierCase('ID'); AFld1.DataSet := ds; AFld1.ProviderFlags := AFld1.ProviderFlags + [pfInKey]; AFld2 := TStringField.Create(ds); - AFld2.FieldName := 'NAME'; + AFld2.FieldName := IdentifierCase('NAME'); AFld2.DataSet := ds; AFld3 := TIntegerField.Create(ds); @@ -1987,8 +1987,8 @@ begin Close; // tests parsing SELECT with quoted identifiers (MySQL requires sql-mode=ANSI_QUOTES) - SQL.Text:='SELECT"ID"FROM"FPDEV"ORDER BY"ID"'; - if SQLServerType in [ssPostgreSQL] then SQL.Text:=lowercase(SQL.Text); // The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard + // The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard + SQL.Text:=IdentifierCase('SELECT"ID"FROM"FPDEV"ORDER BY"ID"'); Open; CheckTrue(CanModify, SQL.Text); Close;