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
$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 {
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;
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;
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) {
$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;
}
}
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,
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,
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,
CREATE TABLE sybase_loader_test1 (
id INTEGER IDENTITY NOT NULL PRIMARY KEY,
ts timestamp,
- charfield VARCHAR(10) DEFAULT 'foo',
computed_dt AS getdate()
)
},
},
],
drop => [ qw/ sybase_loader_test1 sybase_loader_test2 / ],
- count => 38,
+ count => 36,
run => sub {
my ($schema, $monikers, $classes) = @_;
'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})),
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,
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,
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,