mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[postgres] Avoid crash when fetching default value fails
This commit is contained in:
parent
81e86accc3
commit
04e3796610
@ -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>();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user