From 3e3f1d42d9e8d113e05c5ad8970498e1bb52a152 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 27 Jul 2017 09:46:08 +1000 Subject: [PATCH] Fix some unhandled db errors in user profiles (thanks to Coverity) --- src/core/qgsuserprofile.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/qgsuserprofile.cpp b/src/core/qgsuserprofile.cpp index 979e68bc57d..c42698fa688 100644 --- a/src/core/qgsuserprofile.cpp +++ b/src/core/qgsuserprofile.cpp @@ -21,6 +21,7 @@ #include #include #include +#include QgsUserProfile::QgsUserProfile( const QString &folder ) { @@ -76,10 +77,12 @@ const QString QgsUserProfile::alias() const QString profileAlias = name(); if ( query.exec() ) { - query.next(); - QString alias = query.value( 0 ).toString(); - if ( !alias.isEmpty() ) - profileAlias = alias; + if ( query.next() ) + { + QString alias = query.value( 0 ).toString(); + if ( !alias.isEmpty() ) + profileAlias = alias; + } } db.close(); return profileAlias; @@ -108,7 +111,10 @@ QgsError QgsUserProfile::setAlias( const QString &alias ) QString sql = "INSERT OR REPLACE INTO tbl_config_variables VALUES ('ALIAS', :alias);"; query.prepare( sql ); query.bindValue( ":alias", alias ); - query.exec(); + if ( !query.exec() ) + { + error.append( QObject::tr( "Could not save alias to database: %1" ).arg( query.lastError().text() ) ); + } db.close(); return error; }