On 8/7/07, Greg Sabino Mullane <[EMAIL PROTECTED]> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: RIPEMD160
>
>
> > As someone who just joined the mailing list, how do I look at the
> > subversion code?
>
> svn co http://svn.perl.org/modules/DBD-Pg/trunk dbdpg

Thank you.

Will this version remove the need for the second parameter to
pg_getline?  If so, then that should be documented.  I didn't install
so I can't test, but I'll note that with older versions of DBD::Pg
copying the code for pg_getline can result in undefined warnings.  I
eliminated that by making sure that the variable passed in is defined.
 Is this warning fixed in this version, or is that still bad?

I also think the cursor documentation could benefit from an example
showing how to use cursors.  Here is a patch adding that.

Cheers,
Ben

--- Pg.pm.bak   2007-08-07 09:34:33.000000000 -0700
+++ Pg.pm       2007-08-07 10:03:29.000000000 -0700
@@ -3401,14 +3401,31 @@

 =head2 Cursors

-Although PostgreSQL has a cursor concept, it has not been used in the current
+Although PostgreSQL supports cursors, they have not been used in the current
 implementation. Cursors in PostgreSQL can only be used inside a transaction
 block. Because only one transaction block at a time is allowed, this would
 have implied the restriction not to use any nested C<SELECT> statements. Hence
 the C<execute> method fetches all data at once into data structures located in
-the front-end application. This approach must to be considered when selecting
+the front-end application. This fact must to be considered when selecting
 large amounts of data!

+You can use cursors in your application, but you'll need to do a little
+work.  First you must make sure that autocommit is off.  Then declare your
+cursor.  Now you are able to issue queries against the cursor, and select
+against your queries.  This typically results in a double loop, like this:
+
+  $dbh->{AutoCommit} = 0;
+  $dbh->do("DECLARE csr CURSOR FOR $sql");
+  while (1) {
+    my $sth = $dbh->prepare("fetch 1000 from csr");
+    $sth->execute;
+    last if 0 == $sth->rows;
+
+    while (my $row = $sth->fetchrow_hashref) {
+      # Do something with the data.
+    }
+  }
+
 =head2 Datatype bool

Reply via email to