Author: turnstep
Date: Thu Jul 12 11:39:04 2007
New Revision: 9731
Modified:
DBD-Pg/trunk/Pg.h
DBD-Pg/trunk/Pg.pm
DBD-Pg/trunk/Pg.xs
DBD-Pg/trunk/dbdimp.c
DBD-Pg/trunk/t/01constants.t
DBD-Pg/trunk/t/08async.t
Log:
Rename DBDPG_ async stuff to simply PG_, per suggestion by David E. Wheeler
Modified: DBD-Pg/trunk/Pg.h
==============================================================================
--- DBD-Pg/trunk/Pg.h (original)
+++ DBD-Pg/trunk/Pg.h Thu Jul 12 11:39:04 2007
@@ -17,9 +17,9 @@
#define DBDPG_TRUE (bool)1
#define DBDPG_FALSE (bool)0
-#define DBDPG_ASYNC 1
-#define DBDPG_OLDQUERY_CANCEL 2
-#define DBDPG_OLDQUERY_WAIT 4
+#define PG_ASYNC 1
+#define PG_OLDQUERY_CANCEL 2
+#define PG_OLDQUERY_WAIT 4
#include "libpq-fe.h"
Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm (original)
+++ DBD-Pg/trunk/Pg.pm Thu Jul 12 11:39:04 2007
@@ -26,7 +26,7 @@
%EXPORT_TAGS =
(
- async => [qw(DBDPG_ASYNC DBDPG_OLDQUERY_CANCEL
DBDPG_OLDQUERY_WAIT)],
+ async => [qw(PG_ASYNC PG_OLDQUERY_CANCEL PG_OLDQUERY_WAIT)],
pg_types => [qw(
PG_BOOL PG_BYTEA PG_CHAR PG_INT8 PG_INT2 PG_INT4
PG_TEXT PG_OID PG_TID
PG_FLOAT4 PG_FLOAT8 PG_ABSTIME PG_RELTIME PG_TINTERVAL
PG_BPCHAR
@@ -42,7 +42,7 @@
}
$DBDPG_DEFAULT = DBD::Pg::DefaultValue->new();
Exporter::export_ok_tags('pg_types', 'async');
- @EXPORT = qw($DBDPG_DEFAULT DBDPG_ASYNC DBDPG_OLDQUERY_CANCEL
DBDPG_OLDQUERY_WAIT);
+ @EXPORT = qw($DBDPG_DEFAULT PG_ASYNC PG_OLDQUERY_CANCEL
PG_OLDQUERY_WAIT);
require_version DBI 1.45;
@@ -3102,7 +3102,7 @@
use DBD::Pg ':async';
print "Async do() example:\n";
- $dbh->do("SELECT long_running_query()", {pg_async => DBDPG_ASYNC});
+ $dbh->do("SELECT long_running_query()", {pg_async => PG_ASYNC});
do_something_else();
{
if ($dbh->pg_ready()) {
@@ -3118,11 +3118,11 @@
}
print "Async prepare/execute example:\n";
- $sth = $dbh->prepare("SELECT long_running_query(1)", {pg_async => ASYNC});
+ $sth = $dbh->prepare("SELECT long_running_query(1)", {pg_async => PG_ASYNC});
$sth->execute();
## Changed our mind, cancel and run again:
- $sth = $dbh->prepare("SELECT 678", {pg_async => DBDPG_ASYNC +
DBDPG_OLDQUERY_CANCEL});
+ $sth = $dbh->prepare("SELECT 678", {pg_async => PG_ASYNC +
PG_OLDQUERY_CANCEL});
$sth->execute();
do_something_else();
@@ -3148,18 +3148,18 @@
=over 4
-=item DBDPG_ASYNC
+=item PG_ASYNC
This is a constant for the number 1. It is passed to either the do() or the
prepare() method as a value
to the pg_async key and indicates that the query should be sent asynchronously.
-=item DBDPG_OLDQUERY_CANCEL
+=item PG_OLDQUERY_CANCEL
This is a constant for the number 2. When passed to either the do() or the
prepare method(), it causes any
currently running asynchronous query to be cancelled and rolled back. It has
no effect if no asynchronous
query is currently running.
-=item DBDPG_OLDQUERY_WAIT
+=item PG_OLDQUERY_WAIT
This is a constant for the number 4. When passed to either the do() or the
prepare method(), it waits for any
currently running asynchronous query to complete. It has no effect if there is
no asynchronous query currently running.
@@ -3218,7 +3218,7 @@
my $dbh = DBI->connect('dbi:Pg:dbname=postgres', 'postgres', '',
{AutoCommit=>0,RaiseError=>1});
## Kick off a long running query on the first database:
- my $sth = $dbh->prepare("SELECT pg_sleep(?)", {pg_async => DBDPG_ASYNC});
+ my $sth = $dbh->prepare("SELECT pg_sleep(?)", {pg_async => PG_ASYNC});
$sth->execute(5);
## While that is running, do some other things
@@ -3256,8 +3256,8 @@
$SQL = "SELECT count(*) FROM largetable WHERE flavor='blueberry'";
- my $sth1 = $dbhslave1->prepare($SQL, {pg_async => DBDPG_ASYNC});
- my $sth2 = $dbhslave2->prepare($SQL, {pg_async => DBDPG_ASYNC});
+ my $sth1 = $dbhslave1->prepare($SQL, {pg_async => PG_ASYNC});
+ my $sth2 = $dbhslave2->prepare($SQL, {pg_async => PG_ASYNC});
$sth1->execute();
$sth2->execute();
Modified: DBD-Pg/trunk/Pg.xs
==============================================================================
--- DBD-Pg/trunk/Pg.xs (original)
+++ DBD-Pg/trunk/Pg.xs Thu Jul 12 11:39:04 2007
@@ -61,9 +61,9 @@
PG_OID = 26
PG_TID = 27
- DBDPG_ASYNC = DBDPG_ASYNC
- DBDPG_OLDQUERY_CANCEL = DBDPG_OLDQUERY_CANCEL
- DBDPG_OLDQUERY_WAIT = DBDPG_OLDQUERY_WAIT
+ PG_ASYNC = PG_ASYNC
+ PG_OLDQUERY_CANCEL = PG_OLDQUERY_CANCEL
+ PG_OLDQUERY_WAIT = PG_OLDQUERY_WAIT
CODE:
if (0==ix) {
Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c (original)
+++ DBD-Pg/trunk/dbdimp.c Thu Jul 12 11:39:04 2007
@@ -2157,7 +2157,7 @@
}
/* Asynchronous commands get kicked off and return undef */
- if (asyncflag & DBDPG_ASYNC) {
+ if (asyncflag & PG_ASYNC) {
if (dbis->debug >= 4) (void)PerlIO_printf(DBILOGFP, "dbdpg: Going
asychronous with do()\n");
if (! PQsendQuery(imp_dbh->conn, sql)) {
if (dbis->debug >= 4) (void)PerlIO_printf(DBILOGFP, "dbdpg:
PQsendQuery failed\n");
@@ -2410,7 +2410,7 @@
if (dbis->debug >= 5)
(void)PerlIO_printf(DBILOGFP, "dbdpg: Running
PQexecPrepared with (%s)\n", imp_sth->prepare_name);
- if (imp_sth->async_flag & DBDPG_ASYNC)
+ if (imp_sth->async_flag & PG_ASYNC)
ret = PQsendQueryPrepared
(imp_dbh->conn, imp_sth->prepare_name, imp_sth->numphs,
paramValues, paramLengths, paramFormats, 0);
else
@@ -2478,7 +2478,7 @@
if (dbis->debug >= 5)
(void)PerlIO_printf(DBILOGFP, "dbdpg: Running
PQexecParams with (%s)\n", statement);
- if (imp_sth->async_flag & DBDPG_ASYNC)
+ if (imp_sth->async_flag & PG_ASYNC)
ret = PQsendQueryParams
(imp_dbh->conn, statement, imp_sth->numphs,
paramTypes, paramValues, paramLengths, paramFormats, 0);
else
@@ -2513,7 +2513,7 @@
(void)PerlIO_printf(DBILOGFP, "dbdpg: Running
%s with (%s)\n",
imp_sth->async_flag & 1 ? "PQsendQuery" : "PQexec", statement);
- if (imp_sth->async_flag & DBDPG_ASYNC)
+ if (imp_sth->async_flag & PG_ASYNC)
ret = PQsendQuery(imp_dbh->conn, statement);
else
imp_sth->result = PQexec(imp_dbh->conn, statement);
@@ -2531,7 +2531,7 @@
Safefree(paramFormats);
/* If running asynchronously, we don't stick around for the result */
- if (imp_sth->async_flag & DBDPG_ASYNC) {
+ if (imp_sth->async_flag & PG_ASYNC) {
if (dbis->debug >= 2)
(void)PerlIO_printf
(DBILOGFP, "dbdpg: Early return for async query");
@@ -2741,7 +2741,7 @@
/* Are we in the middle of an async for this statement handle? */
if (imp_dbh->async_status) {
if (imp_sth->async_status) {
- handle_old_async(sth, imp_dbh, DBDPG_OLDQUERY_WAIT);
+ handle_old_async(sth, imp_dbh, PG_OLDQUERY_WAIT);
}
}
@@ -2858,7 +2858,7 @@
}
if (imp_dbh->async_status) {
- handle_old_async(sth, imp_dbh, DBDPG_OLDQUERY_WAIT);
+ handle_old_async(sth, imp_dbh, PG_OLDQUERY_WAIT);
}
/* Deallocate only if we named this statement ourselves and we still
have a good connection */
@@ -3626,7 +3626,7 @@
if (dbis->debug >= 4) { (void)PerlIO_printf(DBILOGFP, "dbdpg:
handle_old_sync flag=%d\n", asyncflag); }
- if (asyncflag & DBDPG_OLDQUERY_CANCEL) {
+ if (asyncflag & PG_OLDQUERY_CANCEL) {
/* Cancel the outstanding query */
if (dbis->debug >= 1) { (void)PerlIO_printf(DBILOGFP, "dbdpg:
Cancelling old async command\n"); }
if (PQisBusy(imp_dbh->conn)) {
@@ -3650,7 +3650,7 @@
imp_dbh->done_begin = DBDPG_FALSE;
}
}
- else if (asyncflag & DBDPG_OLDQUERY_WAIT || imp_dbh->async_status == -1) {
+ else if (asyncflag & PG_OLDQUERY_WAIT || imp_dbh->async_status == -1) {
/* Finish up the outstanding query and throw out the result, unless an
error */
if (dbis->debug >= 1) { (void)PerlIO_printf(DBILOGFP, "dbdpg: Waiting
for old async command to finish\n"); }
while ((result = PQgetResult(imp_dbh->conn)) != NULL) {
Modified: DBD-Pg/trunk/t/01constants.t
==============================================================================
--- DBD-Pg/trunk/t/01constants.t (original)
+++ DBD-Pg/trunk/t/01constants.t Thu Jul 12 11:39:04 2007
@@ -1,7 +1,7 @@
use strict;
-use Test::More tests => 28;
+use Test::More tests => 31;
-use DBD::Pg qw(:pg_types);
+use DBD::Pg qw(:pg_types :async);
## Should match the list in Pg.xs
@@ -39,3 +39,7 @@
ok(PG_OID == 26, 'PG_OID returns a correct value');
ok(PG_TID == 27, 'PG_TID returns a correct value');
+is(PG_ASYNC, 1, 'PG_ASYNC returns a correct value');
+is(PG_OLDQUERY_CANCEL, 2, 'PG_OLDQUERY_CANCEL returns a correct value');
+is(PG_OLDQUERY_WAIT, 4, 'PG_OLDQUERY_WAIT returns a correct value');
+
Modified: DBD-Pg/trunk/t/08async.t
==============================================================================
--- DBD-Pg/trunk/t/08async.t (original)
+++ DBD-Pg/trunk/t/08async.t Thu Jul 12 11:39:04 2007
@@ -66,7 +66,7 @@
$t=q{Method do() works as expected with an asychronous flag };
eval {
- $res = $dbh->do("SELECT 123", {pg_async => DBDPG_ASYNC});
+ $res = $dbh->do("SELECT 123", {pg_async => PG_ASYNC});
};
is($@, q{}, $t);
is($res, '0E0', $t);
@@ -104,7 +104,7 @@
};
like($@, qr{No async}, $t);
-$res = $dbh->do("SELECT 123", {pg_async => DBDPG_ASYNC});
+$res = $dbh->do("SELECT 123", {pg_async => PG_ASYNC});
$t=q{Method pg_ready() works after a non-async query};
## Sleep a sub-second to make sure the server has caught up
sleep 0.2;
@@ -136,7 +136,7 @@
};
is($@, q{}, $t);
-$dbh->do("SELECT 'async2'", {pg_async => DBDPG_ASYNC});
+$dbh->do("SELECT 'async2'", {pg_async => PG_ASYNC});
$t=q{Method do() fails when async query has not been cleared};
eval {
@@ -185,7 +185,7 @@
}
my $time = time();
- $res = $dbh->do("SELECT pg_sleep(2)", {pg_async => DBDPG_ASYNC});
+ $res = $dbh->do("SELECT pg_sleep(2)", {pg_async => PG_ASYNC});
$time = time()-$time;
$t = qq{Database method do() returns right away when in async mode};
cmp_ok($time, '<=', 1, $t);
@@ -202,7 +202,7 @@
$t=q{Method do() will not work if async query not yet cleared};
eval {
- $dbh->do("SELECT pg_sleep(2)", {pg_async => DBDPG_ASYNC});
+ $dbh->do("SELECT pg_sleep(2)", {pg_async => PG_ASYNC});
};
like($@, qr{previous async}, $t);
@@ -222,7 +222,7 @@
$t=q{Database method do() cancels the previous async when requested};
eval {
- $res = $dbh->do("SELECT pg_sleep(2)", {pg_async => DBDPG_ASYNC
+ DBDPG_OLDQUERY_CANCEL});
+ $res = $dbh->do("SELECT pg_sleep(2)", {pg_async => PG_ASYNC +
PG_OLDQUERY_CANCEL});
};
is($@, q{}, $t);
@@ -236,22 +236,22 @@
$sth = $dbh->prepare("SELECT 567");
$t = q{Running execute after async do() gives an error};
- $dbh->do("SELECT pg_sleep(2)", {pg_async => DBDPG_ASYNC});
+ $dbh->do("SELECT pg_sleep(2)", {pg_async => PG_ASYNC});
eval {
$res = $sth->execute();
};
like($@, qr{previous async}, $t);
$t = q{Running execute after async do() works when told to cancel};
- $sth = $dbh->prepare("SELECT 678", {pg_async => DBDPG_OLDQUERY_CANCEL});
+ $sth = $dbh->prepare("SELECT 678", {pg_async => PG_OLDQUERY_CANCEL});
eval {
$sth->execute();
};
is($@, q{}, $t);
$t = q{Running execute after async do() works when told to wait};
- $dbh->do("SELECT pg_sleep(2)", {pg_async => DBDPG_ASYNC});
- $sth = $dbh->prepare("SELECT 678", {pg_async => DBDPG_OLDQUERY_WAIT});
+ $dbh->do("SELECT pg_sleep(2)", {pg_async => PG_ASYNC});
+ $sth = $dbh->prepare("SELECT 678", {pg_async => PG_OLDQUERY_WAIT});
eval {
$sth->execute();
};
@@ -262,8 +262,8 @@
}; ## end of pg_sleep skip
-$t=q{Method execute() works when prepare has DBDPG_ASYNC flag};
-$sth = $dbh->prepare("SELECT 123", {pg_async => DBDPG_ASYNC});
+$t=q{Method execute() works when prepare has PG_ASYNC flag};
+$sth = $dbh->prepare("SELECT 123", {pg_async => PG_ASYNC});
eval {
$sth->execute();
};
@@ -308,7 +308,7 @@
$t=q{Directly after pg_cancel(), pg_async_status is -1};
is($dbh->{pg_async_status}, -1, $t);
-$t=q{Method execute() works when prepare has DBDPG_ASYNC flag};
+$t=q{Method execute() works when prepare has PG_ASYNC flag};
$sth->execute();
$t=q{After async execute, pg_async_status is 1};
@@ -339,12 +339,12 @@
$dbh->commit();
$sth->execute();
-$t=q{Method prepare() works when passed in DBDPG_OLDQUERY_CANCEL};
+$t=q{Method prepare() works when passed in PG_OLDQUERY_CANCEL};
my $sth2;
my $SQL = "INSERT INTO dbdpg_async_test(id) SELECT 123 UNION SELECT 456";
eval {
- $sth2 = $dbh->prepare($SQL, {pg_async => DBDPG_ASYNC +
DBDPG_OLDQUERY_CANCEL});
+ $sth2 = $dbh->prepare($SQL, {pg_async => PG_ASYNC +
PG_OLDQUERY_CANCEL});
};
is($@, q{}, $t);