Default value improvements

This commit is contained in:
Jamie Cameron
2008-08-27 16:35:39 +00:00
parent 84488e4329
commit 4ada1905e4
4 changed files with 35 additions and 7 deletions

View File

@ -73,3 +73,5 @@ Display a more friendly error if a scheduled backup cannot be performed because
The root password can be more easily change by the new 'Change Administration Password' page.
---- Changes since 1.420 ----
Display the number of tables and records created when executing SQL for a restore.
---- Changes since 1.430 ----
Improved the input for setting the default value for new fields, and added support for CURRENT_TIMESTAMP.

View File

@ -69,7 +69,7 @@ elsif ($type eq 'date' || $type eq 'datetime' || $type eq 'time' ||
elsif ($type ne 'varchar' && $type ne 'char' && $in{'type'}) {
# Size is optional for new fields of most types
print &ui_table_row($text{'field_size'},
&ui_opt_textbox("size", undef, $text{'default'}, 10));
&ui_opt_textbox("size", undef, 10, $text{'default'}));
}
else {
# Size is one value
@ -114,9 +114,19 @@ print &ui_table_row($text{'field_null'},
[ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
# Default value
$defmode = $f->{'default'} eq 'NULL' ? 0 :
$f->{'default'} eq 'CURRENT_TIMESTAMP' ? 2 :
$f->{'default'} eq '' ? 3 : 1;
@defs = ( [ 3, $in{'type'} ? $text{'field_defnone'}
: $text{'field_defleave'} ],
[ 0, 'NULL' ] );
if ($type eq "timestamp") {
push(@defs, [ 2, $text{'field_current'} ]);
}
push(@defs, [ 1, $text{'field_defval'}." ".
&ui_textbox("default", $defmode == 1 ? $f->{'default'} : "", 40) ]);
print &ui_table_row($text{'field_default'},
&ui_textbox("default", $f->{'default'} eq 'NULL' ? '' :
$f->{'default'}, 40));
&ui_radio("default_def", $defmode, \@defs));
# Part of primary key
print &ui_table_row($text{'field_key'},

View File

@ -164,6 +164,10 @@ field_ascii=Case insensitive
field_binary=Case sensitive
field_null=Allow nulls?
field_default=Default value
field_current=Current time
field_defval=Value
field_defnone=No default
field_defleave=Don't change
field_dmode0=None
field_dmode1=Null
field_key=Part of primary key?

View File

@ -8,6 +8,20 @@ require './mysql-lib.pl';
$access{'edonly'} && &error($text{'dbase_ecannot'});
&error_setup($text{'field_err'});
# Build default clause
if ($in{'default_def'} == 0) {
$default = "default NULL";
}
elsif ($in{'default_def'} == 2) {
$default = "default CURRENT_TIMESTAMP";
}
elsif ($in{'default_def'} == 3) {
$default = $in{'new'} ? "" : "default none";
}
else {
$default = "default '$in{'default'}'";
}
if ($in{'delete'}) {
# delete this field
&execute_sql_logged($in{'db'},
@ -23,8 +37,7 @@ elsif ($in{'new'}) {
$sql = sprintf "alter table %s add %s %s%s %s %s %s",
&quotestr($in{'table'}), &quotestr($in{'field'}), $in{'type'},
$size, $in{'null'} ? '' : 'not null',
$in{'default'} ne '' ? "default '$in{'default'}'"
: "default NULL",
$default,
$in{'ext'};
&execute_sql_logged($in{'db'}, $sql);
&webmin_log("create", "field", $in{'field'}, \%in);
@ -37,8 +50,7 @@ else {
$sql = sprintf "alter table %s modify %s %s%s %s %s %s",
&quotestr($in{'table'}), &quotestr($in{'old'}),
$in{'type'}, $size, $in{'null'} ? 'null' : 'not null',
$in{'default'} ne '' ? "default '$in{'default'}'" :
$in{'null'} ? "default NULL" : "",
$default,
$in{'ext'};
&execute_sql_logged($in{'db'}, $sql);
if ($in{'old'} ne $in{'field'} ||