Skip to content

Commit

Permalink
PG fix test SELECT NULL::bool -> None
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 13, 2020
1 parent 792fa4b commit 555c6c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/providers/postgres/qgspostgresproviderconnection.cpp
Expand Up @@ -277,9 +277,12 @@ QList<QVariantList> QgsPostgresProviderConnection::executeSqlPrivate( const QStr
const QVariant::Type vType { typeMap.value( colIdx, QVariant::Type::String ) };
QVariant val { res.PQgetvalue( rowIdx, colIdx ) };
// Special case for bools: 'f' and 't'
if ( vType == QVariant::Bool && ! val.isNull() )
if ( vType == QVariant::Bool )
{
val = val.toString() == 't';
if ( ! val.toString().isEmpty() )
{
val = val.toString() == 't';
}
}
else if ( val.canConvert( static_cast<int>( vType ) ) )
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsproviderconnection_postgres.py
Expand Up @@ -204,7 +204,7 @@ def test_nulls(self):

md = QgsProviderRegistry.instance().providerMetadata(self.providerKey)
conn = md.createConnection(self.uri, {})
self.assertEqual(conn.executeSql('SELECT NULL::bool'), [[False]])
self.assertEqual(conn.executeSql('SELECT NULL::bool'), [[None]])
self.assertEqual(conn.executeSql('SELECT NULL::text'), [[None]])
self.assertEqual(conn.executeSql('SELECT NULL::bytea'), [[None]])

Expand Down

0 comments on commit 555c6c2

Please sign in to comment.