From 7be1f1c90805dc6c1845434fc215f9f07199db75 Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Fri, 15 Apr 2005 09:31:35 +0000 Subject: Bug 290405: bz_add_column needs a way to specify an initial value Patch By Max Kanat-Alexander r=Tomas.Kopal, a=justdave --- Bugzilla/DB/Schema.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'Bugzilla/DB/Schema.pm') 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 +=item C 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 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 { -- cgit v1.2.3-24-g4f1b