[Libpqxx-general] cancellation of synchronous sql statements

Madden, Don (DCOR) don.madden at smithsdetection.com
Fri Aug 21 17:52:07 UTC 2009


Hi Jeroen,

Thanks for making the cancel_query public.

As a starting point for testing cancel query, I've attached a simple
test in the enclosed file called
"test_cancel_query.cxx". The simple test example, will install a signal
handler for SIGALRM so it can run a timer for a short period, invoke a
blocking SQL command for 2s. The timer will raise SIGALRM after 1s and
cancel the blocking SQL command after 1s. The test will pass if the
cancel exception is caught shortly after 1s (e.g. within 1s). For this
test purposes, there is 2 supporting classes of CStopWatch to measure
the time it took from starting the query to the timer expiring and
cancelling the command. To raise the timer signal, there is a class
called CSigAlrmTimer.

It is fully working and testing on my own test environment.
Unfortunatley it isn't fully complete for test/unit as I couldn't work
out how to create a global connection variable for the alarm_hanlder().
Hopefully someone more familiar with test/unit/ should be able to extend
"test_cancel_query.cxx" for this purpose.

Don


-----Original Message-----
From: Jeroen T. Vermeulen [mailto:jtv at xs4all.nl] 
Sent: 20 August 2009 06:19
To: Madden, Don (DCOR)
Cc: libpqxx-general at pgfoundry.org
Subject: Re: [Libpqxx-general] cancellation of synchronous sql
statements

On Wed, August 19, 2009 00:07, Madden, Don (DCOR) wrote:

> If you execute commands (asynchronously) in a "pipeline", there is a
> public method to "cancel()" an ongoing query.
>
>  If you execute the SQL commands in a blocking call, you could the
> cancel the ongoing command via a signal handler (e.g SIGALRM). lIbpq
> supports this via PQcancel(). "libpqxx" doesn't seem to have any
> equivalent public method. In the connection_base, the wrapper method,
> "cancel_query()" is private.  Likewise I couldn't find any public
method
> to get a raw libpq connection, PGConn in libpqxx's connection_base
> classes?

This sounds like a useful feature.  I just made cancel_query public for
your use, and made the function try a bit harder to be graceful about
deactivated connections.  See revision [1574].  It should work safely
from
signal handlers; using it from other threads is safe for libpq versions
8.0 and up, but not before.  (The thread-safety descriptions already
knew
about this).

What this still needs is a good test.  I'd be most grateful if you could
come up with one that fits in the test suite in test/unit/ !



Jeroen


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


 
************************************************
The information contained in, or attached to, this e-mail, may contain confidential information and is intended solely for the use of the individual or entity to whom they are addressed and may be subject to legal privilege.  If you have received this e-mail in error you should notify the sender immediately by reply e-mail, delete the message from your system and notify your system manager.  Please do not copy it for any purpose, or disclose its contents to any other person.  The views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company.  The recipient should check this e-mail and any attachments for the presence of viruses.  The company accepts no liability for any damage caused, directly or indirectly, by any virus transmitted in this email.
************************************************
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_cancel_query.cxx
Type: application/octet-stream
Size: 4796 bytes
Desc: test_cancel_query.cxx
URL: <http://pgfoundry.org/pipermail/libpqxx-general/attachments/20090821/d55a5866/attachment.obj>


More information about the Libpqxx-general mailing list