Skip to content

Commit

Permalink
Also update oracle provider for addFeatures flags
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 15, 2017
1 parent f6ccdc1 commit 58026db
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
72 changes: 39 additions & 33 deletions src/providers/oracle/qgsoracleprovider.cpp
Expand Up @@ -1173,7 +1173,7 @@ QString QgsOracleProvider::paramValue( QString fieldValue, const QString &defaul
} }




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


if ( mPrimaryKeyType == PktRowId ) if ( !( flags & QgsFeatureSink::FastInsert ) )
{ {
features->setId( mShared->lookupFid( QList<QVariant>() << QVariant( ins.lastInsertId() ) ) ); if ( mPrimaryKeyType == PktRowId )
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
}
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 )
{ {
QgsField fld = field( idx ); features->setId( mShared->lookupFid( QList<QVariant>() << QVariant( ins.lastInsertId() ) ) );
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
}
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 );


QVariant v = getfid.value( col++ ); int col = 0;
if ( v.type() != fld.type() ) Q_FOREACH ( int idx, mPrimaryKeyAttrs )
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() ); {
features->setAttribute( idx, v ); 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 );
}
} }
} }
} }
Expand All @@ -1342,29 +1345,32 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
throw OracleException( tr( "Could not commit transaction" ), db ); throw OracleException( tr( "Could not commit transaction" ), db );
} }


// update feature ids if ( !( flags & QgsFeatureSink::FastInsert ) )
if ( mPrimaryKeyType == PktInt || mPrimaryKeyType == PktFidMap )
{ {
for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); ++features ) // update feature ids
if ( mPrimaryKeyType == PktInt || mPrimaryKeyType == PktFidMap )
{ {
QgsAttributes attributevec = features->attributes(); for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); ++features )

if ( mPrimaryKeyType == PktInt )
{ {
features->setId( STRING_TO_FID( attributevec[ mPrimaryKeyAttrs[0] ] ) ); QgsAttributes attributevec = features->attributes();
}
else
{
QList<QVariant> primaryKeyVals;


Q_FOREACH ( int idx, mPrimaryKeyAttrs ) if ( mPrimaryKeyType == PktInt )
{ {
primaryKeyVals << attributevec[ idx ]; features->setId( STRING_TO_FID( attributevec[ mPrimaryKeyAttrs[0] ] ) );
} }
else
{
QList<QVariant> primaryKeyVals;


features->setId( mShared->lookupFid( QVariant( primaryKeyVals ) ) ); Q_FOREACH ( int idx, mPrimaryKeyAttrs )
{
primaryKeyVals << attributevec[ idx ];
}

features->setId( mShared->lookupFid( QVariant( primaryKeyVals ) ) );
}
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
} }
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion src/providers/oracle/qgsoracleprovider.h
Expand Up @@ -133,7 +133,7 @@ class QgsOracleProvider : public QgsVectorDataProvider
QgsAttributeList pkAttributeIndexes() const override { return mPrimaryKeyAttrs; } QgsAttributeList pkAttributeIndexes() const override { return mPrimaryKeyAttrs; }
QVariant defaultValue( QString fieldName, QString tableName = QString::null, QString schemaName = QString::null ); QVariant defaultValue( QString fieldName, QString tableName = QString::null, QString schemaName = QString::null );
QVariant defaultValue( int fieldId ) const override; QVariant defaultValue( int fieldId ) const override;
bool addFeatures( QgsFeatureList &flist ) override; bool addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flags flags = 0 ) override;
bool deleteFeatures( const QgsFeatureIds &id ) override; bool deleteFeatures( const QgsFeatureIds &id ) override;
bool addAttributes( const QList<QgsField> &attributes ) override; bool addAttributes( const QList<QgsField> &attributes ) override;
bool deleteAttributes( const QgsAttributeIds &ids ) override; bool deleteAttributes( const QgsAttributeIds &ids ) override;
Expand Down

0 comments on commit 58026db

Please sign in to comment.