Skip to content

Commit

Permalink
Handle strings with chars that require escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jun 10, 2019
1 parent b43c870 commit 114affc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -1066,7 +1066,7 @@ QString QgsPostgresConn::quotedJsonValue( const QVariant &value )
if ( value.type() == QVariant::Bool )
return value.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
const auto j { QgsJsonUtils::jsonFromVariant( value ) };
return QStringLiteral( "'%1'" ).arg( QString::fromStdString( j.dump() ) );
return quotedString( QString::fromStdString( j.dump() ) );
}

PGresult *QgsPostgresConn::PQexec( const QString &query, bool logError, bool retry ) const
Expand Down
3 changes: 2 additions & 1 deletion tests/src/python/test_provider_postgres.py
Expand Up @@ -620,6 +620,7 @@ def testJson(self):
attrs = (
123,
None,
"String l'iteral with \"quotes\" and other funny chars ;#/",
1233.45,
[1, 2, 3.4, None],
[True, False],
Expand All @@ -634,7 +635,7 @@ def testJson(self):
f = QgsFeature(vl2.fields())
f.setAttributes([None, attr, attr])
self.assertTrue(vl2.addFeatures([f]))
self.assertTrue(vl2.commitChanges())
self.assertTrue(vl2.commitChanges(), attr)
# Read back
vl2 = QgsVectorLayer('%s table="qgis_test"."json" sql=' % (self.dbconn), "testjson", "postgres")
fid = [f.id() for f in vl2.getFeatures()][-1]
Expand Down

0 comments on commit 114affc

Please sign in to comment.