fix editing of NULL values (fixes 0 to NULL, and fixes setting of NULL values in postgres)

This commit is contained in:
Denis Rouzaud 2014-07-30 15:34:27 +02:00
parent 4995305adc
commit aa40d61a8c
2 changed files with 5 additions and 3 deletions

View File

@ -161,7 +161,9 @@ bool QgsAttributeForm::save()
{
QVariant dstVar = dst[eww->fieldIdx()];
QVariant srcVar = eww->value();
if ( dstVar != srcVar && srcVar.isValid() )
// need to check dstVar.isNull() != srcVar.isNull()
// otherwise if dstVar=NULL and scrVar=0, then dstVar = srcVar
if ( ( dstVar != srcVar || dstVar.isNull() != srcVar.isNull() ) && srcVar.isValid() )
{
dst[eww->fieldIdx()] = srcVar;
@ -199,7 +201,7 @@ bool QgsAttributeForm::save()
int n = 0;
for ( int i = 0; i < dst.count(); ++i )
{
if ( dst[i] == src[i] || !dst[i].isValid() )
if ( ( dst[i] == src[i] && dst[i].isNull() == src[i].isNull() ) || !dst[i].isValid() )
{
QgsDebugMsg( "equal or invalid destination" );
QgsDebugMsg( QString( "dst:'%1' (type:%2,isNull:%3,isValid:%4)" )

View File

@ -2024,7 +2024,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
}
else
{
sql += quotedValue( siter->toString() );
sql += quotedValue( *siter );
}
}
catch ( PGFieldNotFound )