Skip to content
Permalink
Browse files

Merge pull request #34815 from elpaso/bugfix-gh34806-pgconnection-char

Connections API fix Postgres char conversion in execSQL
  • Loading branch information
elpaso committed Mar 2, 2020
2 parents a7566de + aac0c92 commit bf18ebc3002c5c394c7dbaa9d7e2107d99e04583
@@ -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:
@@ -219,6 +220,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"""
@@ -228,6 +230,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 bf18ebc

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