Author: turnstep
Date: Thu Mar 20 07:08:19 2008
New Revision: 10961
Modified:
DBD-Pg/trunk/Changes
DBD-Pg/trunk/Pg.pm
DBD-Pg/trunk/dbdimp.c
DBD-Pg/trunk/t/03smethod.t
Log:
Add $sth->{pg_current_row}, a quick hook to st.cur_tuple
Modified: DBD-Pg/trunk/Changes
==============================================================================
--- DBD-Pg/trunk/Changes (original)
+++ DBD-Pg/trunk/Changes Thu Mar 20 07:08:19 2008
@@ -1,5 +1,9 @@
('GSM' is Greg Sabino Mullane, [EMAIL PROTECTED])
+2.4.x Released March 2008
+
+ - Add $sth->{pg_current_row} [GSM]
+
2.3.0 Released March 19, 2008 (subversion r10951)
- Add $sth->{pg_bound} and $sth->{pg_numbound} [GSM]
Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm (original)
+++ DBD-Pg/trunk/Pg.pm Thu Mar 20 07:08:19 2008
@@ -3264,6 +3264,11 @@
Not supported by this driver.
+=item B<pg_current_row> (integer, read-only)
+
+PostgreSQL specific attribute. Returns the number of the tuple (row) that was
+most recently fetched. Returns zero before and after fetching is performed.
+
=item B<pg_numbound> (integer, read-only)
PostgreSQL specific attribute. Returns the number of placeholders
Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c (original)
+++ DBD-Pg/trunk/dbdimp.c Thu Mar 20 07:08:19 2008
@@ -953,10 +953,12 @@
}
break;
- case 14: /* pg_prepare_now */
+ case 14: /* pg_prepare_now pg_current_row */
if (strEQ("pg_prepare_now", key))
retsv = newSViv((IV)imp_sth->prepare_now);
+ else if (strEQ("pg_current_row", key))
+ retsv = newSViv(imp_sth->cur_tuple);
break;
case 15: /* pg_prepare_name */
Modified: DBD-Pg/trunk/t/03smethod.t
==============================================================================
--- DBD-Pg/trunk/t/03smethod.t (original)
+++ DBD-Pg/trunk/t/03smethod.t Thu Mar 20 07:08:19 2008
@@ -19,7 +19,7 @@
if (! defined $dbh) {
plan skip_all => 'Connection to database failed, cannot continue
testing';
}
-plan tests => 87;
+plan tests => 96;
isnt( $dbh, undef, 'Connect to database for statement handle method testing');
@@ -522,12 +522,45 @@
$sth->bind_param(1, 123);
is_deeply($sth->{pg_bound}, {1=>1, 2=>1}, $t);
+#
+# Test of the statement handle method "pg_numbound"
+#
+
$t=q{Statement handle attribute pg_numbound returns 1 if one placeholders
bound as NULL};
$sth = $dbh->prepare('SELECT 123 WHERE 1 > ? AND 2 > ?');
$sth->bind_param(1, undef);
is_deeply($sth->{pg_bound}, {1=>1, 2=>0}, $t);
+#
+# Test of the statement handle method "pg_current_row"
+#
+
+$t=q{Statement handle attribute pg_current_row returns zero until first row
fetched};
+$sth = $dbh->prepare('SELECT 1 FROM pg_class LIMIT 5');
+is($sth->{pg_current_row}, 0, $t);
+
+$t=q{Statement handle attribute pg_current_row returns zero until first row
fetched};
+$sth->execute();
+is($sth->{pg_current_row}, 0, $t);
+
+$t=q{Statement handle attribute pg_current_row returns 1 after a fetch};
+$sth->fetch();
+is($sth->{pg_current_row}, 1, $t);
+
+$t=q{Statement handle attribute pg_current_row returns correct value while
fetching};
+my $x = 2;
+while (defined $sth->fetch()) {
+ is($sth->{pg_current_row}, $x++, $t);
+}
+$t=q{Statement handle attribute pg_current_row returns 0 when done fetching};
+is($sth->{pg_current_row}, 0, $t);
+
+$t=q{Statement handle attribute pg_current_row returns 0 after
fetchall_arrayref};
+$sth->execute();
+$sth->fetchall_arrayref();
+is($sth->{pg_current_row}, 0, $t);
+
cleanup_database($dbh,'test');
$dbh->rollback();
$dbh->disconnect();