Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed fetching NULL bigint pgsql attributes. Fixes #36011
  • Loading branch information
espinafre committed May 1, 2020
1 parent bc3cea9 commit 5202d08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -859,7 +859,14 @@ void QgsPostgresFeatureIterator::getFeatureAttribute( int idx, QgsPostgresResult
}
case QVariant::LongLong:
{
v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), QString::number( mConn->getBinaryInt( queryResult, row, col ) ), fld.typeName() );
if ( ::PQgetisnull( queryResult.result(), row, col ) )
{
v = QVariant( QVariant::LongLong );
}
else
{
v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), QString::number( mConn->getBinaryInt( queryResult, row, col ) ), fld.typeName() );
}
break;
}
default:
Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -441,6 +441,10 @@ def testNonPkBigintField(self):
bigint_with_default_idx = vl.fields().lookupField('bigint_attribute_def')
self.assertEqual(f.attributes()[bigint_with_default_idx], 42)

# check if NULL values are correctly read
bigint_def_null_idx = vl.fields().lookupField('bigint_attribute')
self.assertEqual(f.attributes()[bigint_def_null_idx], NULL)

# check if we can overwrite a default value
vl.startEditing()
vl.changeAttributeValue(f.id(), bigint_with_default_idx, 43)
Expand Down

0 comments on commit 5202d08

Please sign in to comment.