[libdbd-pg-perl] 19/35: Add new statement handle attribut pg_async_status per CPAN ticket 116172

Christoph Berg myon at debian.org
Wed Sep 27 17:41:04 UTC 2017


This is an automated email from the git hooks/post-receive script.

myon pushed a commit to branch master
in repository libdbd-pg-perl.

commit 44bc762ae526d7d644942dac9de167b937b16d0d
Author: Greg Sabino Mullane <greg at endpoint.com>
Date:   Wed Sep 20 17:43:50 2017 -0400

    Add new statement handle attribut pg_async_status per CPAN ticket 116172
---
 Changes       |  5 +++++
 Pg.pm         |  7 +++++++
 dbdimp.c      |  4 +++-
 t/02attribs.t | 44 ++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/Changes b/Changes
index 23d48d3..c8d4c42 100644
--- a/Changes
+++ b/Changes
@@ -21,6 +21,11 @@ Version 3.7.0
     [Dagfinn Ilmari Mannsåker]
     (Github issue #30)
 
+  - Add $sth->{pg_async_status} to determine async status of a statement handle.
+    Values can be 0 (no async), 1 (async), or -1 (cancelled
+    [Greg Sabino Mullane, as requested by Dmytro Zagashev (ZDM)]
+    (CPAN ticket #116172)
+
 Version 3.6.2  Released May 23, 2017 (git tag 3.6.2)
 
   - Remove errant debugging aid from test suite
diff --git a/Pg.pm b/Pg.pm
index 66686a1..6c4936a 100644
--- a/Pg.pm
+++ b/Pg.pm
@@ -3857,6 +3857,13 @@ being treated as a placeholder.
 DBD::Pg specific attribute. Indicates the current behavior for asynchronous queries. See the section 
 on L</Asynchronous Constants> for more information.
 
+=head3 B<pg_async_status> (integer, read-only)
+
+DBD::Pg specific attribute. Returns the current status of an L<asynchronous|/Asynchronous Queries>
+command. 0 indicates no asynchronous command is in progress, 1 indicates that 
+an asynchronous command has started and -1 indicated that an asynchronous command 
+has been cancelled.
+
 =head3 B<RowsInCache>
 
 Not used by DBD::Pg
diff --git a/dbdimp.c b/dbdimp.c
index 9ed0525..f402f7a 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -1146,10 +1146,12 @@ SV * dbd_st_FETCH_attrib (SV * sth, imp_sth_t * imp_sth, SV * keysv)
 			retsv = newSViv(imp_sth->cur_tuple);
 		break;
 
-	case 15: /* pg_prepare_name */
+	case 15: /* pg_prepare_name pg_async_status */
 
 		if (strEQ("pg_prepare_name", key))
 			retsv = newSVpv((char *)imp_sth->prepare_name, 0);
+		else if (strEQ("pg_async_status", key))
+			retsv = newSViv((IV)imp_sth->async_status);
 		break;
 
 	case 17: /* pg_server_prepare */
diff --git a/t/02attribs.t b/t/02attribs.t
index caa2fb6..c4eee60 100644
--- a/t/02attribs.t
+++ b/t/02attribs.t
@@ -8,7 +8,7 @@ use warnings;
 use Data::Dumper;
 use Test::More;
 use DBI     ':sql_types';
-use DBD::Pg ':pg_types';
+use DBD::Pg qw/ :pg_types :async /;
 use lib 't','.';
 require 'dbdpg_test_setup.pl';
 select(($|=1,select(STDERR),$|=1)[1]);
@@ -18,7 +18,7 @@ my ($helpconnect,$connerror,$dbh) = connect_database();
 if (! $dbh) {
 	plan skip_all => 'Connection to database failed, cannot continue testing';
 }
-plan tests => 259;
+plan tests => 271;
 
 isnt ($dbh, undef, 'Connect to database for handle attributes testing');
 
@@ -28,6 +28,7 @@ my $attributes_tested = q{
 
 d = database handle specific
 s = statement handle specific
+b = both database and statement handle
 a = any type of handle (but we usually use database)
 
 In order:
@@ -76,6 +77,7 @@ s pg_size
 s pg_type
 s pg_oid_status
 s pg_cmd_status
+b pg_async_status
 
 a Active
 a Executed
@@ -954,6 +956,44 @@ q{SELECT * FROM dbd_pg_test},
 }
 
 #
+# Test of the datbase and statement handle attribute "pg_async_status"
+#
+
+$t=q{Statement handle attribute "pg_async_status" returns a 0 as default value};
+is ($sth->{pg_async_status}, 0, $t);
+$t=q{Database handle attribute "pg_async_status" returns a 0 as default value};
+is ($dbh->{pg_async_status}, 0, $t);
+
+$t=q{Statement handle attribute "pg_async_status" returns a 0 after a normal prepare};
+$sth = $dbh->prepare('SELECT 123');
+is ($sth->{pg_async_status}, 0, $t);
+$t=q{Database handle attribute "pg_async_status" returns a 0 after a normal prepare};
+is ($dbh->{pg_async_status}, 0, $t);
+
+$t=q{Statement handle attribute "pg_async_status" returns a 0 after a normal execute};
+$sth->execute();
+is ($sth->{pg_async_status}, 0, $t);
+$t=q{Database handle attribute "pg_async_status" returns a 0 after a normal execute};
+is ($sth->{pg_async_status}, 0, $t);
+
+$t=q{Statement handle attribute "pg_async_status" returns a 0 after an asynchronous prepare};
+$sth = $dbh->prepare('SELECT 123', { pg_async => PG_ASYNC });
+is ($sth->{pg_async_status}, 0, $t);
+$t=q{Database handle attribute "pg_async_status" returns a 0 after an asynchronous prepare};
+is ($dbh->{pg_async_status}, 0, $t);
+$sth->execute();
+$t=q{Statement handle attribute "pg_async_status" returns a 1 after an asynchronous execute};
+is ($sth->{pg_async_status}, 1, $t);
+$t=q{Database handle attribute "pg_async_status" returns a 1 after an asynchronous execute};
+is ($dbh->{pg_async_status}, 1, $t);
+
+$t=q{Statement handle attribute "pg_async_status" returns a -1 after a cancel};
+$dbh->pg_cancel();
+is ($sth->{pg_async_status}, -1, $t);
+$t=q{Database handle attribute "pg_async_status" returns a -1 after a cancel};
+is ($dbh->{pg_async_status}, -1, $t);
+
+#
 # Test of the handle attribute "Active"
 #
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libdbd-pg-perl.git



More information about the Pkg-perl-cvs-commits mailing list