From 36f8d5794b26d277f1072cd6db106ecf5a63daae Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 3 Oct 2021 17:15:33 +0200 Subject: [PATCH] Prefer IdentifierEquals() to compare names of two tables in TDBObject.IsSameAs(), for potentially case insensitive comparison when lower_case_table_names is 1. Fixes "Table x not found in tree" after creating a table with upper case letters on Windows servers. See https://www.heidisql.com/forum.php?t=38150 --- source/dbconnection.pas | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index b8680653..b4dc0474 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -454,6 +454,7 @@ type FInfSch: String; FIdentCharsNoQuote: TSysCharSet; FMaxRowsPerInsert: Int64; + FCaseSensitivity: Integer; procedure SetActive(Value: Boolean); virtual; abstract; procedure DoBeforeConnect; virtual; procedure DoAfterConnect; virtual; @@ -1951,6 +1952,7 @@ begin // Characters in identifiers which don't need to be quoted FIdentCharsNoQuote := ['A'..'Z', 'a'..'z', '0'..'9', '_']; FMaxRowsPerInsert := 10000; + FCaseSensitivity := 0; end; @@ -2396,6 +2398,7 @@ begin if FServerVersionUntouched.IsEmpty then begin FServerVersionUntouched := DecodeAPIString(FLib.mysql_get_server_info(FHandle)); end; + FCaseSensitivity := MakeInt(GetSessionVariable('lower_case_table_names', IntToStr(FCaseSensitivity))); if FDatabase <> '' then begin tmpdb := FDatabase; @@ -5274,13 +5277,9 @@ end; function TDBConnection.IdentifierEquals(Ident1, Ident2: String): Boolean; -var - CaseSensitivity: Integer; begin // Compare only name of identifier, in the case fashion the server tells us - // 1 is probably a bad default value, as this expects the server to run on Windows - CaseSensitivity := MakeInt(GetSessionVariable('lower_case_table_names', '1')); - case CaseSensitivity of + case FCaseSensitivity of 0: Result := Ident1 = Ident2; else Result := CompareText(Ident1, Ident2) = 0; end; @@ -9467,7 +9466,7 @@ begin if (not Assigned(CompareTo)) or (CompareTo = nil) then begin Result := False; end else begin - Result := (Name = CompareTo.Name) + Result := FConnection.IdentifierEquals(Name, CompareTo.Name) and (NodeType = CompareTo.NodeType) and (Database = CompareTo.Database) and (Schema = CompareTo.Schema)