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 Aug 12, 2014
1 parent e642231 commit 54e3fea
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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 @@ -192,7 +194,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
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
}
else
{
sql += quotedValue( siter->toString() );
sql += quotedValue( *siter );
}
}
catch ( PGFieldNotFound )
Expand Down

0 comments on commit 54e3fea

Please sign in to comment.