From: Rafael Kitover Date: Fri, 5 Feb 2010 14:25:39 +0000 (-0500) Subject: fix default_value for all other backends, fix bug with quoted Pg tables from $dbh... X-Git-Tag: 0.05001~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=41968729ce9a8812e3d3ae80adbd79a85b04551b;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix default_value for all other backends, fix bug with quoted Pg tables from $dbh->tables (RT#54338), add inflate_datetime => 0 to 'timestamp' types for Sybase --- diff --git a/Changes b/Changes index 6109aee..a920385 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - correct default_value for all backends with common tests + - fix bug with quoted Pg tables from $dbh->tables (RT#54338) + - add inflate_datetime => 0 to 'timestamp' types for Sybase + 0.05000 2010-02-01 09:24:24 - better data_type, default_value and size for Sybase - added 'generate_pod' option, defaults to on diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm index f1e8529..a644147 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm @@ -30,7 +30,8 @@ sub _columns_info_for { $def =~ s/^\s+//; $def =~ s/\s+\z//; - if ($def =~ /^["'](.*?)['"]\z/) { +# remove Pg typecasts (e.g. 'foo'::character varying) too + if ($def =~ /^["'](.*?)['"](?:::[\w\s]+)?\z/) { $info->{default_value} = $1; } else { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm index fa78392..c526514 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm @@ -2,7 +2,10 @@ package DBIx::Class::Schema::Loader::DBI::DB2; use strict; use warnings; -use base 'DBIx::Class::Schema::Loader::DBI'; +use base qw/ + DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault + DBIx::Class::Schema::Loader::DBI +/; use Carp::Clan qw/^DBIx::Class/; use Class::C3; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index c298602..51843ab 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -2,7 +2,10 @@ package DBIx::Class::Schema::Loader::DBI::Pg; use strict; use warnings; -use base 'DBIx::Class::Schema::Loader::DBI'; +use base qw/ + DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault + DBIx::Class::Schema::Loader::DBI +/; use Carp::Clan qw/^DBIx::Class/; use Class::C3; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm index d240cc8..99d6a4e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm @@ -251,7 +251,11 @@ WHERE o.name = @{[ $dbh->quote($table) ]} AND o.type = 'U' my $info = $sth->fetchall_hashref('name'); while (my ($col, $res) = each %$result) { - $res->{data_type} = $info->{$col}{type}; + my $data_type = $res->{data_type} = $info->{$col}{type}; + + if ($data_type && $data_type =~ /^timestamp\z/i) { + $res->{inflate_datetime} = 0; + } if (my $default = $info->{$col}{deflt}) { if ($default =~ /^AS \s+ (\S+)/ix) { @@ -259,7 +263,7 @@ WHERE o.name = @{[ $dbh->quote($table) ]} AND o.type = 'U' $res->{default_value} = \$function; } elsif ($default =~ /^DEFAULT \s+ (\S+)/ix) { - my ($constant_default) = $1 =~ /^['"\[\]]?(.*?)['"\[\]]\z/; + my ($constant_default) = $1 =~ /^['"\[\]]?(.*?)['"\[\]]?\z/; $res->{default_value} = $constant_default; } } diff --git a/t/12pg_common.t b/t/12pg_common.t index 35526ff..57faa7a 100644 --- a/t/12pg_common.t +++ b/t/12pg_common.t @@ -11,6 +11,7 @@ my $password = $ENV{DBICTEST_PG_PASS} || ''; my $tester = dbixcsl_common_tests->new( vendor => 'Pg', auto_inc_pk => 'SERIAL NOT NULL PRIMARY KEY', + default_function => 'now()', dsn => $dsn, user => $user, password => $password, diff --git a/t/13db2_common.t b/t/13db2_common.t index b27ef4f..2eefb47 100644 --- a/t/13db2_common.t +++ b/t/13db2_common.t @@ -9,6 +9,7 @@ my $password = $ENV{DBICTEST_DB2_PASS} || ''; my $tester = dbixcsl_common_tests->new( vendor => 'DB2', auto_inc_pk => 'INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY', + default_function => 'CURRENT TIMESTAMP', dsn => $dsn, user => $user, password => $password, diff --git a/t/15sybase_common.t b/t/15sybase_common.t index bbfeeda..749aac3 100644 --- a/t/15sybase_common.t +++ b/t/15sybase_common.t @@ -12,6 +12,8 @@ my $password = $ENV{DBICTEST_SYBASE_PASS} || ''; my $tester = dbixcsl_common_tests->new( vendor => 'sybase', auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY', + default_function => 'getdate()', + default_function_def => 'AS getdate()', dsn => $dsn, user => $user, password => $password, @@ -21,7 +23,6 @@ my $tester = dbixcsl_common_tests->new( CREATE TABLE sybase_loader_test1 ( id INTEGER IDENTITY NOT NULL PRIMARY KEY, ts timestamp, - charfield VARCHAR(10) DEFAULT 'foo', computed_dt AS getdate() ) }, @@ -64,7 +65,7 @@ my $tester = dbixcsl_common_tests->new( }, ], drop => [ qw/ sybase_loader_test1 sybase_loader_test2 / ], - count => 38, + count => 36, run => sub { my ($schema, $monikers, $classes) = @_; @@ -83,17 +84,9 @@ my $tester = dbixcsl_common_tests->new( 'timestamp', 'timestamps have the correct data_type'; - is $rsrc->column_info('charfield')->{data_type}, - 'varchar', - 'VARCHAR has correct data_type'; - - is $rsrc->column_info('charfield')->{default_value}, - 'foo', - 'constant DEFAULT is correct'; - - is $rsrc->column_info('charfield')->{size}, - 10, - 'VARCHAR(10) has correct size'; + is $rsrc->column_info('ts')->{inflate_datetime}, + 0, + 'timestamps have inflate_datetime => 0'; ok ((exists $rsrc->column_info('computed_dt')->{data_type} && (not defined $rsrc->column_info('computed_dt')->{data_type})), diff --git a/t/16mssql_common.t b/t/16mssql_common.t index 2b59b07..4282aae 100644 --- a/t/16mssql_common.t +++ b/t/16mssql_common.t @@ -19,6 +19,8 @@ my $password = $ENV{DBICTEST_MSSQL_PASS} || ''; my $tester = dbixcsl_common_tests->new( vendor => 'mssql', auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY', + default_function => 'getdate()', + default_function_def => 'DATETIME DEFAULT getdate()', dsn => $dsn, user => $user, password => $password, diff --git a/t/16mssql_odbc_common.t b/t/16mssql_odbc_common.t index 0e2e44c..fd95f84 100644 --- a/t/16mssql_odbc_common.t +++ b/t/16mssql_odbc_common.t @@ -10,6 +10,8 @@ my $password = $ENV{DBICTEST_MSSQL_ODBC_PASS} || ''; my $tester = dbixcsl_common_tests->new( vendor => 'mssql', auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY', + default_function => 'getdate()', + default_function_def => 'DATETIME DEFAULT getdate()', dsn => $dsn, user => $user, password => $password, diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 45a09e3..31bd90e 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -839,7 +839,7 @@ sub create { qq{ CREATE TABLE loader_test35 ( - id INTEGER PRIMARY KEY, + id INTEGER NOT NULL PRIMARY KEY, a_varchar VARCHAR(100) DEFAULT 'foo', an_int INTEGER DEFAULT 42, a_double DOUBLE PRECISION DEFAULT 10.555,