diff options
author | mkanat%kerio.com <> | 2005-04-15 09:31:35 +0000 |
---|---|---|
committer | mkanat%kerio.com <> | 2005-04-15 09:31:35 +0000 |
commit | 7be1f1c90805dc6c1845434fc215f9f07199db75 (patch) | |
tree | 300ef71ea7c797362fb4ec02794db617ec2b0eb9 /Bugzilla/DB/Schema.pm | |
parent | 6b2e132ec32b657e8f806eedc4d9f06fc66131ef (diff) | |
download | bugs-7be1f1c90805dc6c1845434fc215f9f07199db75.tar bugs-7be1f1c90805dc6c1845434fc215f9f07199db75.tar.gz bugs-7be1f1c90805dc6c1845434fc215f9f07199db75.tar.bz2 bugs-7be1f1c90805dc6c1845434fc215f9f07199db75.tar.xz bugs-7be1f1c90805dc6c1845434fc215f9f07199db75.zip |
Bug 290405: bz_add_column needs a way to specify an initial value
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=Tomas.Kopal, a=justdave
Diffstat (limited to 'Bugzilla/DB/Schema.pm')
-rw-r--r-- | Bugzilla/DB/Schema.pm | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 9ef1f6214..99127ff69 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -1359,22 +1359,30 @@ sub _get_create_index_ddl { sub get_add_column_ddl { -=item C<get_add_column_ddl($table, $column, \%definition)> +=item C<get_add_column_ddl($table, $column, \%definition, $init_value)> Description: Generate SQL to add a column to a table. Params: $table - The table containing the column. $column - The name of the column being added. \%definition - The new definition for the column, in standard C<ABSTRACT_SCHEMA> format. + $init_value - (optional) An initial value to set + the column to. Should already be SQL-quoted + if necessary. Returns: An array of SQL statements. =cut - my ($self, $table, $column, $definition) = @_; + my ($self, $table, $column, $definition, $init_value) = @_; + my @statements; + push(@statements, "ALTER TABLE $table ADD COLUMN $column " . + $self->get_type_ddl($definition)); - my $statement = "ALTER TABLE $table ADD COLUMN $column " . - $self->get_type_ddl($definition); + # XXX - Note that although this works for MySQL, most databases will fail + # before this point, if we haven't set a default. + (push(@statements, "UPDATE $table SET $column = $init_value")) + if defined $init_value; - return ($statement); + return (@statements); } sub get_add_index_ddl { |