Skip to content

Commit 04e3796

Browse files
committed
[postgres] Avoid crash when fetching default value fails
1 parent 81e86ac commit 04e3796

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/core/qgsvectordataprovider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ QStringList QgsVectorDataProvider::errors() const
606606
return mErrors;
607607
}
608608

609-
void QgsVectorDataProvider::pushError( const QString& msg )
609+
void QgsVectorDataProvider::pushError( const QString& msg ) const
610610
{
611611
QgsDebugMsg( msg );
612612
mErrors << msg;
@@ -722,4 +722,4 @@ QStringList QgsVectorDataProvider::smEncodings;
722722
QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer*, const QList<QgsVectorLayer*>& ) const
723723
{
724724
return QList<QgsRelation>();
725-
}
725+
}

src/core/qgsvectordataprovider.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
445445

446446
signals:
447447
/** Signals an error in this provider */
448-
void raiseError( const QString& msg );
448+
void raiseError( const QString& msg ) const;
449449

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

468-
void pushError( const QString& msg );
468+
void pushError( const QString& msg ) const;
469469

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

481481
/** List of errors */
482-
QStringList mErrors;
482+
mutable QStringList mErrors;
483483

484484
static QStringList smEncodings;
485485

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,13 @@ QVariant QgsPostgresProvider::defaultValue( int fieldId ) const
17071707

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

1710-
return convertValue( fld.type(), fld.subType(), res.PQgetvalue( 0, 0 ) );
1710+
if ( res.result() )
1711+
return convertValue( fld.type(), fld.subType(), res.PQgetvalue( 0, 0 ) );
1712+
else
1713+
{
1714+
pushError( tr( "Could not execute query" ) );
1715+
return QVariant();
1716+
}
17111717
}
17121718

17131719
return defVal;

0 commit comments

Comments
 (0)