From: Rafael Kitover Date: Sat, 13 Jun 2009 00:28:06 +0000 (+0000) Subject: finished up on_connect_call stuff X-Git-Tag: v0.08108~48^2~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5fc1107ffcb8986652e955e471460bb00798e644;p=dbsrgits%2FDBIx-Class.git finished up on_connect_call stuff --- diff --git a/Makefile.PL b/Makefile.PL index 3713df1..940d78d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -81,6 +81,9 @@ my %force_requires_if_author = ( 'DateTime::Format::MySQL' => 0, 'DateTime::Format::Pg' => 0, + # t/73oracle.t + 'DateTime::Format::Oracle' => 0, + # t/96_is_deteministic_value.t 'DateTime::Format::Strptime' => 0, diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index fb54184..5ebbab5 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -221,6 +221,26 @@ Some predefined storage methods you may use: Executes a SQL string or a code reference that returns a SQL string. This is what L and L use. +It can take: + +=over + +=item a scalar + +Will execute the scalar as SQL. + +=item an arrayref + +Taken to be arguments to L, the SQL string optionally followed by the +attributes hashref and bind values. + +=item a code reference + +Will execute C<< $code->($storage) >> and execute the return array refs as +above. + +=back + =item set_datetime_format Execute any statements necessary to initialize the database session to return diff --git a/t/92storage_on_connect_call.t b/t/92storage_on_connect_call.t new file mode 100644 index 0000000..d0d937b --- /dev/null +++ b/t/92storage_on_connect_call.t @@ -0,0 +1,67 @@ +use strict; +use warnings; +no warnings qw/once redefine/; + +use lib qw(t/lib); +require DBICTest; + +use Test::More tests => 9; + +my $schema = DBICTest->init_schema( + no_connect => 1, + no_deploy => 1, +); + +local *DBIx::Class::Storage::DBI::connect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; + is $_[1], 'bar', 'got param in connect_call method'; +}; + +local *DBIx::Class::Storage::DBI::disconnect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in disconnect_call method'; +}; + +ok $schema->connection( + DBICTest->_database, + { + on_connect_call => [ + [ do_sql => 'create table test1 (id integer)' ], + [ 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)' ], + [ foo => 'bar' ], + ], + on_connect_do => 'insert into test1 values (4)', + on_disconnect_call => 'foo', + }, +), 'connection()'; + +is_deeply ( + $schema->storage->dbh->selectall_arrayref('select * from test1'), + [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ], + 'on_connect_call/do actions worked' +); + +local *DBIx::Class::Storage::DBI::connect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; +}; + +local *DBIx::Class::Storage::DBI::connect_call_bar = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; +}; + +$schema->storage->disconnect; + +ok $schema->connection( + DBICTest->_database, + { + # method list form + on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ], + }, +), 'connection()'; + +$schema->storage->ensure_connected;