[postgres] Avoid crash when fetching default value fails

This commit is contained in:
Matthias Kuhn 2016-10-18 10:32:08 +02:00
parent 81e86accc3
commit 04e3796610
3 changed files with 12 additions and 6 deletions

View File

@ -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;
@ -722,4 +722,4 @@ QStringList QgsVectorDataProvider::smEncodings;
QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer*, const QList<QgsVectorLayer*>& ) const
{
return QList<QgsRelation>();
}
}

View File

@ -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();
@ -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;
@ -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;

View File

@ -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;