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. The root password can be more easily change by the new 'Change Administration Password' page.
---- Changes since 1.420 ---- ---- Changes since 1.420 ----
Display the number of tables and records created when executing SQL for a restore. 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'}) { elsif ($type ne 'varchar' && $type ne 'char' && $in{'type'}) {
# Size is optional for new fields of most types # Size is optional for new fields of most types
print &ui_table_row($text{'field_size'}, print &ui_table_row($text{'field_size'},
&ui_opt_textbox("size", undef, $text{'default'}, 10)); &ui_opt_textbox("size", undef, 10, $text{'default'}));
} }
else { else {
# Size is one value # Size is one value
@ -114,9 +114,19 @@ print &ui_table_row($text{'field_null'},
[ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ])); [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
# Default value # 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'}, print &ui_table_row($text{'field_default'},
&ui_textbox("default", $f->{'default'} eq 'NULL' ? '' : &ui_radio("default_def", $defmode, \@defs));
$f->{'default'}, 40));
# Part of primary key # Part of primary key
print &ui_table_row($text{'field_key'}, print &ui_table_row($text{'field_key'},

View File

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

View File

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