X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=DBSchema%2FColumn.pm;h=0d001595083f274a6315bf8669b0b99d494fdf58;hb=1041236795634d90ecdbb132935193602f83dd34;hp=b13d5c0033ffc3b779cd28bc615d1d377a08d8bc;hpb=67bdf8ab29e1fe0b2a057d9955a30bb363cda1f6;p=DBIx-DBSchema.git diff --git a/DBSchema/Column.pm b/DBSchema/Column.pm index b13d5c0..0d00159 100644 --- a/DBSchema/Column.pm +++ b/DBSchema/Column.pm @@ -5,7 +5,7 @@ use vars qw($VERSION); use Carp; use DBIx::DBSchema::_util qw(_load_driver _dbh); -$VERSION = '0.12'; +$VERSION = '0.13'; =head1 NAME @@ -267,7 +267,10 @@ sub line { my $default; my $orig_default = $self->default; if ( $driver_class->can("_column_value_needs_quoting") ) { - if ($driver_class->_column_value_needs_quoting($self)) { + if ( $driver_class->_column_value_needs_quoting($self) + && !ref($self->default) + ) + { $default = $dbh->quote($self->default); } else { $default = ref($self->default) ? ${$self->default} : $self->default; @@ -429,35 +432,51 @@ sub sql_alter_column { my $dbd = "DBIx::DBSchema::DBD::$driver"; my $hashref = $dbd->alter_column_callback( $dbh, $table, $self, $new ); - # change the name... + if ( $hashref->{'sql_alter'} ) { - # change the type... - - if ( $hashref->{'sql_alter_null' } ) { - - push @sql, $hashref->{'sql_alter_null'}; + push @sql, $hashref->{'sql_alter'}; } else { - # change nullability from NOT NULL to NULL - if ( ! $self->null && $new->null ) { - - push @sql, "ALTER TABLE $table ALTER COLUMN $name DROP NOT NULL"; - + # change the name... + # not yet implemented. how do we tell which old column it was? + + # change the type... + if ( $hashref->{'sql_alter_type'} ) { + push @sql, $hashref->{'sql_alter_type'}; } - - # change nullability from NULL to NOT NULL... - # this one could be more complicated, need to set a DEFAULT value and update - # the table first... - if ( $self->null && ! $new->null ) { - - push @sql, "ALTER TABLE $table ALTER COLUMN $name SET NOT NULL"; - + + # change nullability... + + if ( $hashref->{'sql_alter_null'} ) { + + push @sql, $hashref->{'sql_alter_null'}; + + } else { + + # change nullability from NOT NULL to NULL + if ( ! $self->null && $new->null ) { + + push @sql, "ALTER TABLE $table ALTER COLUMN $name DROP NOT NULL"; + + } + + # change nullability from NULL to NOT NULL... + # this one could be more complicated, need to set a DEFAULT value and update + # the table first... + if ( $self->null && ! $new->null ) { + + push @sql, "ALTER TABLE $table ALTER COLUMN $name SET NOT NULL"; + + } + } + # change default + + # change other stuff... + } - - # change other stuff... @sql;