Skip Menu |

This queue is for tickets about the DBD-Mock CPAN distribution.

Report information
The Basics
Id: 35145
Status: resolved
Priority: 0/
Queue: DBD-Mock

People
Owner: Nobody in particular
Requestors: matt.lawrence [...] virgin.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.36
Fixed in: (no value)



Subject: selectcol_arrayref ignores "Columns" attribute
selectcol_arrayref is documented to accept a Columns attribute, to select specific or multiple columns. This doesn't currently work with DBD::Mock. The attached patch implements this feature and adds a test for it. Regards, Matt Lawrence
Subject: dbd_mock_selectcol.diff
--- lib/DBD/Mock.pm 2008-04-17 10:21:01.000000000 +0100 +++ lib/DBD/Mock.pm 2008-04-17 10:36:17.000000000 +0100 @@ -395,9 +395,14 @@ # something went wrong, and so return undef. return undef unless defined $a_ref || ref($a_ref) ne 'ARRAY'; + my @cols = 0; + if (ref $attrib->{Columns} eq 'ARRAY') { + @cols = map { $_ - 1 } @{$attrib->{Columns}}; + } + # if we do get something then we # grab all the columns out of it. - return [ map { $_->[0] } @{$a_ref} ] + return [ map { @$_[@cols] } @{$a_ref} ] } { --- t/024_selcol_fetchhash.t 2008-04-17 10:42:19.000000000 +0100 +++ t/024_selcol_fetchhash.t 2008-04-17 10:42:28.000000000 +0100 @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More :ests => 8; BEGIN { use_ok('DBD::Mock'); @@ -69,6 +69,16 @@ is_deeply($res, \@expected, "Checking if selectcol_arrayref works."); } +{ + my %expected = (1 => 'european', 27 => 'african'); + + my $res = eval { $dbh->selectcol_arrayref($swallow_sql, {Columns=>[1, 2]}) }; + is_deeply( + { @{$res||[]} }, \%expected, + 'Checking if selectcol_arrayref works with Columns attribute' + ); +} + is_deeply( $dbh->selectall_hashref($items_sql, 'id', "Checking selectall_hashref with named key."), { '2' => $coco_hash,
On Thu Apr 17 05:50:09 2008, MATTLAW wrote: Show quoted text
> The attached patch implements this feature and adds a test for it.
Apologies, there was an error in the patch.
--- lib/DBD/Mock.pm.orig 2008-04-17 10:21:01.000000000 +0100 +++ lib/DBD/Mock.pm 2008-04-17 10:36:17.000000000 +0100 @@ -395,9 +395,14 @@ # something went wrong, and so return undef. return undef unless defined $a_ref || ref($a_ref) ne 'ARRAY'; + my @cols = 0; + if (ref $attrib->{Columns} eq 'ARRAY') { + @cols = map { $_ - 1 } @{$attrib->{Columns}}; + } + # if we do get something then we # grab all the columns out of it. - return [ map { $_->[0] } @{$a_ref} ] + return [ map { @$_[@cols] } @{$a_ref} ] } { --- t/024_selcol_fetchhash.t.orig 2008-04-17 10:42:19.000000000 +0100 +++ t/024_selcol_fetchhash.t 2008-04-17 10:52:45.000000000 +0100 @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 8; BEGIN { use_ok('DBD::Mock'); @@ -69,6 +69,16 @@ is_deeply($res, \@expected, "Checking if selectcol_arrayref works."); } +{ + my %expected = (1 => 'european', 27 => 'african'); + + my $res = eval { $dbh->selectcol_arrayref($swallow_sql, {Columns=>[1, 2]}) }; + is_deeply( + { @{$res||[]} }, \%expected, + 'Checking if selectcol_arrayref works with Columns attribute' + ); +} + is_deeply( $dbh->selectall_hashref($items_sql, 'id', "Checking selectall_hashref with named key."), { '2' => $coco_hash,