Permalink
Browse files

Fix comparison of table names on servers with lower_case_table_names=…

…1 or 2 (both insensitive). Affects SQL export, which is calling PrepareColumnAttributes since recently. Closes #168.
  • Loading branch information...
ansgarbecker committed Jun 26, 2018
1 parent d8c5007 commit 3576f764382ce32af243991c4c82bd2d5c618f05
Showing with 24 additions and 1 deletion.
  1. +24 −1 source/dbconnection.pas
@@ -438,6 +438,7 @@ TDBConnection = class(TComponent)
property Datatypes: TDBDataTypeArray read FDatatypes;
property Favorites: TStringList read FFavorites;
function GetLockedTableCount(db: String): Integer;
function IdentifierEquals(Ident1, Ident2: String): Boolean;
published
property Active: Boolean read FActive write SetActive default False;
property Database: String read FDatabase write SetDatabase;
@@ -4063,6 +4064,28 @@ function TDBConnection.GetLockedTableCount(db: String): Integer;
end;
function TDBConnection.IdentifierEquals(Ident1, Ident2: String): Boolean;
var
Vars: TDBQuery;
CaseSensitivity: Integer;
begin
// Compare only name of identifier, in the case fashion the server tells us
Vars := GetSessionVariables(False);
CaseSensitivity := 1; // probably a bad default value, as this expects the server to run on Windows
while not Vars.Eof do begin
if Vars.Col(0) = 'lower_case_table_names' then begin
CaseSensitivity := MakeInt(Vars.Col(1));
Break;
end;
Vars.Next;
end;
case CaseSensitivity of
0: Result := Ident1 = Ident2;
else Result := CompareText(Ident1, Ident2) = 0;
end;
end;
function TMySQLConnection.GetRowCount(Obj: TDBObject): Int64;
var
Rows: String;
@@ -6381,7 +6404,7 @@ procedure TDBQuery.PrepareColumnAttributes;
DB := Connection.Database;
DBObjects := Connection.GetDBObjects(DB);
for LObj in DBObjects do begin
if (LObj.NodeType in [lntTable, lntView]) and (LObj.Name = TableName) then begin
if (LObj.NodeType in [lntTable, lntView]) and Connection.IdentifierEquals(LObj.Name, TableName) then begin
Obj := LObj;
break;
end;

2 comments on commit 3576f76

@fifonik

This comment has been minimized.

fifonik replied Jun 27, 2018

Is not it more optimal to have FCaseSensitive : Boolean property on Connection object and calculate it only once?
If I understand correctly, with current implementation all environment variables are scanned on every identifiers comparison.

Alternatively, case sensitivity could be detected outside of "for LObj in DBObjects" loop and to be passed into IdentifierEquals as optional parameter.

@ansgarbecker

This comment has been minimized.

Collaborator

ansgarbecker replied Jun 27, 2018

Yes, I thought the same short after committing that. Will check that.

Please sign in to comment.