Skip to content

Commit

Permalink
Fix storing attribute of feature with negative identifier and test
Browse files Browse the repository at this point in the history
The test was also bogus in that it expected an inappropriate FID.
  • Loading branch information
strk committed Jun 9, 2016
1 parent 92dda42 commit 9a96414
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -718,14 +718,17 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int
case pktInt:
case pktUint64:
fid = mConn->getBinaryInt( queryResult, row, col++ );
if ( mSource->mPrimaryKeyType == pktInt )
{
fid = QgsPostgresUtils::int32pk_to_fid( fid );
}
if ( !subsetOfAttributes || fetchAttributes.contains( mSource->mPrimaryKeyAttrs.at( 0 ) ) )
{
feature.setAttribute( mSource->mPrimaryKeyAttrs[0], fid );
}
if ( mSource->mPrimaryKeyType == pktInt )
{
// NOTE: this needs be done _after_ the setAttribute call
// above as we want the attribute value to be 1:1 with
// database value
fid = QgsPostgresUtils::int32pk_to_fid( fid );
}
break;

case pktFidMap:
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_postgres.py
Expand Up @@ -169,7 +169,7 @@ def test_query_attribute(dbconn, query, att, val, fidval):
self.assertEqual(f.attributes()[att_idx], val)
#self.assertEqual(f.id(), val)
self.assertEqual(count, 1)
test_query_attribute(self.dbconn, '(SELECT -1::int4 i, NULL::geometry(Point) g)', 'i', -1, 1)
test_query_attribute(self.dbconn, '(SELECT -1::int4 i, NULL::geometry(Point) g)', 'i', -1, 4294967295)
test_query_attribute(self.dbconn, '(SELECT -1::int2 i, NULL::geometry(Point) g)', 'i', -1, 1)
test_query_attribute(self.dbconn, '(SELECT -1::int8 i, NULL::geometry(Point) g)', 'i', -1, 1)
test_query_attribute(self.dbconn, '(SELECT -65535::int8 i, NULL::geometry(Point) g)', 'i', -65535, 1)
Expand Down

0 comments on commit 9a96414

Please sign in to comment.