Skip to content
Permalink
Browse files
database providers: cope with empty attribute changes (fixes #12040)
  • Loading branch information
jef-n committed Jan 30, 2015
1 parent 6eb6112 commit 843cf04920f6825bee451a4c5005e88711ce5b6d
@@ -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;
@@ -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() )
@@ -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()];
@@ -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;
@@ -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 );
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 )
{
@@ -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 )
{

0 comments on commit 843cf04

Please sign in to comment.