[Bast-commits] r6658 - in DBIx-Class/0.08/branches/on_connect_call:
. lib/DBIx/Class/Storage lib/DBIx/Class/Storage/DBI/Oracle t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Sat Jun 13 11:03:37 GMT 2009
Author: caelum
Date: 2009-06-13 11:03:36 +0000 (Sat, 13 Jun 2009)
New Revision: 6658
Modified:
DBIx-Class/0.08/branches/on_connect_call/Makefile.PL
DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm
DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
DBIx-Class/0.08/branches/on_connect_call/t/73oracle.t
DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t
DBIx-Class/0.08/branches/on_connect_call/t/92storage.t
DBIx-Class/0.08/branches/on_connect_call/t/92storage_on_connect_call.t
Log:
fixup _setup_connect_do, other minor cleanups
Modified: DBIx-Class/0.08/branches/on_connect_call/Makefile.PL
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/Makefile.PL 2009-06-13 03:57:40 UTC (rev 6657)
+++ DBIx-Class/0.08/branches/on_connect_call/Makefile.PL 2009-06-13 11:03:36 UTC (rev 6658)
@@ -81,7 +81,7 @@
'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
Modified: DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm 2009-06-13 03:57:40 UTC (rev 6657)
+++ DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm 2009-06-13 11:03:36 UTC (rev 6658)
@@ -183,11 +183,11 @@
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
@@ -200,9 +200,15 @@
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;
Modified: DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm 2009-06-13 03:57:40 UTC (rev 6657)
+++ DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm 2009-06-13 11:03:36 UTC (rev 6658)
@@ -241,12 +241,15 @@
=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
@@ -474,26 +477,22 @@
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
@@ -642,9 +641,12 @@
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;
@@ -761,9 +763,12 @@
# 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 {
@@ -821,7 +826,7 @@
}
# 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) = @_;
Modified: DBIx-Class/0.08/branches/on_connect_call/t/73oracle.t
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/t/73oracle.t 2009-06-13 03:57:40 UTC (rev 6657)
+++ DBIx-Class/0.08/branches/on_connect_call/t/73oracle.t 2009-06-13 11:03:36 UTC (rev 6658)
@@ -41,12 +41,10 @@
' 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;
@@ -115,13 +113,11 @@
$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
+# test join with row count ambiguity
-my $dt = DateTime->now;
-
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 }
@@ -130,7 +126,6 @@
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' });
Modified: DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t 2009-06-13 03:57:40 UTC (rev 6657)
+++ DBIx-Class/0.08/branches/on_connect_call/t/73oracle_inflate.t 2009-06-13 11:03:36 UTC (rev 6658)
@@ -17,7 +17,7 @@
plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
}
else {
- plan tests => 7;
+ plan tests => 9;
}
}
@@ -67,9 +67,33 @@
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");
}
}
Modified: DBIx-Class/0.08/branches/on_connect_call/t/92storage.t
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/t/92storage.t 2009-06-13 03:57:40 UTC (rev 6657)
+++ DBIx-Class/0.08/branches/on_connect_call/t/92storage.t 2009-06-13 11:03:36 UTC (rev 6658)
@@ -162,7 +162,7 @@
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",
);
}
Modified: DBIx-Class/0.08/branches/on_connect_call/t/92storage_on_connect_call.t
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/t/92storage_on_connect_call.t 2009-06-13 03:57:40 UTC (rev 6657)
+++ DBIx-Class/0.08/branches/on_connect_call/t/92storage_on_connect_call.t 2009-06-13 11:03:36 UTC (rev 6658)
@@ -3,7 +3,7 @@
no warnings qw/once redefine/;
use lib qw(t/lib);
-require DBICTest;
+use DBICTest;
use Test::More tests => 9;
@@ -31,6 +31,7 @@
[ 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)',
More information about the Bast-commits
mailing list