mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 11:17:57 +08:00
Support default values of BIT columns in table editor and SQL export. Fixes issue #2544.
This commit is contained in:
@ -3181,7 +3181,7 @@ procedure TDBConnection.ParseTableStructure(CreateTable: String; Columns: TTable
|
||||
var
|
||||
ColSpec: String;
|
||||
rx, rxCol: TRegExpr;
|
||||
i: Integer;
|
||||
i, LiteralStart: Integer;
|
||||
InLiteral: Boolean;
|
||||
Col: TTableColumn;
|
||||
Key: TTableKey;
|
||||
@ -3317,16 +3317,17 @@ begin
|
||||
Col.DefaultType := cdtCurTS;
|
||||
Col.DefaultText := 'CURRENT_TIMESTAMP';
|
||||
Delete(ColSpec, 1, 18);
|
||||
end else if ColSpec[1] = '''' then begin
|
||||
end else if (ColSpec[1] = '''') or (Copy(ColSpec, 1, 2) = 'b''') then begin
|
||||
InLiteral := True;
|
||||
for i:=2 to Length(ColSpec) do begin
|
||||
LiteralStart := Pos('''', ColSpec)+1;
|
||||
for i:=LiteralStart to Length(ColSpec) do begin
|
||||
if ColSpec[i] = '''' then
|
||||
InLiteral := not InLiteral
|
||||
else if not InLiteral then
|
||||
break;
|
||||
end;
|
||||
Col.DefaultType := cdtText;
|
||||
Col.DefaultText := Copy(ColSpec, 2, i-3);
|
||||
Col.DefaultText := Copy(ColSpec, LiteralStart, i-LiteralStart-1);
|
||||
// A single quote gets escaped by single quote - remove the escape char - escaping is done in Save action afterwards
|
||||
Col.DefaultText := StringReplace(Col.DefaultText, '''''', '''', [rfReplaceAll]);
|
||||
Delete(ColSpec, 1, i);
|
||||
@ -5103,7 +5104,7 @@ begin
|
||||
Result := Result + ' NULL';
|
||||
end;
|
||||
if DefaultType <> cdtNothing then begin
|
||||
Result := Result + ' ' + GetColumnDefaultClause(DefaultType, DefaultText);
|
||||
Result := Result + ' ' + GetColumnDefaultClause(DefaultType, DataType.Index, DefaultText);
|
||||
Result := TrimRight(Result); // Remove whitespace for columns without default value
|
||||
end;
|
||||
if IsVirtual then
|
||||
|
@ -314,7 +314,7 @@ type
|
||||
function StringListCompareAnythingAsc(List: TStringList; Index1, Index2: Integer): Integer;
|
||||
function StringListCompareAnythingDesc(List: TStringList; Index1, Index2: Integer): Integer;
|
||||
function GetColumnDefaultType(var Text: String): TColumnDefaultType;
|
||||
function GetColumnDefaultClause(DefaultType: TColumnDefaultType; Text: String): String;
|
||||
function GetColumnDefaultClause(DefaultType: TColumnDefaultType; DataTypeIndex: TDBDatatypeIndex; Text: String): String;
|
||||
function GetImageLinkTimeStamp(const FileName: string): TDateTime;
|
||||
function IsEmpty(Str: String): Boolean;
|
||||
function IsNotEmpty(Str: String): Boolean;
|
||||
@ -2305,12 +2305,16 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function GetColumnDefaultClause(DefaultType: TColumnDefaultType; Text: String): String;
|
||||
function GetColumnDefaultClause(DefaultType: TColumnDefaultType; DataTypeIndex: TDBDatatypeIndex; Text: String): String;
|
||||
begin
|
||||
Text := esc(Text);
|
||||
// Support BIT syntax in MySQL
|
||||
if DataTypeIndex = dtBit then
|
||||
Text := 'b'+Text;
|
||||
case DefaultType of
|
||||
cdtNothing: Result := '';
|
||||
cdtText: Result := 'DEFAULT '+esc(Text);
|
||||
cdtTextUpdateTS: Result := 'DEFAULT '+esc(Text)+' ON UPDATE CURRENT_TIMESTAMP';
|
||||
cdtText: Result := 'DEFAULT '+Text;
|
||||
cdtTextUpdateTS: Result := 'DEFAULT '+Text+' ON UPDATE CURRENT_TIMESTAMP';
|
||||
cdtNull: Result := 'DEFAULT NULL';
|
||||
cdtNullUpdateTS: Result := 'DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP';
|
||||
cdtCurTS: Result := 'DEFAULT CURRENT_TIMESTAMP';
|
||||
|
@ -561,7 +561,7 @@ begin
|
||||
ColSpec := ColSpec + ' NULL';
|
||||
end;
|
||||
if Col.DefaultType <> cdtNothing then begin
|
||||
ColSpec := ColSpec + ' ' + GetColumnDefaultClause(Col.DefaultType, Col.DefaultText);
|
||||
ColSpec := ColSpec + ' ' + GetColumnDefaultClause(Col.DefaultType, Col.DataType.Index, Col.DefaultText);
|
||||
ColSpec := TrimRight(ColSpec); // Remove whitespace for columns without default value
|
||||
end;
|
||||
if IsVirtual then
|
||||
|
Reference in New Issue
Block a user