Skip to content
Permalink
Browse files

PG provider connection API: convert to bools

Fixes #33130

Backport from master/2.16
  • Loading branch information
elpaso authored and nyalldawson committed Oct 29, 2020
1 parent baf00ad commit 613f5b8f4142e4c76f06029fddc56fc142bd5f56
@@ -277,7 +277,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 ) );
}
@@ -183,6 +183,14 @@ def test_pk_cols_order(self):
conn = md.createConnection(self.uri, {})
self.assertEqual(self._table_by_name(conn.tables(), 'bikes_view').primaryKeyColumns(), ['pk', 'name'])
self.assertEqual(self._table_by_name(conn.tables(), 'some_poly_data_view').primaryKeyColumns(), ['pk', 'geom'])

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__':

0 comments on commit 613f5b8

Please sign in to comment.
You can’t perform that action at this time.