1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
From 54e3feacb11ba36463c7f97ecae114392a2d4479 Mon Sep 17 00:00:00 2001
From: Denis Rouzaud <denis.rouzaud@gmail.com>
Date: Wed, 30 Jul 2014 15:34:27 +0200
Subject: fix editing of NULL values (fixes 0 to NULL, and fixes setting of
NULL values in postgres)
Origin: https://github.com/qgis/QGIS/commit/54e3feacb11ba36463c7f97ecae114392a2d4479
--- a/src/gui/qgsattributeform.cpp
+++ b/src/gui/qgsattributeform.cpp
@@ -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;
@@ -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)" )
--- a/src/providers/postgres/qgspostgresprovider.cpp
+++ b/src/providers/postgres/qgspostgresprovider.cpp
@@ -2024,7 +2024,7 @@ bool QgsPostgresProvider::changeAttribut
}
else
{
- sql += quotedValue( siter->toString() );
+ sql += quotedValue( *siter );
}
}
catch ( PGFieldNotFound )
|