From b8a52445f2a1bdae86e16d4a3e9aa9d2b709c333 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 3 Jan 2008 10:49:23 +0000 Subject: [PATCH] Patch from Slavin Rezic to prevent quoting around numeric defaults in Pg. --- Changes | 4 ++++ DBSchema.pm | 2 +- DBSchema/Column.pm | 13 ++++++++++--- DBSchema/DBD/Pg.pm | 19 ++++++++++++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index b1ef494..55a349b 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Perl extension DBIx::DBSchema. +0.37 unreleased + - Patch from Slavin Rezic to prevent quoting around + numeric defaults in Pg. + 0.36 Thu Dec 13 17:49:35 PST 2007 - Patch from ISHIGAKI@cpan.org to suppress unnecessary warnings about undefined local_options, thanks! diff --git a/DBSchema.pm b/DBSchema.pm index 8c89d1c..d2bdd35 100644 --- a/DBSchema.pm +++ b/DBSchema.pm @@ -10,7 +10,7 @@ use DBIx::DBSchema::Column; use DBIx::DBSchema::ColGroup::Unique; use DBIx::DBSchema::ColGroup::Index; -$VERSION = "0.36"; +$VERSION = "0.37_01"; $VERSION = eval $VERSION; # modperlstyle: convert the string into a number $DEBUG = 0; diff --git a/DBSchema/Column.pm b/DBSchema/Column.pm index 431e69c..b13d5c0 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.11'; +$VERSION = '0.12'; =head1 NAME @@ -248,13 +248,14 @@ sub line { my($self, $dbh) = ( shift, _dbh(@_) ); my $driver = $dbh ? _load_driver($dbh) : ''; + my $driver_class = "DBIx::DBSchema::DBD::${driver}"; ## # type mapping ## my %typemap; - %typemap = eval "\%DBIx::DBSchema::DBD::${driver}::typemap" if $driver; + %typemap = eval "\%${driver_class}::typemap" if $driver; my $type = defined( $typemap{uc($self->type)} ) ? $typemap{uc($self->type)} : $self->type; @@ -265,7 +266,13 @@ sub line { my $default; my $orig_default = $self->default; - if ( defined($self->default) && !ref($self->default) && $self->default ne '' + if ( $driver_class->can("_column_value_needs_quoting") ) { + if ($driver_class->_column_value_needs_quoting($self)) { + $default = $dbh->quote($self->default); + } else { + $default = ref($self->default) ? ${$self->default} : $self->default; + } + } elsif ( defined($self->default) && !ref($self->default) && $self->default ne '' && ref($dbh) # false laziness: nicked from FS::Record::_quote && ( $self->default !~ /^\-?\d+(\.\d+)?$/ diff --git a/DBSchema/DBD/Pg.pm b/DBSchema/DBD/Pg.pm index 02fe8d9..fae68e1 100644 --- a/DBSchema/DBD/Pg.pm +++ b/DBSchema/DBD/Pg.pm @@ -5,7 +5,7 @@ use vars qw($VERSION @ISA %typemap); use DBD::Pg 1.32; use DBIx::DBSchema::DBD; -$VERSION = '0.12'; +$VERSION = '0.13'; @ISA = qw(DBIx::DBSchema::DBD); die "DBD::Pg version 1.32 or 1.41 (or later) required--". @@ -263,6 +263,23 @@ sub alter_column_callback { } +sub _column_value_needs_quoting { + my($proto, $col) = @_; + $col->type !~ m{^( + int(?:2|4|8)? + | smallint + | integer + | bigint + | (?:numeric|decimal)(?:\(\d+(?:\s*\,\s*\d+\))?)? + | real + | double\s+precision + | float(?:\(\d+\))? + | serial(?:4|8)? + | bigserial + )$}x; +} + + =head1 AUTHOR Ivan Kohler -- 2.11.0