Skip to content

Commit 75b9c66

Browse files
signedavnyalldawson
authored andcommitted
displaystring of every json object
Removed unused stuff
1 parent 8d4ffac commit 75b9c66

File tree

5 files changed

+8
-33
lines changed

5 files changed

+8
-33
lines changed

src/core/qgsfield.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,8 @@ QString QgsField::displayString( const QVariant &v ) const
257257
}
258258
else if ( d->typeName.compare( "json" ) == 0 || d->typeName.compare( "jsonb" ) == 0 )
259259
{
260-
//this works only if the json/jsonb field contains a map - this has to be improved.
261-
//toJsonDocument works only if the usertype is QJsonDocument
262-
QJsonValue value = QJsonValue::fromVariant( v );
263-
QJsonDocument doc( value.toObject() );
264-
return QString::fromUtf8( doc.toJson( QJsonDocument::Indented ).data() );
260+
QJsonDocument doc = QJsonDocument::fromVariant( v );
261+
return QString::fromUtf8( doc.toJson().data() );
265262
}
266263
// Fallback if special rules do not apply
267264
return v.toString();

src/providers/postgres/qgspostgresconn.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ static QString doubleQuotedMapValue( const QString &v )
989989

990990
static QString quotedMap( const QVariantMap &map )
991991
{
992-
//should it be stored in json/jsonb as well?
992+
//to store properly it should be decided if it's a hstore or a json/jsonb field here...
993993
QString ret;
994994
for ( QVariantMap::const_iterator i = map.constBegin(); i != map.constEnd(); ++i )
995995
{

src/providers/postgres/qgspostgresprovider.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -2132,9 +2132,10 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags )
21322132
.arg( delim,
21332133
quotedValue( v.toString() ) );
21342134
}
2135-
//TODO: convert arrays and hstore to native types and json/jsonb
2135+
//TODO: convert arrays and hstore to native types
21362136
else
21372137
{
2138+
//this should be for json/jsonb in future
21382139
values += delim + quotedValue( v );
21392140
}
21402141
}
@@ -3709,8 +3710,9 @@ bool QgsPostgresProvider::convertField( QgsField &field, const QMap<QString, QVa
37093710
break;
37103711

37113712
case QVariant::Map:
3712-
fieldType = QStringLiteral( "hstore" );
3713-
//or json/jsonb
3713+
fieldType = field.typeName();
3714+
if ( fieldType.isEmpty() )
3715+
fieldType = QStringLiteral( "hstore" );
37143716
fieldPrec = -1;
37153717
break;
37163718

tests/src/providers/testqgspostgresprovider.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,6 @@ class TestQgsPostgresProvider: public QObject
124124
qDebug() << "actual: " << decoded;
125125
QCOMPARE( decoded.toMap(), expected );
126126
}
127-
/*
128-
void decodeJsonInt()
129-
{
130-
const QVariant decoded = QgsPostgresProvider::convertValue( QVariant::Map, QVariant::String, QStringLiteral( "'123'" ), QStringLiteral( "json" ) );
131-
QCOMPARE( decoded.type(), QVariant::Int );
132-
133-
int expected;
134-
expected="'123'";
135-
qDebug() << "actual: " << decoded;
136-
QCOMPARE( decoded., expected );
137-
}
138-
void decodeJsonbInt()
139-
{
140-
const QVariant decoded = QgsPostgresProvider::convertValue( QVariant::Map, QVariant::String, QStringLiteral( "'123'" ), QStringLiteral( "jsonb" ) );
141-
QCOMPARE( decoded.type(), QVariant::Int );
142-
143-
int expected;
144-
expected=123;
145-
qDebug() << "actual: " << decoded;
146-
QCOMPARE( decoded.toInt(), expected );
147-
}
148-
*/
149127
};
150128

151129
QGSTEST_MAIN( TestQgsPostgresProvider )

tests/src/python/test_provider_postgres.py

-2
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,6 @@ def testJson(self):
650650
self.assertEqual(f.attributes()[value_idx], {'c': 4, 'd': 5})
651651
self.assertEqual(f.attributes()[value_idx], {'c': 4.0, 'd': 5.0})
652652

653-
#test int - not yet implemented
654-
655653
def testStringArray(self):
656654
vl = QgsVectorLayer('%s table="qgis_test"."string_array" sql=' % (self.dbconn), "teststringarray", "postgres")
657655
self.assertTrue(vl.isValid())

0 commit comments

Comments
 (0)