Skip to content
Permalink
Browse files

Connectios API fix Postgres char conversion in execSQL

Fixes #34806
  • Loading branch information
elpaso authored and nyalldawson committed Mar 2, 2020
1 parent 1ffda15 commit 74a546932d5d917e53e9c27529fed896ecffa7de
@@ -228,7 +228,6 @@ QList<QVariantList> QgsPostgresProviderConnection::executeSqlPrivate( const QStr
if ( typeRes.size() > 0 && typeRes.first().size() > 0 )
{
static const QStringList intTypes = { QStringLiteral( "oid" ),
QStringLiteral( "char" ),
QStringLiteral( "int2" ),
QStringLiteral( "int4" ),
QStringLiteral( "int8" )
@@ -263,6 +262,10 @@ QList<QVariantList> QgsPostgresProviderConnection::executeSqlPrivate( const QStr
{
vType = QVariant::Bool;
}
else if ( typName == QStringLiteral( "char" ) )
{
vType = QVariant::Char;
}
else
{
QgsDebugMsg( QStringLiteral( "Unhandled PostgreSQL type %1" ).arg( typName ) );
@@ -38,6 +38,7 @@ class TestPyQgsProviderConnectionPostgres(unittest.TestCase, TestPyQgsProviderCo
@classmethod
def setUpClass(cls):
"""Run before all tests"""

TestPyQgsProviderConnectionBase.setUpClass()
cls.postgres_conn = "service='qgis_test'"
if 'QGIS_PGTEST_DB' in os.environ:
@@ -207,6 +208,7 @@ def test_nulls(self):
self.assertEqual(conn.executeSql('SELECT NULL::bool'), [[None]])
self.assertEqual(conn.executeSql('SELECT NULL::text'), [[None]])
self.assertEqual(conn.executeSql('SELECT NULL::bytea'), [[None]])
self.assertEqual(conn.executeSql('SELECT NULL::char'), [[None]])

def test_pk_cols_order(self):
"""Test that PKs are returned in consistent order: see GH #34167"""
@@ -216,6 +218,13 @@ def test_pk_cols_order(self):
self.assertEqual(conn.table('qgis_test', 'bikes_view').primaryKeyColumns(), ['pk', 'name'])
self.assertEqual(conn.table('qgis_test', 'some_poly_data_view').primaryKeyColumns(), ['pk', 'geom'])

def test_char_type_conversion(self):
"""Test char types: see GH #34806"""

md = QgsProviderRegistry.instance().providerMetadata(self.providerKey)
conn = md.createConnection(self.uri, {})
self.assertEqual(conn.executeSql("SELECT relname, relkind FROM pg_class c, pg_namespace n WHERE n.oid = c.relnamespace AND relname = 'bikes_view' AND c.relkind IN ('t', 'v', 'm')"), [['bikes_view', 'v']])


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

0 comments on commit 74a5469

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