Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 45159
Status: resolved
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: dfenze [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 0.08103



Subject: dbic::Storage::DBI on_connect_do fn/param in connect_info should also accept scalar
on_connect_do should accept also scalar value -- string which contains one SQL statement. Patch included.
Subject: dbic_on_connect_do.patch
diff -r f497971c2c6f DBIx-Class-0.08100/lib/DBIx/Class/Storage/DBI.pm --- a/DBIx-Class-0.08100/lib/DBIx/Class/Storage/DBI.pm Mon Apr 20 14:26:33 2009 +0200 +++ b/DBIx-Class-0.08100/lib/DBIx/Class/Storage/DBI.pm Mon Apr 20 14:28:44 2009 +0200 @@ -471,6 +471,11 @@ =over +=item a scalar + +This contains one SQL statement to execute. + + =item an array reference This contains SQL statements to execute in order. Each element contains @@ -944,14 +949,17 @@ $self->_conn_tid(threads->tid) if $INC{'threads.pm'}; my $connection_do = $self->on_connect_do; - $self->_do_connection_actions($connection_do) if ref($connection_do); + $self->_do_connection_actions($connection_do) if defined($connection_do); } sub _do_connection_actions { my $self = shift; my $connection_do = shift; - if (ref $connection_do eq 'ARRAY') { + if (!ref $connection_do) { + $self->_do_query($connection_do); + } + elsif (ref $connection_do eq 'ARRAY') { $self->_do_query($_) foreach @$connection_do; } elsif (ref $connection_do eq 'CODE') {
On Mon Apr 20 08:30:41 2009, prema wrote: Show quoted text
> on_connect_do should accept also scalar value -- string which contains > one SQL statement. Patch included.
Where are the tests?
Stalling, no reply from author
Newer version of patch with test included is attached
commit 178d94ff5052a21dbb9ae7d34bab8cd3c0c40364 Author: Premysl 'Anydot' Hruby <dfenze@gmail.com> Date: Sat May 2 19:37:32 2009 +0200 on_connect_do accepts scalar also diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index c276f38..74d7fae 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -471,6 +471,11 @@ the database. Its value may contain: =over +=item a scalar + +This contains one SQL statement to execute. + + =item an array reference This contains SQL statements to execute in order. Each element contains @@ -944,14 +949,17 @@ sub _populate_dbh { $self->_conn_tid(threads->tid) if $INC{'threads.pm'}; my $connection_do = $self->on_connect_do; - $self->_do_connection_actions($connection_do) if ref($connection_do); + $self->_do_connection_actions($connection_do) if defined($connection_do); } sub _do_connection_actions { my $self = shift; my $connection_do = shift; - if (ref $connection_do eq 'ARRAY') { + if (!ref $connection_do) { + $self->_do_query($connection_do); + } + elsif (ref $connection_do eq 'ARRAY') { $self->_do_query($_) foreach @$connection_do; } elsif (ref $connection_do eq 'CODE') { diff --git a/t/92storage_on_connect_do.t b/t/92storage_on_connect_do.t index 6c467cd..e96412a 100644 --- a/t/92storage_on_connect_do.t +++ b/t/92storage_on_connect_do.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 10; +use Test::More tests => 12; use lib qw(t/lib); use base 'DBICTest'; @@ -11,6 +11,21 @@ my $schema = DBICTest->init_schema( no_connect => 1, no_deploy => 1, ); + +ok $schema->connection( + DBICTest->_database, + { + on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)', + }, +), 'connection()'; + +is_deeply + $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'), + [], + 'string version on_connect_do() worked'; + +$schema->storage->disconnect; + ok $schema->connection( DBICTest->_database, {
On Sat May 02 13:41:32 2009, prema wrote: Show quoted text
> Newer version of patch with test included is attached
Applied with some modifications as http://dev.catalyst.perl.org/svnweb/bast/revision/?rev=6356
DBIx::Class 0.08103 just released on CPAN fixes this RT.