Skip to content

Commit

Permalink
database providers: cope with empty attribute changes (fixes #12040)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 30, 2015
1 parent 6eb6112 commit 843cf04
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
11 changes: 6 additions & 5 deletions src/providers/mssql/qgsmssqlprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ bool QgsMssqlProvider::deleteAttributes( const QgsAttributeIds &attributes )
}


bool QgsMssqlProvider::changeAttributeValues( const QgsChangedAttributesMap & attr_map )
bool QgsMssqlProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_map )
{
if ( attr_map.isEmpty() )
return true;
Expand All @@ -1024,8 +1024,11 @@ bool QgsMssqlProvider::changeAttributeValues( const QgsChangedAttributesMap & at
if ( FID_IS_NEW( fid ) )
continue;

QString statement;
statement = QString( "UPDATE [%1].[%2] SET " ).arg( mSchemaName, mTableName );
const QgsAttributeMap& attrs = it.value();
if ( attrs.isEmpty() )
continue;

QString statement = QString( "UPDATE [%1].[%2] SET " ).arg( mSchemaName, mTableName );

bool first = true;
if ( !mDatabase.isOpen() )
Expand All @@ -1035,8 +1038,6 @@ bool QgsMssqlProvider::changeAttributeValues( const QgsChangedAttributesMap & at
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );

const QgsAttributeMap& attrs = it.value();

for ( QgsAttributeMap::const_iterator it2 = attrs.begin(); it2 != attrs.end(); ++it2 )
{
QgsField fld = mAttributeFields[it2.key()];
Expand Down
9 changes: 5 additions & 4 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ bool QgsOgrProvider::deleteAttributes( const QgsAttributeIds &attributes )
}


bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr_map )
bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_map )
{
if ( attr_map.isEmpty() )
return true;
Expand All @@ -1195,16 +1195,17 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
continue;
}

OGRFeatureH of = OGR_L_GetFeature( ogrLayer, static_cast<long>( FID_TO_NUMBER( fid ) ) );
const QgsAttributeMap &attr = it.value();
if ( attr.isEmpty() )
continue;

OGRFeatureH of = OGR_L_GetFeature( ogrLayer, static_cast<long>( FID_TO_NUMBER( fid ) ) );
if ( !of )
{
pushError( tr( "Feature %1 for attribute update not found." ).arg( fid ) );
continue;
}

const QgsAttributeMap& attr = it.value();

char *oldlocale = setlocale( LC_NUMERIC, NULL );
if ( oldlocale )
oldlocale = strdup( oldlocale );
Expand Down
10 changes: 8 additions & 2 deletions src/providers/oracle/qgsoracleprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,13 +1570,16 @@ bool QgsOracleProvider::deleteAttributes( const QgsAttributeIds& ids )
return returnvalue;
}

bool QgsOracleProvider::changeAttributeValues( const QgsChangedAttributesMap & attr_map )
bool QgsOracleProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_map )
{
bool returnvalue = true;

if ( mIsQuery )
return false;

if ( attr_map.isEmpty() )
return true;

QSqlDatabase db( *mConnection );

try
Expand All @@ -1597,9 +1600,12 @@ bool QgsOracleProvider::changeAttributeValues( const QgsChangedAttributesMap & a
if ( FID_IS_NEW( fid ) )
continue;

const QgsAttributeMap& attrs = iter.value();
if ( attrs.isEmpty() )
continue;

QString sql = QString( "UPDATE %1 SET " ).arg( mQuery );

const QgsAttributeMap& attrs = iter.value();
bool pkChanged = false;

// cycle through the changed attributes of the feature
Expand Down
15 changes: 10 additions & 5 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2020,18 +2020,20 @@ bool QgsPostgresProvider::deleteAttributes( const QgsAttributeIds& ids )
return returnvalue;
}

bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap & attr_map )
bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_map )
{
bool returnvalue = true;

if ( mIsQuery )
return false;

QgsPostgresConn* conn = connectionRW();
if ( attr_map.isEmpty() )
return true;

QgsPostgresConn *conn = connectionRW();
if ( !conn )
{
return false;
}

conn->lock();

try
Expand All @@ -2047,9 +2049,12 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
if ( FID_IS_NEW( fid ) )
continue;

const QgsAttributeMap &attrs = iter.value();
if ( attrs.isEmpty() )
continue;

QString sql = QString( "UPDATE %1 SET " ).arg( mQuery );

const QgsAttributeMap& attrs = iter.value();
bool pkChanged = false;

// cycle through the changed attributes of the feature
Expand Down
11 changes: 8 additions & 3 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3859,12 +3859,15 @@ bool QgsSpatiaLiteProvider::addAttributes( const QList<QgsField> &attributes )
return false;
}

bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap & attr_map )
bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_map )
{
char *errMsg = NULL;
bool toCommit = false;
QString sql;

if ( attr_map.isEmpty() )
return true;

int ret = sqlite3_exec( sqliteHandle, "BEGIN", NULL, NULL, &errMsg );
if ( ret != SQLITE_OK )
{
Expand All @@ -3883,11 +3886,13 @@ bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap
if ( FID_IS_NEW( fid ) )
continue;

const QgsAttributeMap &attrs = iter.value();
if ( attrs.isEmpty() )
continue;

QString sql = QString( "UPDATE %1 SET " ).arg( quotedIdentifier( mTableName ) );
bool first = true;

const QgsAttributeMap & attrs = iter.value();

// cycle through the changed attributes of the feature
for ( QgsAttributeMap::const_iterator siter = attrs.begin(); siter != attrs.end(); ++siter )
{
Expand Down

0 comments on commit 843cf04

Please sign in to comment.