Skip to content

Commit

Permalink
displaystring of every json object
Browse files Browse the repository at this point in the history
Removed unused stuff
  • Loading branch information
signedav authored and nyalldawson committed Sep 14, 2018
1 parent 8d4ffac commit 75b9c66
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 33 deletions.
7 changes: 2 additions & 5 deletions src/core/qgsfield.cpp
Expand Up @@ -257,11 +257,8 @@ QString QgsField::displayString( const QVariant &v ) const
}
else if ( d->typeName.compare( "json" ) == 0 || d->typeName.compare( "jsonb" ) == 0 )
{
//this works only if the json/jsonb field contains a map - this has to be improved.
//toJsonDocument works only if the usertype is QJsonDocument
QJsonValue value = QJsonValue::fromVariant( v );
QJsonDocument doc( value.toObject() );
return QString::fromUtf8( doc.toJson( QJsonDocument::Indented ).data() );
QJsonDocument doc = QJsonDocument::fromVariant( v );
return QString::fromUtf8( doc.toJson().data() );
}
// Fallback if special rules do not apply
return v.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -989,7 +989,7 @@ static QString doubleQuotedMapValue( const QString &v )

static QString quotedMap( const QVariantMap &map )
{
//should it be stored in json/jsonb as well?
//to store properly it should be decided if it's a hstore or a json/jsonb field here...
QString ret;
for ( QVariantMap::const_iterator i = map.constBegin(); i != map.constEnd(); ++i )
{
Expand Down
8 changes: 5 additions & 3 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -2132,9 +2132,10 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags )
.arg( delim,
quotedValue( v.toString() ) );
}
//TODO: convert arrays and hstore to native types and json/jsonb
//TODO: convert arrays and hstore to native types
else
{
//this should be for json/jsonb in future
values += delim + quotedValue( v );
}
}
Expand Down Expand Up @@ -3709,8 +3710,9 @@ bool QgsPostgresProvider::convertField( QgsField &field, const QMap<QString, QVa
break;

case QVariant::Map:
fieldType = QStringLiteral( "hstore" );
//or json/jsonb
fieldType = field.typeName();
if ( fieldType.isEmpty() )
fieldType = QStringLiteral( "hstore" );
fieldPrec = -1;
break;

Expand Down
22 changes: 0 additions & 22 deletions tests/src/providers/testqgspostgresprovider.cpp
Expand Up @@ -124,28 +124,6 @@ class TestQgsPostgresProvider: public QObject
qDebug() << "actual: " << decoded;
QCOMPARE( decoded.toMap(), expected );
}
/*
void decodeJsonInt()
{
const QVariant decoded = QgsPostgresProvider::convertValue( QVariant::Map, QVariant::String, QStringLiteral( "'123'" ), QStringLiteral( "json" ) );
QCOMPARE( decoded.type(), QVariant::Int );
int expected;
expected="'123'";
qDebug() << "actual: " << decoded;
QCOMPARE( decoded., expected );
}
void decodeJsonbInt()
{
const QVariant decoded = QgsPostgresProvider::convertValue( QVariant::Map, QVariant::String, QStringLiteral( "'123'" ), QStringLiteral( "jsonb" ) );
QCOMPARE( decoded.type(), QVariant::Int );
int expected;
expected=123;
qDebug() << "actual: " << decoded;
QCOMPARE( decoded.toInt(), expected );
}
*/
};

QGSTEST_MAIN( TestQgsPostgresProvider )
Expand Down
2 changes: 0 additions & 2 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -650,8 +650,6 @@ def testJson(self):
self.assertEqual(f.attributes()[value_idx], {'c': 4, 'd': 5})
self.assertEqual(f.attributes()[value_idx], {'c': 4.0, 'd': 5.0})

#test int - not yet implemented

def testStringArray(self):
vl = QgsVectorLayer('%s table="qgis_test"."string_array" sql=' % (self.dbconn), "teststringarray", "postgres")
self.assertTrue(vl.isValid())
Expand Down

0 comments on commit 75b9c66

Please sign in to comment.