assume that storage attributes can be set per-RS
Gianni Ceccarelli [Thu, 26 Aug 2010 13:33:59 +0000 (14:33 +0100)]
lib/DBIx/Class/Storage/DBI/Pg.pm
t/72pg_cursors.t

index ed8075e..e1e43d4 100644 (file)
@@ -255,54 +255,16 @@ sub _get_next_pg_cursor_number {
     return $ret;
 }
 
-sub _should_use_pg_cursors {
-    my ($self,$attrs) = @_;
-
-    if (   exists $attrs->{server_cursors}
-        && defined $attrs->{server_cursors}
-    ) {
-        return $attrs->{server_cursors};
-    }
-
-    return $self->get_use_dbms_capability('server_cursors');
-}
-
-sub _get_pg_cursor_page_size {
-    my ($self,$attrs) = @_;
-
-    if (   exists $attrs->{cursor_page_size}
-        && defined $attrs->{cursor_page_size}
-    ) {
-        return $attrs->{cursor_page_size};
-    }
-
-    if (defined $self->cursor_page_size) {
-        return $self->cursor_page_size;
-    }
-
-    return 1000;
-}
-
-sub _select {
-    my $self = shift;
-    my ($ident, $select, $where, $attrs) = @_;
-
-    # ugly ugly ugly, but this is the last sub in the call chain that
-    # receives $attrs
-    local $self->{_use_pg_cursors}=$self->_should_use_pg_cursors($attrs);
-    local $self->{_pg_cursor_page_size}=$self->_get_pg_cursor_page_size($attrs);
-
-    return $self->next::method(@_);
-}
-
 sub _dbh_sth {
     my ($self, $dbh, $sql) = @_;
 
     # here we have to use the ugly local attributes because we no
     # longer have access to the resultset attributes
-    if ($self->{_use_pg_cursors} && $sql =~ /^SELECT\b/i) {
+    if ($self->get_use_dbms_capability('server_cursors')
+            && $sql =~ /^SELECT\b/i) {
         return DBIx::Class::Storage::DBI::Pg::Sth
-            ->new($self,$dbh,$sql,$self->{_pg_cursor_page_size});
+            ->new($self,$dbh,$sql,
+                  $self->cursor_page_size||1000);
     }
     else { # short-circuit
         return $self->next::method($dbh,$sql);
index a2cca05..4141999 100644 (file)
@@ -11,7 +11,7 @@ my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}
 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
   unless ($dsn && $dbuser);
 
-plan tests => 14;
+plan tests => 16;
 
 sub create_test_schema {
     my ($schema)=@_;
@@ -110,6 +110,16 @@ is (
 
 {
     $called=0;
+    my $rs=$schema->resultset('Artist')->search({});
+    $schema->storage->set_use_dbms_capability('server_cursors',0);
+    my @rows=$rs->all;
+    is(scalar(@rows),$rows,'get all the rows (all)');
+    is($called,0,'Pg::Sth *not* called');
+    $schema->storage->set_use_dbms_capability('server_cursors',1);
+}
+
+{
+    $called=0;
     my $rs=$schema->resultset('Artist')->search({},{server_cursors=>0});
     my @rows=$rs->all;
     is(scalar(@rows),$rows,'get all the rows (all)');