Fulfill rfe #750: Field editor - allow non quoted literals for default value

This commit is contained in:
Ansgar Becker
2008-09-17 20:25:00 +00:00
parent 159c175375
commit b9724a5aaf
3 changed files with 70 additions and 24 deletions

View File

@ -1842,6 +1842,7 @@ var
dummy: Boolean; dummy: Boolean;
hasCommentColumn: Boolean; hasCommentColumn: Boolean;
SelectedCaptions: WideStrings.TWideStringList; SelectedCaptions: WideStrings.TWideStringList;
defaultVal: WideString;
begin begin
// Table-Properties // Table-Properties
dataselected := false; dataselected := false;
@ -1894,8 +1895,12 @@ begin
else else
// No default value. // No default value.
VTRowDataListColumns[i-1].Captions.Add('') VTRowDataListColumns[i-1].Captions.Add('')
else else begin
VTRowDataListColumns[i-1].Captions.Add('''' + FSelectedTableColumns.FieldByName('Default').AsWideString + ''''); defaultVal := FSelectedTableColumns.FieldByName('Default').AsWideString;
if UpperCase(defaultVal) <> 'CURRENT_TIMESTAMP' then
defaultVal := '''' + defaultVal + '''';
VTRowDataListColumns[i-1].Captions.Add(defaultVal);
end;
VTRowDataListColumns[i-1].Captions.Add( FSelectedTableColumns.FieldByName('Extra').AsWideString ); VTRowDataListColumns[i-1].Captions.Add( FSelectedTableColumns.FieldByName('Extra').AsWideString );
if hasCommentColumn then if hasCommentColumn then

View File

@ -73,7 +73,7 @@ object FieldEditForm: TFieldEditForm
end end
object lblComment: TLabel object lblComment: TLabel
Left = 8 Left = 8
Top = 136 Top = 160
Width = 49 Width = 49
Height = 13 Height = 13
Caption = '&Comment:' Caption = '&Comment:'
@ -91,7 +91,7 @@ object FieldEditForm: TFieldEditForm
end end
object EditDefault: TTntEdit object EditDefault: TTntEdit
Left = 88 Left = 88
Top = 109 Top = 132
Width = 192 Width = 192
Height = 21 Height = 21
TabOrder = 5 TabOrder = 5
@ -125,22 +125,22 @@ object FieldEditForm: TFieldEditForm
end end
object GroupBoxAttributes: TGroupBox object GroupBoxAttributes: TGroupBox
Left = 8 Left = 8
Top = 168 Top = 184
Width = 272 Width = 272
Height = 113 Height = 97
Caption = 'Attributes' Caption = 'Attributes'
TabOrder = 7 TabOrder = 7
object CheckBoxBinary: TCheckBox object CheckBoxBinary: TCheckBox
Left = 16 Left = 9
Top = 24 Top = 21
Width = 65 Width = 65
Height = 17 Height = 17
Caption = 'Binary' Caption = 'Binary'
TabOrder = 0 TabOrder = 0
end end
object CheckBoxUnsigned: TCheckBox object CheckBoxUnsigned: TCheckBox
Left = 16 Left = 9
Top = 48 Top = 45
Width = 65 Width = 65
Height = 17 Height = 17
Caption = 'Unsigned' Caption = 'Unsigned'
@ -148,8 +148,8 @@ object FieldEditForm: TFieldEditForm
OnClick = CheckBoxUnsignedClick OnClick = CheckBoxUnsignedClick
end end
object CheckBoxZerofill: TCheckBox object CheckBoxZerofill: TCheckBox
Left = 16 Left = 9
Top = 72 Top = 69
Width = 57 Width = 57
Height = 17 Height = 17
Caption = 'Zerofill' Caption = 'Zerofill'
@ -157,16 +157,16 @@ object FieldEditForm: TFieldEditForm
OnClick = CheckBoxZerofillClick OnClick = CheckBoxZerofillClick
end end
object CheckBoxNotNull: TCheckBox object CheckBoxNotNull: TCheckBox
Left = 128 Left = 121
Top = 24 Top = 21
Width = 69 Width = 69
Height = 17 Height = 17
Caption = 'Not Null' Caption = 'Not Null'
TabOrder = 3 TabOrder = 3
end end
object CheckBoxAutoIncrement: TCheckBox object CheckBoxAutoIncrement: TCheckBox
Left = 128 Left = 121
Top = 48 Top = 45
Width = 97 Width = 97
Height = 17 Height = 17
Caption = 'AutoIncrement' Caption = 'AutoIncrement'
@ -184,11 +184,25 @@ object FieldEditForm: TFieldEditForm
end end
object EditComment: TTntEdit object EditComment: TTntEdit
Left = 88 Left = 88
Top = 133 Top = 157
Width = 192 Width = 192
Height = 21 Height = 21
TabOrder = 6 TabOrder = 6
end end
object comboDefault: TComboBox
Left = 88
Top = 109
Width = 192
Height = 21
Style = csDropDownList
ItemHeight = 13
TabOrder = 8
OnChange = comboDefaultChange
Items.Strings = (
'NULL'
'CURRENT_TIMESTAMP'
'Custom string ...')
end
end end
object tabIndexes: TTabSheet object tabIndexes: TTabSheet
Caption = 'Indexes' Caption = 'Indexes'

View File

@ -11,7 +11,7 @@ interface
uses uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ImgList, ToolWin, ExtCtrls, Buttons, VirtualTrees, StdCtrls, ComCtrls, ImgList, ToolWin, ExtCtrls, Buttons, VirtualTrees,
PngSpeedButton, TntStdCtrls, WideStrings; PngSpeedButton, TntStdCtrls, WideStrings, WideStrUtils;
type type
TFieldEditorMode = (femFieldAdd,femFieldUpdate,femIndexEditor); TFieldEditorMode = (femFieldAdd,femFieldUpdate,femIndexEditor);
@ -56,6 +56,7 @@ type
btnDatatypeHelp: TButton; btnDatatypeHelp: TButton;
lblComment: TLabel; lblComment: TLabel;
EditComment: TTntEdit; EditComment: TTntEdit;
comboDefault: TComboBox;
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure btnDatatypeHelpClick(Sender: TObject); procedure btnDatatypeHelpClick(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
@ -85,6 +86,7 @@ type
TShiftState); TShiftState);
procedure ComboBoxTypeKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure ComboBoxTypeKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure listClick(Sender: TObject); procedure listClick(Sender: TObject);
procedure comboDefaultChange(Sender: TObject);
private private
{ Private declarations } { Private declarations }
TempKeys : TStringList; TempKeys : TStringList;
@ -104,6 +106,12 @@ type
{$I const.inc} {$I const.inc}
const
DEFAULT_NULL = 0;
DEFAULT_CURTS = 1;
DEFAULT_CUSTOM = 2;
implementation implementation
uses uses
@ -204,6 +212,7 @@ begin
EditFieldName.Text := 'Enter column name'; EditFieldName.Text := 'Enter column name';
ComboBoxType.ItemIndex := 1; ComboBoxType.ItemIndex := 1;
EditLength.Text := ''; EditLength.Text := '';
comboDefault.ItemIndex := DEFAULT_NULL;
EditDefault.Text := ''; EditDefault.Text := '';
EditComment.Text := ''; EditComment.Text := '';
CheckBoxUnsigned.Checked := true; CheckBoxUnsigned.Checked := true;
@ -220,7 +229,15 @@ begin
NodeData := ListColumns.GetNodeData(ListColumns.GetFirstSelected); NodeData := ListColumns.GetNodeData(ListColumns.GetFirstSelected);
EditFieldname.Text := FFieldName; EditFieldname.Text := FFieldName;
EditLength.Text := getEnumValues( NodeData.Captions[1] ); EditLength.Text := getEnumValues( NodeData.Captions[1] );
EditDefault.Text := NodeData.Captions[3]; editDefault.Text := '';
if NodeData.Captions[3] = 'NULL' then
comboDefault.ItemIndex := DEFAULT_NULL
else if NodeData.Captions[3] = 'CURRENT_TIMESTAMP' then
comboDefault.ItemIndex := DEFAULT_CURTS
else begin
comboDefault.ItemIndex := DEFAULT_CUSTOM;
EditDefault.Text := WideDequotedStr(NodeData.Captions[3], '''');
end;
EditComment.Text := NodeData.Captions[5]; EditComment.Text := NodeData.Captions[5];
// extract field type // extract field type
@ -410,13 +427,19 @@ begin
end; end;
// DEFAULT // DEFAULT
EditDefault.Enabled := FieldType.HasDefault; comboDefault.Enabled := FieldType.HasDefault;
lblDefault.Enabled := EditDefault.Enabled; EditDefault.Enabled := FieldType.HasDefault and (comboDefault.ItemIndex = DEFAULT_CUSTOM);
lblDefault.Enabled := comboDefault.Enabled;
if not EditDefault.Enabled then if not EditDefault.Enabled then
EditDefault.Text := ''; // Ensure text is empty EditDefault.Text := ''; // Ensure text is empty
end; end;
procedure TFieldEditForm.comboDefaultChange(Sender: TObject);
begin
editDefault.Enabled := TCombobox(Sender).ItemIndex = DEFAULT_CUSTOM;
end;
{*** {***
Add or update field Add or update field
@ -472,10 +495,14 @@ begin
if CheckBoxZerofill.Checked = true then if CheckBoxZerofill.Checked = true then
strAttributes := strAttributes + ' ZEROFILL'; strAttributes := strAttributes + ' ZEROFILL';
if (length(EditDefault.Text) > 0) and EditDefault.Enabled then if comboDefault.Enabled then
begin begin
strDefault := ' DEFAULT '; case comboDefault.ItemIndex of
strDefault := strDefault + EditDefault.Text DEFAULT_NULL: strDefault := 'NULL';
DEFAULT_CURTS: strDefault := 'CURRENT_TIMESTAMP';
DEFAULT_CUSTOM: strDefault := esc(editDefault.Text);
end;
strDefault := ' DEFAULT '+strDefault;
end; end;
if CheckBoxNotNull.Enabled then if CheckBoxNotNull.Enabled then