Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PG provider connection API: convert to bools
Fixes #33130
  • Loading branch information
elpaso committed Nov 28, 2019
1 parent 6ca436d commit 8d95650
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/providers/postgres/qgspostgresproviderconnection.cpp
Expand Up @@ -294,7 +294,12 @@ QList<QVariantList> QgsPostgresProviderConnection::executeSqlPrivate( const QStr
{
const QVariant::Type vType { typeMap.value( colIdx, QVariant::Type::String ) };
QVariant val { res.PQgetvalue( rowIdx, colIdx ) };
if ( val.canConvert( static_cast<int>( vType ) ) )
// Special case for bools: 'f' and 't'
if ( vType == QVariant::Bool )
{
val = val.toString() == 't';
}
else if ( val.canConvert( static_cast<int>( vType ) ) )
{
val.convert( static_cast<int>( vType ) );
}
Expand Down
8 changes: 8 additions & 0 deletions tests/src/python/test_qgsproviderconnection_postgres.py
Expand Up @@ -177,6 +177,14 @@ def test_postgis_raster_rename(self):
self.assertFalse('Raster2' in table_names)
self.assertTrue('Raster1' in table_names)

def test_true_false(self):
"""Test returned values from BOOL queries"""

md = QgsProviderRegistry.instance().providerMetadata(self.providerKey)
conn = md.createConnection(self.uri, {})
self.assertEqual(conn.executeSql('SELECT FALSE'), [[False]])
self.assertEqual(conn.executeSql('SELECT TRUE'), [[True]])


if __name__ == '__main__':
unittest.main()

0 comments on commit 8d95650

Please sign in to comment.