From: John Napiorkowski Date: Tue, 6 May 2008 18:47:00 +0000 (+0000) Subject: changed the warning on DBIC::Storage::DBI->select_single so that it wont call fetch_... X-Git-Tag: v0.08240~463 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=1a4e8d7c8431df44e9cf1cc4f5d261390ec789c6 changed the warning on DBIC::Storage::DBI->select_single so that it wont call fetch_* on an empty sth, updated tests for the above and added a todo test for the wrong count problem --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index d0f5b1e..7d76be6 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1287,7 +1287,9 @@ sub select_single { my $self = shift; my ($rv, $sth, @bind) = $self->_select(@_); my @row = $sth->fetchrow_array; - carp "Query returned more than one row" if $sth->fetchrow_array; + if(@row && $sth->fetchrow_array) { + carp "Query returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single"; + } # Need to call finish() to work round broken DBDs $sth->finish(); return @row; diff --git a/t/61findnot.t b/t/61findnot.t index 17f64fd..8479494 100644 --- a/t/61findnot.t +++ b/t/61findnot.t @@ -54,7 +54,8 @@ ok($art, 'Artist found by key in the resultset'); $artist_rs = $schema->resultset("Artist"); warning_is { $artist_rs->find({}, { key => 'primary' }) -} "DBIx::Class::ResultSet::find(): Query returned more than one row", "Non-unique find generated a cursor inexhaustion warning"; +} "DBIx::Class::ResultSet::find(): Query returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single" + => "Non-unique find generated a cursor inexhaustion warning"; $artist_rs = $schema->resultset("Artist")->search({}, { prefetch => 'cds' }); warning_is { diff --git a/t/71mysql.t b/t/71mysql.t index a326dda..4aa48bd 100644 --- a/t/71mysql.t +++ b/t/71mysql.t @@ -13,7 +13,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' unless ($dsn && $user); -plan tests => 5; +plan tests => 10; my $schema = DBICTest::Schema->connect($dsn, $user, $pass); @@ -85,6 +85,34 @@ SKIP: { is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); } +## Can we properly deal with the null search problem? + +use Data::Dump qw/dump/; + +NULLINSEARCH: { + + ok my $artist1_rs = $schema->resultset('Artist')->search({artistid=>6666}) + => 'Created an artist resultset of 6666'; + + is $artist1_rs->count, 0 + => 'Got no returned rows'; + + ok my $artist2_rs = $schema->resultset('Artist')->search({artistid=>undef}) + => 'Created an artist resultset of undef'; + + TODO: { + $TODO = "need to fix the row count =1 when select * from table where pk IS NULL problem"; + is $artist2_rs->count, 0 + => 'got no rows'; + } + + my $artist = $artist2_rs->single; + + is $artist => undef + => 'Nothing Found!'; +} + + # clean up our mess END { $dbh->do("DROP TABLE artist") if $dbh;