From: Dagfinn Ilmari Mannsåker Date: Thu, 20 May 2010 23:15:48 +0000 (+0100) Subject: fix for negative numeric default values X-Git-Tag: 0.07000~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1b3e8f7a3780171fc24656cf24177089bcc1267f;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix for negative numeric default values --- diff --git a/Changes b/Changes index bee1d26..7bb4147 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - fix for negative numeric default values - sequence is detected for Oracle - fix for SQLite is_auto_increment detection when table is empty (hobbs) - rescan now reloads all tables diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm index bff0091..796fd52 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm @@ -35,7 +35,8 @@ sub _columns_info_for { $info->{default_value} = $1; } else { - $info->{default_value} = $def =~ /^\d/ ? $def : \$def; + # Some DBs (eg. Pg) put brackets around negative number defaults + $info->{default_value} = $def =~ /^\(?(-?\d.*?)\)?$/ ? $1 : \$def; } } } diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 26a14ad..af46977 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -88,7 +88,7 @@ sub run_tests { my $extra_count = $self->{extra}{count} || 0; - plan tests => @connect_info * (179 + $extra_count + ($self->{data_type_tests}{test_count} || 0)); + plan tests => @connect_info * (181 + $extra_count + ($self->{data_type_tests}{test_count} || 0)); foreach my $info_idx (0..$#connect_info) { my $info = $connect_info[$info_idx]; @@ -434,11 +434,21 @@ sub test_schema { 'constant integer default', ); + is( + $class35->column_info('a_negative_int')->{default_value}, -42, + 'constant negative integer default', + ); + cmp_ok( $class35->column_info('a_double')->{default_value}, '==', 10.555, 'constant numeric default', ); + cmp_ok( + $class35->column_info('a_negative_double')->{default_value}, '==', -10.555, + 'constant negative numeric default', + ); + my $function_default = $class35->column_info('a_function')->{default_value}; isa_ok( $function_default, 'SCALAR', 'default_value for function default' ); @@ -1197,7 +1207,9 @@ sub create { id INTEGER NOT NULL PRIMARY KEY, a_varchar VARCHAR(100) DEFAULT 'foo', an_int INTEGER DEFAULT 42, + a_negative_int INTEGER DEFAULT -42, a_double DOUBLE PRECISION DEFAULT 10.555, + a_negative_double DOUBLE PRECISION DEFAULT -10.555, a_function $self->{default_function_def} ) $self->{innodb} },