Skip to content

Commit

Permalink
Fix some unhandled db errors in user profiles (thanks to Coverity)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 26, 2017
1 parent 687adbf commit 3e3f1d4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/core/qgsuserprofile.cpp
Expand Up @@ -21,6 +21,7 @@
#include <QSettings>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>

QgsUserProfile::QgsUserProfile( const QString &folder )
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3e3f1d4

Please sign in to comment.