'DateTime::Format::MySQL' => 0,
'DateTime::Format::Pg' => 0,
- # t/73oracle.t
+ # t/73oracle_inflate.t
'DateTime::Format::Oracle' => 0,
# t/96_is_deteministic_value.t
=back
-=item set_datetime_format
+=item datetime_setup
Execute any statements necessary to initialize the database session to return
and accept datetime/timestamp values used with
L<DBIx::Class::InflateColumn::DateTime>.
+Only necessary for some databases, see your specific storage driver for
+implementation details.
+
=back
=item on_disconnect_call
my $val = shift;
- (my $call = $opt) =~ s/_do\z/_call/;
+ $self->throw_exception("The value of $opt cannot be 'undef'")
+ unless defined $val;
- if (ref($self->$call) ne 'ARRAY') {
- $self->$call([
- defined $self->$call ? $self->$call : ()
- ]);
- }
+ my @store;
if (not ref($val)) {
- push @{ $self->$call }, [ 'do_sql', $val ];
+ push @store, [ 'do_sql', $val ];
} elsif (ref($val) eq 'CODE') {
- push @{ $self->$call }, $val;
+ push @store, $val;
} elsif (ref($val) eq 'ARRAY') {
- push @{ $self->$call },
- map [ 'do_sql', $_ ], @$val;
+ push @store, map [ 'do_sql', $_ ], @$val;
} else {
$self->throw_exception("Invalid type for $opt ".ref($val));
}
- $self->$accessor($val);
+ $self->$accessor(\@store);
}
=head2 dbh_do
my ($self) = @_;
if( $self->connected ) {
- my $connection_call = $self->on_disconnect_call;
- $self->_do_connection_actions(disconnect_call_ => $connection_call)
- if $connection_call;
+ if (my $connection_call = $self->on_disconnect_call) {
+ $self->_do_connection_actions(disconnect_call_ => $connection_call)
+ }
+ if (my $connection_do = $self->_on_disconnect_do) {
+ $self->_do_connection_actions(disconnect_call_ => $connection_do)
+ }
$self->_dbh->rollback unless $self->_dbh_autocommit;
$self->_dbh->disconnect;
# there is no transaction in progress by definition
$self->{transaction_depth} = $self->_dbh_autocommit ? 0 : 1;
- my $connection_call = $self->on_connect_call;
- $self->_do_connection_actions(connect_call_ => $connection_call)
- if $connection_call;
+ if (my $connection_call = $self->on_connect_call) {
+ $self->_do_connection_actions(connect_call_ => $connection_call)
+ }
+ if (my $connection_do = $self->_on_connect_do) {
+ $self->_do_connection_actions(connect_call_ => $connection_do)
+ }
}
sub _determine_driver {
}
# override in db-specific backend when necessary
-sub connect_call_set_datetime_format { 1 }
+sub connect_call_datetime_setup { 1 }
sub _do_query {
my ($self, $action) = @_;
sub datetime_parser_type { return "DateTime::Format::Oracle"; }
-=head2 connect_call_set_datetime_format
+=head2 connect_call_datetime_setup
Used as:
- on_connect_call => 'set_datetime_format'
+ on_connect_call => 'datetime_setup'
In L<DBIx::Class::Storage::DBI/connect_info> to set the session nls date, and
timestamp values for use with L<DBIx::Class::InflateColumn::DateTime> and the
C<nls_timestamp_tz_format> is also initialized but is not currently used by
L<DBIx::Class::InflateColumn::DateTime>.
+These are the defaults used:
+
+ $ENV{NLS_DATE_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS';
+ $ENV{NLS_TIMESTAMP_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS.FF';
+ $ENV{NLS_TIMESTAMP_TZ_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS.FF TZHTZM';
+
=cut
-sub connect_call_set_datetime_format {
+sub connect_call_datetime_setup {
my $self = shift;
my $dbh = $self->dbh;
' as well as following sequences: \'pkid1_seq\', \'pkid2_seq\' and \'nonpkid_seq\''
unless ($dsn && $user && $pass);
-plan tests => 36;
+plan tests => 35;
DBICTest::Schema->load_classes('ArtistFQN');
-my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
- on_connect_call => 'set_datetime_format'
-});
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
my $dbh = $schema->storage->dbh;
$new = $schema->resultset('ArtistFQN')->create( { name => 'bar' } );
is( $new->artistid, 2, "Oracle Auto-PK worked with fully-qualified tablename" );
-# test join with row count ambiguity, and DateTime inflation
-
-my $dt = DateTime->now;
+# test join with row count ambiguity
my $cd = $schema->resultset('CD')->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' });
my $track = $schema->resultset('Track')->create({ trackid => 1, cd => 1,
- position => 1, title => 'Track1', last_updated_on => $dt });
+ position => 1, title => 'Track1' });
my $tjoin = $schema->resultset('Track')->search({ 'me.title' => 'Track1'},
{ join => 'cd',
rows => 2 }
ok(my $row = $tjoin->next);
is($row->title, 'Track1', "ambiguous column ok");
-is($row->updated_date, $dt, "DateTime inflation/deflation ok");
# check count distinct with multiple columns
my $other_track = $schema->resultset('Track')->create({ trackid => 2, cd => 1, position => 1, title => 'Track2' });
plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
}
else {
- plan tests => 7;
+ plan tests => 9;
}
}
is( $track->last_updated_on->month, $dt->month, "deflate ok");
is( int $track->last_updated_at->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision");
+# test datetime_setup
+
+$schema->storage->disconnect;
+
+delete $ENV{NLS_DATE_FORMAT};
+delete $ENV{NLS_TIMESTAMP_FORMAT};
+
+$schema->connection($dsn, $user, $pass, {
+ on_connect_call => 'datetime_setup'
+});
+
+$dt = DateTime->now();
+
+my $timestamp = $dt->clone;
+$timestamp->millisecond( 80 );
+
+$track = $schema->resultset('Track')->find( 1 );
+$track->update({ last_updated_on => $dt, last_updated_at => $timestamp });
+
+$track = $schema->resultset('Track')->find(1);
+
+is( $track->last_updated_on, $dt, 'DateTime round-trip as DATE' );
+is( $track->last_updated_at, $timestamp, 'DateTime round-trip as TIMESTAMP' );
+
# clean up our mess
END {
- if($dbh) {
+ if($schema && ($dbh = $schema->storage->dbh)) {
$dbh->do("DROP TABLE track");
}
}
is_deeply (
[$storage->on_connect_do, $storage->on_disconnect_do ],
- [ [qw/a b c/], [qw/d e f/] ],
+ [ [ map [ do_sql => $_ ], qw/a b c/ ], [ map [ do_sql => $_ ], qw/d e f/ ] ],
"$type correctly parsed DBIC specific on_[dis]connect_do",
);
}
no warnings qw/once redefine/;
use lib qw(t/lib);
-require DBICTest;
+use DBICTest;
use Test::More tests => 9;
[ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ],
[ do_sql => sub { ['insert into test1 values (2)'] } ],
[ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ],
+ # this invokes $storage->connect_call_foo('bar') (above)
[ foo => 'bar' ],
],
on_connect_do => 'insert into test1 values (4)',