Skip to content

Commit 12cb6fc

Browse files
committed
[wfs] fix turning attribute value to NULL
1 parent 5eddbb6 commit 12cb6fc

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/providers/wfs/qgswfsprovider.cpp

+19-6
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,16 @@ QString QgsWFSProvider::convertToXML( const QVariant &value )
10491049
if ( value.type() == QVariant::DateTime )
10501050
{
10511051
QDateTime dt = value.toDateTime().toUTC();
1052-
valueStr.sprintf( "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
1053-
dt.date().year(), dt.date().month(), dt.date().day(),
1054-
dt.time().hour(), dt.time().minute(), dt.time().second(), dt.time().msec() );
1052+
if ( !dt.isNull() )
1053+
{
1054+
valueStr.sprintf( "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
1055+
dt.date().year(), dt.date().month(), dt.date().day(),
1056+
dt.time().hour(), dt.time().minute(), dt.time().second(), dt.time().msec() );
1057+
}
1058+
else
1059+
{
1060+
valueStr = QString();
1061+
}
10551062
}
10561063
return valueStr;
10571064
}
@@ -1095,9 +1102,15 @@ bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
10951102
propertyElem.appendChild( nameElem );
10961103

10971104
QDomElement valueElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, QStringLiteral( "Value" ) );
1098-
QDomText valueText = transactionDoc.createTextNode( convertToXML( attMapIt.value() ) );
1099-
valueElem.appendChild( valueText );
1100-
propertyElem.appendChild( valueElem );
1105+
1106+
if ( attMapIt.value().isValid() && !attMapIt.value().isNull() )
1107+
{
1108+
// WFS does not support :nil='true'
1109+
// if value is NULL, do not add value element
1110+
QDomText valueText = transactionDoc.createTextNode( convertToXML( attMapIt.value() ) );
1111+
valueElem.appendChild( valueText );
1112+
propertyElem.appendChild( valueElem );
1113+
}
11011114

11021115
updateElem.appendChild( propertyElem );
11031116
}

0 commit comments

Comments
 (0)