Skip to content
Permalink
Browse files
[Postgres] Fixes #42778 : don't quote integer array elements to match…
… array_out()
  • Loading branch information
troopa81 authored and nyalldawson committed Jun 14, 2021
1 parent a76f330 commit 91556044e25f05b0a2ab013532d0360488737e47
Showing with 28 additions and 2 deletions.
  1. +1 −1 src/providers/postgres/qgspostgresconn.cpp
  2. +1 −1 tests/src/providers/testqgspostgresconn.cpp
  3. +26 −0 tests/src/python/test_provider_postgres.py
@@ -1200,7 +1200,7 @@ static QString quotedList( const QVariantList &list )
}

QString inner = i->toString();
if ( inner.startsWith( '{' ) )
if ( inner.startsWith( '{' ) || i->type() == QVariant::Int || i->type() == QVariant::LongLong )
{
ret.append( inner );
}
@@ -82,7 +82,7 @@ class TestQgsPostgresConn: public QObject
QVariantList list;
list << 1 << -5;
const QString actual = QgsPostgresConn::quotedValue( list );
QCOMPARE( actual, QString( "E'{\"1\",\"-5\"}'" ) );
QCOMPARE( actual, QString( "E'{1,-5}'" ) );
}

void quotedValue2DimArray()
@@ -3106,6 +3106,32 @@ def _get_layer(sql):
self.assertEqual(l.fields().count(), 3)
self.assertEqual([f.name() for f in l.fields()], ['__rid__', 'id', 'id (2)'])

def testPkeyIntArray(self):
"""
Test issue #42778 when pkey is an int array
"""
md = QgsProviderRegistry.instance().providerMetadata("postgres")
conn = md.createConnection(self.dbconn, {})
conn.executeSql('DROP TABLE IF EXISTS public.test_pkey_intarray')
conn.executeSql('CREATE TABLE public.test_pkey_intarray (id _int8 PRIMARY KEY, name VARCHAR(64))')
conn.executeSql("""INSERT INTO public.test_pkey_intarray (id, name) VALUES('{0,0,19111815}', 'test')""")

uri = QgsDataSourceUri(self.dbconn +
' sslmode=disable key=\'id\' table="public"."test_pkey_intarray" sql=')
vl = QgsVectorLayer(uri.uri(), 'test', 'postgres')
self.assertTrue(vl.isValid())

feat = next(vl.getFeatures())
self.assertTrue(feat.isValid())
self.assertEqual(feat["name"], "test")

fid = feat.id()
self.assertTrue(fid > 0)

feat = vl.getFeature(fid)
self.assertTrue(feat.isValid())
self.assertEqual(feat["name"], "test")


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

0 comments on commit 9155604

Please sign in to comment.