Patch from Slavin Rezic <srezic@cpan.org> to prevent quoting around numeric defaults...
authorivan <ivan>
Thu, 3 Jan 2008 10:49:23 +0000 (10:49 +0000)
committerivan <ivan>
Thu, 3 Jan 2008 10:49:23 +0000 (10:49 +0000)
Changes
DBSchema.pm
DBSchema/Column.pm
DBSchema/DBD/Pg.pm

diff --git a/Changes b/Changes
index b1ef494..55a349b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension DBIx::DBSchema.
 
+0.37 unreleased
+        - Patch from Slavin Rezic <srezic@cpan.org> 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!
index 8c89d1c..d2bdd35 100644 (file)
@@ -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;
index 431e69c..b13d5c0 100644 (file)
@@ -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+)?$/
index 02fe8d9..fae68e1 100644 (file)
@@ -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 <ivan-dbix-dbschema@420.am>