Fix issue #1132: Error on Create Table in the Table Editor

This commit is contained in:
Ansgar Becker
2009-05-16 06:00:12 +00:00
parent 5209995eed
commit ea71eb13f9
2 changed files with 21 additions and 9 deletions

View File

@ -181,6 +181,10 @@ type
procedure SetBounds(R: TRect); virtual; stdcall; procedure SetBounds(R: TRect); virtual; stdcall;
end; end;
function GetColumnDefaultType(var Text: WideString): TColumnDefaultType;
implementation implementation
@ -1199,4 +1203,11 @@ begin
end; end;
function GetColumnDefaultType(var Text: WideString): TColumnDefaultType;
begin
Result := TColumnDefaultType(MakeInt(Copy(Text, 1, 1)));
Text := Copy(Text, 2, Length(Text)-1);
end;
end. end.

View File

@ -384,7 +384,7 @@ end;
function TfrmTableEditor.ComposeAlterStatement: WideString; function TfrmTableEditor.ComposeAlterStatement: WideString;
var var
Specs, Props, IndexesComposed, OldIndexesComposed: TWideStringlist; Specs, Props, IndexesComposed, OldIndexesComposed: TWideStringlist;
ColSpec, IndexSQL: WideString; ColSpec, IndexSQL, DefaultText: WideString;
i, j: Integer; i, j: Integer;
AddIt, DropIt: Boolean; AddIt, DropIt: Boolean;
dt: TMySQLDataTypeRecord; dt: TMySQLDataTypeRecord;
@ -430,9 +430,10 @@ begin
ColSpec := ColSpec + ' NOT'; ColSpec := ColSpec + ' NOT';
ColSpec := ColSpec + ' NULL'; ColSpec := ColSpec + ' NULL';
if Props[4] <> '' then begin if Props[4] <> '' then begin
DefaultType := TColumnDefaultType(MakeInt(Copy(Props[4], 1, 1))); DefaultText := Props[4];
DefaultType := GetColumnDefaultType(DefaultText);
case DefaultType of case DefaultType of
cdtText: ColSpec := ColSpec + ' DEFAULT '+esc(Copy(Props[4], 2, Length(Props[4])-1)); cdtText: ColSpec := ColSpec + ' DEFAULT '+esc(DefaultText);
cdtNull: ColSpec := ColSpec + ' DEFAULT NULL'; cdtNull: ColSpec := ColSpec + ' DEFAULT NULL';
cdtCurTS: ColSpec := ColSpec + ' DEFAULT CURRENT_TIMESTAMP'; cdtCurTS: ColSpec := ColSpec + ' DEFAULT CURRENT_TIMESTAMP';
cdtAutoInc: ColSpec := ColSpec + ' AUTO_INCREMENT'; cdtAutoInc: ColSpec := ColSpec + ' AUTO_INCREMENT';
@ -502,6 +503,7 @@ var
ColProps: TWideStringlist; ColProps: TWideStringlist;
dt: TMySQLDataTypeRecord; dt: TMySQLDataTypeRecord;
DefaultType: TColumnDefaultType; DefaultType: TColumnDefaultType;
DefaultText: WideString;
begin begin
// Compose CREATE query, called by buttons and for SQL code tab // Compose CREATE query, called by buttons and for SQL code tab
Result := 'CREATE TABLE '+Mainform.mask(editName.Text)+' ('+CRLF; Result := 'CREATE TABLE '+Mainform.mask(editName.Text)+' ('+CRLF;
@ -516,12 +518,11 @@ begin
if not StrToBool(ColProps[3]) then if not StrToBool(ColProps[3]) then
Result := Result + ' NOT'; Result := Result + ' NOT';
Result := Result + ' NULL'; Result := Result + ' NULL';
if ColProps[4] <> '' then
Result := Result + ' DEFAULT '+esc(ColProps[4]);
if ColProps[4] <> '' then begin if ColProps[4] <> '' then begin
DefaultType := TColumnDefaultType(MakeInt(Copy(ColProps[4], 1, 1))); DefaultText := ColProps[4];
DefaultType := GetColumnDefaultType(DefaultText);
case DefaultType of case DefaultType of
cdtText: Result := Result + ' DEFAULT '+esc(Copy(ColProps[4], 2, Length(ColProps[4])-1)); cdtText: Result := Result + ' DEFAULT '+esc(DefaultText);
cdtNull: Result := Result + ' DEFAULT NULL'; cdtNull: Result := Result + ' DEFAULT NULL';
cdtCurTS: Result := Result + ' DEFAULT CURRENT_TIMESTAMP'; cdtCurTS: Result := Result + ' DEFAULT CURRENT_TIMESTAMP';
cdtAutoInc: Result := Result + ' AUTO_INCREMENT'; cdtAutoInc: Result := Result + ' AUTO_INCREMENT';
@ -945,8 +946,8 @@ begin
6: begin 6: begin
DefaultEditor := TColumnDefaultEditorLink.Create; DefaultEditor := TColumnDefaultEditorLink.Create;
Props := TWideStringlist(Columns.Objects[Node.Index]); Props := TWideStringlist(Columns.Objects[Node.Index]);
DefaultEditor.DefaultType := TColumnDefaultType(MakeInt(Copy(Props[Column-2], 0, 1))); DefaultEditor.DefaultText := Props[Column-2];
DefaultEditor.DefaultText := Copy(Props[Column-2], 2, Length(Props[Column-2])-1); DefaultEditor.DefaultType := GetColumnDefaultType(DefaultEditor.DefaultText);
EditLink := DefaultEditor; EditLink := DefaultEditor;
end end
else else