mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Support backticks in column names, key names and foreign key names, for the table designer. Fixes issue #2292.
This commit is contained in:
@ -3283,6 +3283,8 @@ var
|
|||||||
Key: TTableKey;
|
Key: TTableKey;
|
||||||
ForeignKey: TForeignKey;
|
ForeignKey: TForeignKey;
|
||||||
Collations: TDBQuery;
|
Collations: TDBQuery;
|
||||||
|
const
|
||||||
|
QuoteReplacement = '{{}}';
|
||||||
begin
|
begin
|
||||||
Ping(True);
|
Ping(True);
|
||||||
if Assigned(Columns) then Columns.Clear;
|
if Assigned(Columns) then Columns.Clear;
|
||||||
@ -3298,6 +3300,7 @@ begin
|
|||||||
rx.Expression := '^\s+['+Quotes+']([^'+Quotes+']+)['+Quotes+']\s(\w+)';
|
rx.Expression := '^\s+['+Quotes+']([^'+Quotes+']+)['+Quotes+']\s(\w+)';
|
||||||
rxCol := TRegExpr.Create;
|
rxCol := TRegExpr.Create;
|
||||||
rxCol.ModifierI := True;
|
rxCol.ModifierI := True;
|
||||||
|
CreateTable := StringReplace(CreateTable, FQuoteChar+FQuoteChar, QuoteReplacement, [rfReplaceAll]);
|
||||||
if rx.Exec(CreateTable) then while true do begin
|
if rx.Exec(CreateTable) then while true do begin
|
||||||
if not Assigned(Columns) then
|
if not Assigned(Columns) then
|
||||||
break;
|
break;
|
||||||
@ -3315,6 +3318,7 @@ begin
|
|||||||
Col := TTableColumn.Create(Self);
|
Col := TTableColumn.Create(Self);
|
||||||
Columns.Add(Col);
|
Columns.Add(Col);
|
||||||
Col.Name := DeQuoteIdent(rx.Match[1]);
|
Col.Name := DeQuoteIdent(rx.Match[1]);
|
||||||
|
Col.Name := StringReplace(Col.Name, QuoteReplacement, FQuoteChar, [rfReplaceAll]);
|
||||||
Col.OldName := Col.Name;
|
Col.OldName := Col.Name;
|
||||||
Col.Status := esUntouched;
|
Col.Status := esUntouched;
|
||||||
Col.LengthCustomized := False;
|
Col.LengthCustomized := False;
|
||||||
@ -3459,6 +3463,7 @@ begin
|
|||||||
Keys.Add(Key);
|
Keys.Add(Key);
|
||||||
Key.Name := rx.Match[4];
|
Key.Name := rx.Match[4];
|
||||||
if Key.Name = '' then Key.Name := rx.Match[2]; // PRIMARY
|
if Key.Name = '' then Key.Name := rx.Match[2]; // PRIMARY
|
||||||
|
Key.Name := StringReplace(Key.Name, QuoteReplacement, FQuoteChar, [rfReplaceAll]);
|
||||||
Key.OldName := Key.Name;
|
Key.OldName := Key.Name;
|
||||||
Key.IndexType := rx.Match[2];
|
Key.IndexType := rx.Match[2];
|
||||||
Key.OldIndexType := Key.IndexType;
|
Key.OldIndexType := Key.IndexType;
|
||||||
@ -3474,6 +3479,7 @@ begin
|
|||||||
Key.Columns[i] := rxCol.Match[1];
|
Key.Columns[i] := rxCol.Match[1];
|
||||||
Key.SubParts.Add(rxCol.Match[3]);
|
Key.SubParts.Add(rxCol.Match[3]);
|
||||||
end;
|
end;
|
||||||
|
Key.Columns[i] := StringReplace(Key.Columns[i], QuoteReplacement, FQuoteChar, [rfReplaceAll]);
|
||||||
end;
|
end;
|
||||||
if not rx.ExecNext then
|
if not rx.ExecNext then
|
||||||
break;
|
break;
|
||||||
@ -3488,12 +3494,14 @@ begin
|
|||||||
ForeignKey := TForeignKey.Create(Self);
|
ForeignKey := TForeignKey.Create(Self);
|
||||||
ForeignKeys.Add(ForeignKey);
|
ForeignKeys.Add(ForeignKey);
|
||||||
ForeignKey.KeyName := rx.Match[1];
|
ForeignKey.KeyName := rx.Match[1];
|
||||||
|
ForeignKey.KeyName := StringReplace(ForeignKey.KeyName, QuoteReplacement, FQuoteChar, [rfReplaceAll]);
|
||||||
ForeignKey.OldKeyName := ForeignKey.KeyName;
|
ForeignKey.OldKeyName := ForeignKey.KeyName;
|
||||||
ForeignKey.KeyNameWasCustomized := True;
|
ForeignKey.KeyNameWasCustomized := True;
|
||||||
ForeignKey.ReferenceTable := StringReplace(rx.Match[3], '`', '', [rfReplaceAll]);
|
ForeignKey.ReferenceTable := StringReplace(rx.Match[3], '`', '', [rfReplaceAll]);
|
||||||
ForeignKey.ReferenceTable := StringReplace(ForeignKey.ReferenceTable, '"', '', [rfReplaceAll]);
|
ForeignKey.ReferenceTable := StringReplace(ForeignKey.ReferenceTable, '"', '', [rfReplaceAll]);
|
||||||
ForeignKey.ReferenceTable := StringReplace(ForeignKey.ReferenceTable, '[', '', [rfReplaceAll]);
|
ForeignKey.ReferenceTable := StringReplace(ForeignKey.ReferenceTable, '[', '', [rfReplaceAll]);
|
||||||
ForeignKey.ReferenceTable := StringReplace(ForeignKey.ReferenceTable, ']', '', [rfReplaceAll]);
|
ForeignKey.ReferenceTable := StringReplace(ForeignKey.ReferenceTable, ']', '', [rfReplaceAll]);
|
||||||
|
ForeignKey.ReferenceTable := StringReplace(ForeignKey.ReferenceTable, QuoteReplacement, FQuoteChar, [rfReplaceAll]);
|
||||||
ExplodeQuotedList(rx.Match[2], ForeignKey.Columns);
|
ExplodeQuotedList(rx.Match[2], ForeignKey.Columns);
|
||||||
ExplodeQuotedList(rx.Match[4], ForeignKey.ForeignColumns);
|
ExplodeQuotedList(rx.Match[4], ForeignKey.ForeignColumns);
|
||||||
if rx.Match[6] <> '' then
|
if rx.Match[6] <> '' then
|
||||||
|
Reference in New Issue
Block a user