Skip to content

Commit 9cfa285

Browse files
authoredMay 1, 2020
Merge pull request #36128 from qgis-bot/backport-36124-to-release-3_12
[Backport release-3_12] Fixed fetching NULL bigint pgsql attributes. Fixes #36011
2 parents 3e21da8 + 57bde67 commit 9cfa285

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎src/providers/postgres/qgspostgresfeatureiterator.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,14 @@ void QgsPostgresFeatureIterator::getFeatureAttribute( int idx, QgsPostgresResult
859859
}
860860
case QVariant::LongLong:
861861
{
862-
v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), QString::number( mConn->getBinaryInt( queryResult, row, col ) ), fld.typeName() );
862+
if ( ::PQgetisnull( queryResult.result(), row, col ) )
863+
{
864+
v = QVariant( QVariant::LongLong );
865+
}
866+
else
867+
{
868+
v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), QString::number( mConn->getBinaryInt( queryResult, row, col ) ), fld.typeName() );
869+
}
863870
break;
864871
}
865872
default:

‎tests/src/python/test_provider_postgres.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ def testNonPkBigintField(self):
441441
bigint_with_default_idx = vl.fields().lookupField('bigint_attribute_def')
442442
self.assertEqual(f.attributes()[bigint_with_default_idx], 42)
443443

444+
# check if NULL values are correctly read
445+
bigint_def_null_idx = vl.fields().lookupField('bigint_attribute')
446+
self.assertEqual(f.attributes()[bigint_def_null_idx], NULL)
447+
444448
# check if we can overwrite a default value
445449
vl.startEditing()
446450
vl.changeAttributeValue(f.id(), bigint_with_default_idx, 43)

0 commit comments

Comments
 (0)
Please sign in to comment.