Skip to content

Commit

Permalink
[postgres] Avoid crash when fetching default value fails
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 21, 2016
1 parent 81e86ac commit 04e3796
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/core/qgsvectordataprovider.cpp
Expand Up @@ -606,7 +606,7 @@ QStringList QgsVectorDataProvider::errors() const
return mErrors;
}

void QgsVectorDataProvider::pushError( const QString& msg )
void QgsVectorDataProvider::pushError( const QString& msg ) const
{
QgsDebugMsg( msg );
mErrors << msg;
Expand Down Expand Up @@ -722,4 +722,4 @@ QStringList QgsVectorDataProvider::smEncodings;
QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer*, const QList<QgsVectorLayer*>& ) const
{
return QList<QgsRelation>();
}
}
6 changes: 3 additions & 3 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -445,7 +445,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider

signals:
/** Signals an error in this provider */
void raiseError( const QString& msg );
void raiseError( const QString& msg ) const;

protected:
void clearMinMaxCache();
Expand All @@ -465,7 +465,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
/** The names of the providers native types*/
QList< NativeType > mNativeTypes;

void pushError( const QString& msg );
void pushError( const QString& msg ) const;

/** Old-style mapping of index to name for QgsPalLabeling fix */
QgsAttrPalIndexNameHash mAttrPalIndexName;
Expand All @@ -479,7 +479,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
QMap<QString, QVariant::Type> mOldTypeList;

/** List of errors */
QStringList mErrors;
mutable QStringList mErrors;

static QStringList smEncodings;

Expand Down
8 changes: 7 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -1707,7 +1707,13 @@ QVariant QgsPostgresProvider::defaultValue( int fieldId ) const

QgsPostgresResult res( connectionRO()->PQexec( QString( "SELECT %1" ).arg( defVal.toString() ) ) );

return convertValue( fld.type(), fld.subType(), res.PQgetvalue( 0, 0 ) );
if ( res.result() )
return convertValue( fld.type(), fld.subType(), res.PQgetvalue( 0, 0 ) );
else
{
pushError( tr( "Could not execute query" ) );
return QVariant();
}
}

return defVal;
Expand Down

0 comments on commit 04e3796

Please sign in to comment.