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 1, 2021
1 parent 2e5e626 commit 082aa7bbcb847b9ed507e808203bb23c979c4c45
@@ -1203,7 +1203,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 );
}
@@ -139,7 +139,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()
@@ -3203,6 +3203,32 @@ def testInsertOnlyFieldIsEditable(self):
self.assertTrue(QgsVectorLayerUtils.fieldIsEditable(vl, 0, feature))
self.assertTrue(QgsVectorLayerUtils.fieldIsEditable(vl, 1, feature))

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 082aa7b

Please sign in to comment.