Skip to content

Commit

Permalink
[oracle] Fix handling of NULL values when add features to provider
Browse files Browse the repository at this point in the history
Fixes NULL attribute values are incorrectly converted to empty
strings or 0 numeric values instead of NULL.
  • Loading branch information
nyalldawson committed Apr 26, 2018
1 parent 201f108 commit 3a3b0fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/providers/oracle/qgsoracleprovider.cpp
Expand Up @@ -1301,11 +1301,14 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flag
QVariant value = attributevec.value( fieldId[i], QVariant() );

QString v;
if ( !value.isValid() )
if ( !value.isValid() || value.isNull() )
{
QgsField fld = field( fieldId[i] );
v = paramValue( defaultValues[i], defaultValues[i] );
features->setAttribute( fieldId[i], convertValue( fld.type(), v ) );
if ( mPrimaryKeyAttrs.contains( i ) && !defaultValues.at( i ).isEmpty() )
{
QgsField fld = field( fieldId[i] );
v = paramValue( defaultValues[i], defaultValues[i] );
features->setAttribute( fieldId[i], convertValue( fld.type(), v ) );
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_oracle.py
Expand Up @@ -67,7 +67,7 @@ def execSQLCommand(self, sql, ignore_errors=False):
def disabled_getSource(self):
# create temporary table for edit tests
self.execSQLCommand('DROP TABLE "QGIS"."EDIT_DATA"', ignore_errors=True)
self.execSQLCommand("""CREATE TABLE QGIS.EDIT_DATA ("pk" INTEGER PRIMARY KEY, "cnt" INTEGER, "name" VARCHAR2(100), "name2" VARCHAR2(100), "num_char" VARCHAR2(100), GEOM SDO_GEOMETRY)""")
self.execSQLCommand("""CREATE TABLE QGIS.EDIT_DATA ("pk" INTEGER GENERATED by default ON null as IDENTITY(START WITH 1 INCREMENT BY 1) PRIMARY KEY, "cnt" INTEGER, "name" VARCHAR2(100), "name2" VARCHAR2(100), "num_char" VARCHAR2(100), GEOM SDO_GEOMETRY)""")
self.execSQLCommand("""INSERT INTO QGIS.EDIT_DATA ("pk", "cnt", "name", "name2", "num_char", GEOM)
SELECT 5, -200, NULL, 'NuLl', '5', SDO_GEOMETRY( 2001,4326,SDO_POINT_TYPE(-71.123, 78.23, NULL), NULL, NULL) from dual
UNION ALL SELECT 3, 300, 'Pear', 'PEaR', '3', NULL from dual
Expand Down

0 comments on commit 3a3b0fe

Please sign in to comment.