[Bast-commits] r7631 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Fri Sep 11 22:15:50 GMT 2009


Author: ribasushi
Date: 2009-09-11 22:15:50 +0000 (Fri, 11 Sep 2009)
New Revision: 7631

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm
   DBIx-Class/0.08/trunk/t/88result_set_column.t
Log:
Add single() ro RSC

Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2009-09-11 21:13:45 UTC (rev 7630)
+++ DBIx-Class/0.08/trunk/Changes	2009-09-11 22:15:50 UTC (rev 7631)
@@ -8,9 +8,11 @@
           dropped during the serial-autodetection rwrite
         - Make sure ResultSetColumn does not depend on the (undefined)
           return value of ->cursor->reset()
+        - Add single() to ResultSetColumn (same semantics as ResultSet)
         - Make sure to turn off IDENTITY_INSERT after insert() on MSSQL
           tables that needed it
         - More informative exception on failing _resolve_relationship
+        - Fix unreported rollback exceptions in TxnScopeGuard
 
 0.08111 2009-09-06 21:58:00 (UTC)
         - The hashref to connection_info now accepts a 'dbh_maker'

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm	2009-09-11 21:13:45 UTC (rev 7630)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm	2009-09-11 22:15:50 UTC (rev 7631)
@@ -207,6 +207,33 @@
   return $row;
 }
 
+=head2 single
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $value
+
+=back
+
+Much like L<DBIx::Class::ResultSet/single> fetches one and only one column
+value using the cursor directly. If additional rows are present a warning
+is issued before discarding the cursor.
+
+=cut
+
+sub single {
+  my $self = shift;
+
+  my $attrs = $self->_resultset->_resolved_attrs;
+  my ($row) = $self->_resultset->result_source->storage->select_single(
+    $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs
+  );
+
+  return $row;
+}
+
 =head2 min
 
 =over 4

Modified: DBIx-Class/0.08/trunk/t/88result_set_column.t
===================================================================
--- DBIx-Class/0.08/trunk/t/88result_set_column.t	2009-09-11 21:13:45 UTC (rev 7630)
+++ DBIx-Class/0.08/trunk/t/88result_set_column.t	2009-09-11 22:15:50 UTC (rev 7631)
@@ -1,7 +1,8 @@
 use strict;
-use warnings;  
+use warnings;
 
 use Test::More;
+use Test::Warn;
 use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
@@ -31,6 +32,10 @@
 
 is($rs_year->first, 1999, "first okay");
 
+warnings_exist (sub {
+  is($rs_year->single, 1999, "single okay");
+}, qr/Query returned more than one row/, 'single warned');
+
 # test +select/+as for single column
 my $psrs = $schema->resultset('CD')->search({},
     {




More information about the Bast-commits mailing list