Skip to content

Commit

Permalink
fix editing of NULL values (fixes 0 to NULL, and fixes setting of NUL…
Browse files Browse the repository at this point in the history
…L values in postgres)
  • Loading branch information
3nids committed Jul 30, 2014
1 parent 4995305 commit aa40d61
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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)" )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -2024,7 +2024,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
}
else
{
sql += quotedValue( siter->toString() );
sql += quotedValue( *siter );
}
}
catch ( PGFieldNotFound )
Expand Down

2 comments on commit aa40d61

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on aa40d61 Jul 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another candidate for backporting to 2.4?

@3nids
Copy link
Member Author

@3nids 3nids commented on aa40d61 Aug 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 54e3fea

Please sign in to comment.