Revision history for Perl extension DBIx::Class::Schema::Loader
- - rewrite default_value \'now()' as \'CURRENT_TIMESTAMP' for Pg
+ - rewrite datetime default functions as \'CURRENT_TIMESTAMP' where
+ possible (except for Sybase ASE) to ease cross-deployment
- use column_info instead of select to get Oracle column list (RT#42281)
- match quotes in MySQL parser in more places (RT#42101)
- fix unique detection in DB2 for multiple schemas (RT#39622)
}
sub _columns_info_for {
- my ($self, $table) = @_;
- return $self->next::method(uc $table);
-}
+ my $self = shift;
+ my ($table) = @_;
-sub _extra_column_info {
- my ($self, $table, $column, $info, $dbi_info) = @_;
- my %extra_info;
+ my $result = $self->next::method(uc $table);
my $dbh = $self->schema->storage->dbh;
- my $sth = $dbh->prepare_cached(
- q{
- SELECT COUNT(*)
- FROM syscat.columns
- WHERE tabschema = ? AND tabname = ? AND colname = ?
- AND identity = 'Y' AND generated != ''
- },
- {}, 1);
- $sth->execute($self->db_schema, $table, $column);
- if ($sth->fetchrow_array) {
- $extra_info{is_auto_increment} = 1;
+
+ while (my ($col, $info) = each %$result) {
+ # check for identities
+ my $sth = $dbh->prepare_cached(
+ q{
+ SELECT COUNT(*)
+ FROM syscat.columns
+ WHERE tabschema = ? AND tabname = ? AND colname = ?
+ AND identity = 'Y' AND generated != ''
+ },
+ {}, 1);
+ $sth->execute($self->db_schema, uc $table, uc $col);
+ if ($sth->fetchrow_array) {
+ $info->{is_auto_increment} = 1;
+ }
+
+ if (eval { lc ${ $info->{default_value} } }||'' eq 'CURRENT TIMESTAMP') {
+ ${ $info->{default_value} } = 'CURRENT_TIMESTAMP';
+ delete $info->{size};
+ }
}
- return \%extra_info;
+ return $result;
}
=head1 SEE ALSO
=cut
1;
+# vim:et sts=4 sw=4 tw=0:
$info->{default_value} =
$default =~ /^['(] (.*) [)']\z/x ? $1 :
$default =~ /^\d/ ? $default : \$default;
+
+ if (eval { lc ${ $info->{default_value} } }||'' eq 'getdate()') {
+ ${ $info->{default_value} } = 'CURRENT_TIMESTAMP';
+ }
}
}
delete $result->{$col}{default_value};
}
-# alias now() to current_timestamp for deploying to other DBs
- if (eval { lc ${ $result->{$col}{default_value} } eq 'now()' }) {
+# alias now() to CURRENT_TIMESTAMP for deploying to other DBs
+ if (eval { lc ${ $result->{$col}{default_value} }||'' eq 'now()' }) {
+ # do not use a ref to a constant, that breaks Data::Dump output
${$result->{$col}{default_value}} = 'CURRENT_TIMESTAMP';
}
}
}
delete $info->{default_value} if ref($info->{default_value}) eq 'SCALAR' && ${ $info->{default_value} } eq 'NULL';
+
+ if (eval { lc ${ $info->{default_value} } }||'' eq 'current timestamp') {
+ ${ $info->{default_value} } = 'CURRENT_TIMESTAMP';
+ }
}
return $result;
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,
null => '',
+ data_types => {
+ 'timestamp DEFAULT CURRENT TIMESTAMP' => { data_type => 'timestamp', default_value => \'CURRENT_TIMESTAMP' }
+ },
);
if( !$dsn || !$user ) {
else {
$tester->run_tests();
}
+# vim:et sts=4 sw=4 tw=0:
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()',
connect_info => [ ($dbd_sybase_dsn ? {
dsn => $dbd_sybase_dsn,
# datetime types
date => { data_type => 'date' },
datetime => { data_type => 'datetime' },
+ # test rewriting getdate() to CURRENT_TIMESTAMP
'datetime DEFAULT getdate()'
- => { data_type => 'datetime', default_value => \'getdate()' },
+ => { data_type => 'datetime', default_value => \'CURRENT_TIMESTAMP' },
smalldatetime => { data_type => 'smalldatetime' },
time => { data_type => 'time' },
'time(0)'=> { data_type => 'time', size => 0 },
# The default max_cursor_count and max_statement_count settings of 50 are too
# low to run this test.
+#
+# Setting them to zero is preferred.
my $dbd_sqlanywhere_dsn = $ENV{DBICTEST_SYBASE_ASA_DSN} || '';
my $dbd_sqlanywhere_user = $ENV{DBICTEST_SYBASE_ASA_USER} || '';
my $tester = dbixcsl_common_tests->new(
vendor => 'SQLAnywhere',
auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY',
- default_function => 'current timestamp',
connect_info => [ ($dbd_sqlanywhere_dsn ? {
dsn => $dbd_sqlanywhere_dsn,
user => $dbd_sqlanywhere_user,
'smalldatetime'
=> { data_type => 'smalldatetime' },
'timestamp' => { data_type => 'timestamp' },
+ # rewrite 'current timestamp' as 'CURRENT_TIMESTAMP'
'timestamp DEFAULT current timestamp'
- => { data_type => 'timestamp', default_value => \"current timestamp" },
+ => { data_type => 'timestamp', default_value => \"CURRENT_TIMESTAMP" },
'time' => { data_type => 'time' },
# String Types