Skip to content

Commit aa40d61

Browse files
committed
fix editing of NULL values (fixes 0 to NULL, and fixes setting of NULL values in postgres)
1 parent 4995305 commit aa40d61

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/gui/qgsattributeform.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ bool QgsAttributeForm::save()
161161
{
162162
QVariant dstVar = dst[eww->fieldIdx()];
163163
QVariant srcVar = eww->value();
164-
if ( dstVar != srcVar && srcVar.isValid() )
164+
// need to check dstVar.isNull() != srcVar.isNull()
165+
// otherwise if dstVar=NULL and scrVar=0, then dstVar = srcVar
166+
if ( ( dstVar != srcVar || dstVar.isNull() != srcVar.isNull() ) && srcVar.isValid() )
165167
{
166168
dst[eww->fieldIdx()] = srcVar;
167169

@@ -199,7 +201,7 @@ bool QgsAttributeForm::save()
199201
int n = 0;
200202
for ( int i = 0; i < dst.count(); ++i )
201203
{
202-
if ( dst[i] == src[i] || !dst[i].isValid() )
204+
if ( ( dst[i] == src[i] && dst[i].isNull() == src[i].isNull() ) || !dst[i].isValid() )
203205
{
204206
QgsDebugMsg( "equal or invalid destination" );
205207
QgsDebugMsg( QString( "dst:'%1' (type:%2,isNull:%3,isValid:%4)" )

src/providers/postgres/qgspostgresprovider.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
20242024
}
20252025
else
20262026
{
2027-
sql += quotedValue( siter->toString() );
2027+
sql += quotedValue( *siter );
20282028
}
20292029
}
20302030
catch ( PGFieldNotFound )

0 commit comments

Comments
 (0)