@@ -2737,7 +2737,7 @@ bool QgsPostgresProvider::setSubsetString( QString theSQL )
27372737{
27382738 QString prevWhere = sqlWhereClause;
27392739
2740- sqlWhereClause = theSQL;
2740+ sqlWhereClause = theSQL. trimmed () ;
27412741
27422742 if ( !mIsDbPrimaryKey && !uniqueData ( mQuery , primaryKey ) )
27432743 {
@@ -3207,54 +3207,51 @@ bool QgsPostgresProvider::Conn::openCursor( QString cursorName, QString sql )
32073207
32083208bool QgsPostgresProvider::Conn::closeCursor ( QString cursorName )
32093209{
3210- bool res = PQexecNR ( QString ( " CLOSE %1" ).arg ( cursorName ) );
3210+ if ( !PQexecNR ( QString ( " CLOSE %1" ).arg ( cursorName ) ) )
3211+ return false ;
32113212
32123213 if ( --openCursors == 0 )
32133214 {
32143215 QgsDebugMsg ( " Committing read-only transaction" );
32153216 PQexecNR ( " COMMIT" );
32163217 }
32173218
3218- return res ;
3219+ return true ;
32193220}
32203221
32213222bool QgsPostgresProvider::Conn::PQexecNR ( QString query )
32223223{
32233224 Result res = ::PQexec ( conn, query.toUtf8 () );
3224- if ( res )
3225+ if ( ! res )
32253226 {
3226- int errorStatus = PQresultStatus ( res );
3227- if ( errorStatus != PGRES_COMMAND_OK )
3228- {
3227+ QgsDebugMsgLevel ( QString ( " Query: %1 returned no result buffer" ).arg ( query ), 3 );
3228+ return false ;
3229+ }
3230+
3231+ if ( PQresultStatus ( res ) == PGRES_COMMAND_OK )
3232+ return true ;
3233+
32293234#ifdef QGISDEBUG
3230- QString err = QString ( " Query: %1 returned %2 [%3]" )
3231- .arg ( query )
3232- .arg ( errorStatus )
3233- .arg ( QString::fromUtf8 ( PQresultErrorMessage ( res ) ) );
3234- QgsDebugMsgLevel ( err, 3 );
3235+ QString err = QString ( " Query: %1 returned %2 [%3]" )
3236+ .arg ( query )
3237+ .arg ( errorStatus )
3238+ .arg ( QString::fromUtf8 ( PQresultErrorMessage ( res ) ) );
3239+ QgsDebugMsg ( err );
32353240#endif
3236- if ( openCursors )
3237- {
3238- PQexecNR ( " ROLLBACK" );
3239-
3240- QgsPostgresProvider::showMessageBox (
3241- tr ( " Query failed" ),
3242- tr ( " %1 cursor states lost.\n SQL: %2\n Result: %3 (%4)" )
3243- .arg ( openCursors )
3244- .arg ( query )
3245- .arg ( errorStatus )
3246- .arg ( QString::fromUtf8 ( PQresultErrorMessage ( res ) ) ) );
3247- openCursors = 0 ;
3248-
3249- PQexecNR ( " BEGIN READ ONLY" );
3250- }
3251- }
3252- return errorStatus == PGRES_COMMAND_OK;
3253- }
3254- else
3241+ if ( openCursors )
32553242 {
3256- QgsDebugMsgLevel ( QString ( " Query: %1 returned no result buffer" ).arg ( query ), 3 );
3243+ QgsPostgresProvider::showMessageBox (
3244+ tr ( " Query failed" ),
3245+ tr ( " %1 cursor states lost.\n SQL: %2\n Result: %3 (%4)" )
3246+ .arg ( openCursors )
3247+ .arg ( query )
3248+ .arg ( errorStatus )
3249+ .arg ( QString::fromUtf8 ( PQresultErrorMessage ( res ) ) ) );
3250+ openCursors = 0 ;
32573251 }
3252+
3253+ PQexecNR ( " ROLLBACK" );
3254+
32583255 return false ;
32593256}
32603257
0 commit comments