From 855b3b4e26377647de5c5f9d38485f9f00bc9257 Mon Sep 17 00:00:00 2001 From: "Juergen E. Fischer" Date: Mon, 21 Jan 2019 18:40:39 +0100 Subject: [PATCH] oracle provider: check for valid lastInsertId() on ::addFeatures (fixes #20109) --- src/providers/oracle/qgsoracleprovider.cpp | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/providers/oracle/qgsoracleprovider.cpp b/src/providers/oracle/qgsoracleprovider.cpp index 27252fc15d60..d20c722e9307 100644 --- a/src/providers/oracle/qgsoracleprovider.cpp +++ b/src/providers/oracle/qgsoracleprovider.cpp @@ -1337,19 +1337,22 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flag } else if ( mPrimaryKeyType == PktInt || mPrimaryKeyType == PktFidMap ) { - getfid.addBindValue( QVariant( ins.lastInsertId() ) ); - if ( !getfid.exec() || !getfid.next() ) - throw OracleException( tr( "Could not retrieve feature id %1" ).arg( features->id() ), getfid ); - - int col = 0; - Q_FOREACH ( int idx, mPrimaryKeyAttrs ) + if ( ins.lastInsertId().isValid() ) { - QgsField fld = field( idx ); + getfid.addBindValue( QVariant( ins.lastInsertId() ) ); + if ( !getfid.exec() || !getfid.next() ) + throw OracleException( tr( "Could not retrieve feature id %1" ).arg( features->id() ), getfid ); - QVariant v = getfid.value( col++ ); - if ( v.type() != fld.type() ) - v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() ); - features->setAttribute( idx, v ); + int col = 0; + Q_FOREACH ( int idx, mPrimaryKeyAttrs ) + { + QgsField fld = field( idx ); + + QVariant v = getfid.value( col++ ); + if ( v.type() != fld.type() ) + v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() ); + features->setAttribute( idx, v ); + } } } }