Detect empty string without quotes as text default type. See https://www.heidisql.com/forum.php?t=35365

This commit is contained in:
Ansgar Becker
2020-01-13 11:53:17 +01:00
parent 9b10d77c5a
commit 245e033bb0

View File

@ -4561,7 +4561,7 @@ begin
Col.DefaultText := 'AUTO_INCREMENT'; Col.DefaultText := 'AUTO_INCREMENT';
end else if ColQuery.IsNull('COLUMN_DEFAULT') then begin end else if ColQuery.IsNull('COLUMN_DEFAULT') then begin
Col.DefaultType := cdtNothing; Col.DefaultType := cdtNothing;
end else if DefText.StartsWith('''') then begin end else if DefText.StartsWith('''') or DefText.IsEmpty then begin
Col.DefaultType := cdtText; Col.DefaultType := cdtText;
Col.DefaultText := ExtractLiteral(DefText, ''); Col.DefaultText := ExtractLiteral(DefText, '');
end else begin end else begin
@ -4593,7 +4593,7 @@ begin
Result := inherited; Result := inherited;
Exit; Exit;
end; end;
// Fallback for old MySQL pre-5.0 servers // !!Fallback!! for old MySQL pre-5.0 servers
Result := TTableColumnList.Create(True); Result := TTableColumnList.Create(True);
ColQuery := GetResults('SHOW FULL COLUMNS FROM '+QuoteIdent(Table.Database)+'.'+QuoteIdent(Table.Name)); ColQuery := GetResults('SHOW FULL COLUMNS FROM '+QuoteIdent(Table.Database)+'.'+QuoteIdent(Table.Name));
while not ColQuery.Eof do begin while not ColQuery.Eof do begin
@ -8623,7 +8623,6 @@ end;
function TTableColumn.SQLCode(OverrideCollation: String=''; Parts: TColumnParts=[cpAll]): String; function TTableColumn.SQLCode(OverrideCollation: String=''; Parts: TColumnParts=[cpAll]): String;
var var
IsVirtual: Boolean; IsVirtual: Boolean;
Text: String;
function InParts(Part: TColumnPart): Boolean; function InParts(Part: TColumnPart): Boolean;
begin begin
@ -8658,10 +8657,9 @@ begin
if InParts(cpDefault) then begin if InParts(cpDefault) then begin
if DefaultType <> cdtNothing then begin if DefaultType <> cdtNothing then begin
Text := esc(DefaultText);
case DefaultType of case DefaultType of
// cdtNothing: leave out whole clause // cdtNothing: leave out whole clause
cdtText: Result := Result + 'DEFAULT '+esc(DefaultText); cdtText: Result := Result + 'DEFAULT '+FConnection.EscapeString(DefaultText);
cdtNull: Result := Result + 'DEFAULT NULL'; cdtNull: Result := Result + 'DEFAULT NULL';
cdtAutoInc: Result := Result + 'AUTO_INCREMENT'; cdtAutoInc: Result := Result + 'AUTO_INCREMENT';
cdtExpression: Result := Result + 'DEFAULT '+DefaultText; cdtExpression: Result := Result + 'DEFAULT '+DefaultText;
@ -8684,16 +8682,16 @@ begin
if InParts(cpComment) then begin if InParts(cpComment) then begin
if (Comment <> '') and FConnection.Parameters.IsMySQL then if (Comment <> '') and FConnection.Parameters.IsMySQL then
Result := Result + 'COMMENT ' + esc(Comment) + ' '; Result := Result + 'COMMENT ' + FConnection.EscapeString(Comment) + ' ';
end; end;
if InParts(cpCollation) then begin if InParts(cpCollation) then begin
if Collation <> '' then begin if Collation <> '' then begin
Result := Result + 'COLLATE '; Result := Result + 'COLLATE ';
if OverrideCollation <> '' then if OverrideCollation <> '' then
Result := Result + esc(OverrideCollation) + ' ' Result := Result + FConnection.EscapeString(OverrideCollation) + ' '
else else
Result := Result + esc(Collation) + ' '; Result := Result + FConnection.EscapeString(Collation) + ' ';
end; end;
end; end;