Skip to content

Commit 58026db

Browse files
committedJun 15, 2017
Also update oracle provider for addFeatures flags
1 parent f6ccdc1 commit 58026db

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed
 

‎src/providers/oracle/qgsoracleprovider.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ QString QgsOracleProvider::paramValue( QString fieldValue, const QString &defaul
11731173
}
11741174

11751175

1176-
bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
1176+
bool QgsOracleProvider::addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flags flags )
11771177
{
11781178
if ( flist.size() == 0 )
11791179
return true;
@@ -1311,26 +1311,29 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
13111311
if ( !ins.exec() )
13121312
throw OracleException( tr( "Could not insert feature %1" ).arg( features->id() ), ins );
13131313

1314-
if ( mPrimaryKeyType == PktRowId )
1314+
if ( !( flags & QgsFeatureSink::FastInsert ) )
13151315
{
1316-
features->setId( mShared->lookupFid( QList<QVariant>() << QVariant( ins.lastInsertId() ) ) );
1317-
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
1318-
}
1319-
else if ( mPrimaryKeyType == PktInt || mPrimaryKeyType == PktFidMap )
1320-
{
1321-
getfid.addBindValue( QVariant( ins.lastInsertId() ) );
1322-
if ( !getfid.exec() || !getfid.next() )
1323-
throw OracleException( tr( "Could not retrieve feature id %1" ).arg( features->id() ), getfid );
1324-
1325-
int col = 0;
1326-
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
1316+
if ( mPrimaryKeyType == PktRowId )
13271317
{
1328-
QgsField fld = field( idx );
1318+
features->setId( mShared->lookupFid( QList<QVariant>() << QVariant( ins.lastInsertId() ) ) );
1319+
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
1320+
}
1321+
else if ( mPrimaryKeyType == PktInt || mPrimaryKeyType == PktFidMap )
1322+
{
1323+
getfid.addBindValue( QVariant( ins.lastInsertId() ) );
1324+
if ( !getfid.exec() || !getfid.next() )
1325+
throw OracleException( tr( "Could not retrieve feature id %1" ).arg( features->id() ), getfid );
13291326

1330-
QVariant v = getfid.value( col++ );
1331-
if ( v.type() != fld.type() )
1332-
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
1333-
features->setAttribute( idx, v );
1327+
int col = 0;
1328+
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
1329+
{
1330+
QgsField fld = field( idx );
1331+
1332+
QVariant v = getfid.value( col++ );
1333+
if ( v.type() != fld.type() )
1334+
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
1335+
features->setAttribute( idx, v );
1336+
}
13341337
}
13351338
}
13361339
}
@@ -1342,29 +1345,32 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
13421345
throw OracleException( tr( "Could not commit transaction" ), db );
13431346
}
13441347

1345-
// update feature ids
1346-
if ( mPrimaryKeyType == PktInt || mPrimaryKeyType == PktFidMap )
1348+
if ( !( flags & QgsFeatureSink::FastInsert ) )
13471349
{
1348-
for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); ++features )
1350+
// update feature ids
1351+
if ( mPrimaryKeyType == PktInt || mPrimaryKeyType == PktFidMap )
13491352
{
1350-
QgsAttributes attributevec = features->attributes();
1351-
1352-
if ( mPrimaryKeyType == PktInt )
1353+
for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); ++features )
13531354
{
1354-
features->setId( STRING_TO_FID( attributevec[ mPrimaryKeyAttrs[0] ] ) );
1355-
}
1356-
else
1357-
{
1358-
QList<QVariant> primaryKeyVals;
1355+
QgsAttributes attributevec = features->attributes();
13591356

1360-
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
1357+
if ( mPrimaryKeyType == PktInt )
13611358
{
1362-
primaryKeyVals << attributevec[ idx ];
1359+
features->setId( STRING_TO_FID( attributevec[ mPrimaryKeyAttrs[0] ] ) );
13631360
}
1361+
else
1362+
{
1363+
QList<QVariant> primaryKeyVals;
13641364

1365-
features->setId( mShared->lookupFid( QVariant( primaryKeyVals ) ) );
1365+
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
1366+
{
1367+
primaryKeyVals << attributevec[ idx ];
1368+
}
1369+
1370+
features->setId( mShared->lookupFid( QVariant( primaryKeyVals ) ) );
1371+
}
1372+
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
13661373
}
1367-
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
13681374
}
13691375
}
13701376

‎src/providers/oracle/qgsoracleprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class QgsOracleProvider : public QgsVectorDataProvider
133133
QgsAttributeList pkAttributeIndexes() const override { return mPrimaryKeyAttrs; }
134134
QVariant defaultValue( QString fieldName, QString tableName = QString::null, QString schemaName = QString::null );
135135
QVariant defaultValue( int fieldId ) const override;
136-
bool addFeatures( QgsFeatureList &flist ) override;
136+
bool addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flags flags = 0 ) override;
137137
bool deleteFeatures( const QgsFeatureIds &id ) override;
138138
bool addAttributes( const QList<QgsField> &attributes ) override;
139139
bool deleteAttributes( const QgsAttributeIds &ids ) override;

0 commit comments

Comments
 (0)
Please sign in to comment.