[Qgis-developer] qgspostgresprovider and cursors
Stefanie Tellex
stefie10 at media.mit.edu
Thu Nov 6 14:06:25 EST 2008
Hi,
I had a strange bug where the transaction got aborted because of a bad
SQL where clause, and after it was aborted, future queries were being
ignored.
The attached patch makes it go away by ensuring that the current
transaction is closed and all existing cursors are closed before setting
a new subset query. It also makes it possible to close a cursor more
than once without a problem by preventing openCursors from falling below
zero.
However the code for managing cursors and transactions in
QgsPostgresProvider was pretty confusing, and I suspect there are
similar bugs hiding out still.
It's against revision 9563.
Thanks,
Stefanie
-------------- next part --------------
Index: qgis/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- qgis.orig/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp 2008-11-06 11:51:42.000000000 -0500
+++ qgis/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp 2008-11-06 11:51:44.000000000 -0500
@@ -2173,6 +2173,7 @@
void QgsPostgresProvider::setSubsetString( QString theSQL )
{
+ connectionRO->closeCursor( QString( "qgisf%1" ).arg( providerId ) );
sqlWhereClause = theSQL;
// Update datasource uri too
mUri.setSql( theSQL );
@@ -2619,8 +2620,11 @@
bool QgsPostgresProvider::Conn::closeCursor( QString cursorName )
{
bool res = PQexecNR( QString( "CLOSE %1" ).arg( cursorName ) );
-
- if ( --openCursors == 0 )
+ --openCursors;
+ if (openCursors < 0) {
+ openCursors = 0;
+ }
+ if (openCursors == 0 )
{
QgsDebugMsg( "Commiting read-only transaction" );
PQexecNR( "COMMIT" );
More information about the Qgis-developer
mailing list