Skip to content

Commit

Permalink
More tests for json values, fix boolean representation
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jun 10, 2019
1 parent 114affc commit 660e451
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -1063,8 +1063,6 @@ QString QgsPostgresConn::quotedJsonValue( const QVariant &value )
{
if ( value.isNull() || !value.isValid() )
return QStringLiteral( "null" );
if ( value.type() == QVariant::Bool )
return value.toBool() ? QStringLiteral( "true" ) : QStringLiteral( "false" );
const auto j { QgsJsonUtils::jsonFromVariant( value ) };
return quotedString( QString::fromStdString( j.dump() ) );
}
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspostgresconn.h
Expand Up @@ -285,6 +285,7 @@ class QgsPostgresConn : public QObject

/**
* Quote a json(b) value for placement in a SQL string.
* \note a null value will be represented as a NULL and not as a json null.
*/
static QString quotedJsonValue( const QVariant &value );

Expand Down
6 changes: 4 additions & 2 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -619,9 +619,11 @@ def testJson(self):

attrs = (
123,
None,
"String l'iteral with \"quotes\" and other funny chars ;#/",
1233.45,
None,
True,
False,
r"String literal with \"quotes\" 'and' other funny chars []{};#/èé*",
[1, 2, 3.4, None],
[True, False],
{'a': 123, 'b': 123.34, 'c': 'a string', 'd': [1, 2, 3], 'e': {'a': 123, 'b': 123.45}}
Expand Down

0 comments on commit 660e451

Please sign in to comment.