Skip to content
Permalink
Browse files

postgres provider: improve error handling

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13374 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Apr 24, 2010
1 parent d66171d commit 5f4b8251c84c2a8e188573b1f4ee959631208a41
Showing with 29 additions and 32 deletions.
  1. +29 −32 src/providers/postgres/qgspostgresprovider.cpp
@@ -2737,7 +2737,7 @@ bool QgsPostgresProvider::setSubsetString( QString theSQL )
{
QString prevWhere = sqlWhereClause;

sqlWhereClause = theSQL;
sqlWhereClause = theSQL.trimmed();

if ( !mIsDbPrimaryKey && !uniqueData( mQuery, primaryKey ) )
{
@@ -3207,54 +3207,51 @@ bool QgsPostgresProvider::Conn::openCursor( QString cursorName, QString sql )

bool QgsPostgresProvider::Conn::closeCursor( QString cursorName )
{
bool res = PQexecNR( QString( "CLOSE %1" ).arg( cursorName ) );
if ( !PQexecNR( QString( "CLOSE %1" ).arg( cursorName ) ) )
return false;

if ( --openCursors == 0 )
{
QgsDebugMsg( "Committing read-only transaction" );
PQexecNR( "COMMIT" );
}

return res;
return true;
}

bool QgsPostgresProvider::Conn::PQexecNR( QString query )
{
Result res = ::PQexec( conn, query.toUtf8() );
if ( res )
if ( !res )
{
int errorStatus = PQresultStatus( res );
if ( errorStatus != PGRES_COMMAND_OK )
{
QgsDebugMsgLevel( QString( "Query: %1 returned no result buffer" ).arg( query ), 3 );
return false;
}

if ( PQresultStatus( res ) == PGRES_COMMAND_OK )
return true;

#ifdef QGISDEBUG
QString err = QString( "Query: %1 returned %2 [%3]" )
.arg( query )
.arg( errorStatus )
.arg( QString::fromUtf8( PQresultErrorMessage( res ) ) );
QgsDebugMsgLevel( err, 3 );
QString err = QString( "Query: %1 returned %2 [%3]" )
.arg( query )
.arg( errorStatus )
.arg( QString::fromUtf8( PQresultErrorMessage( res ) ) );
QgsDebugMsg( err );
#endif
if ( openCursors )
{
PQexecNR( "ROLLBACK" );

QgsPostgresProvider::showMessageBox(
tr( "Query failed" ),
tr( "%1 cursor states lost.\nSQL: %2\nResult: %3 (%4)" )
.arg( openCursors )
.arg( query )
.arg( errorStatus )
.arg( QString::fromUtf8( PQresultErrorMessage( res ) ) ) );
openCursors = 0;

PQexecNR( "BEGIN READ ONLY" );
}
}
return errorStatus == PGRES_COMMAND_OK;
}
else
if ( openCursors )
{
QgsDebugMsgLevel( QString( "Query: %1 returned no result buffer" ).arg( query ), 3 );
QgsPostgresProvider::showMessageBox(
tr( "Query failed" ),
tr( "%1 cursor states lost.\nSQL: %2\nResult: %3 (%4)" )
.arg( openCursors )
.arg( query )
.arg( errorStatus )
.arg( QString::fromUtf8( PQresultErrorMessage( res ) ) ) );
openCursors = 0;
}

PQexecNR( "ROLLBACK" );

return false;
}

0 comments on commit 5f4b825

Please sign in to comment.
You can’t perform that action at this time.