Skip to content
Permalink
Browse files

displaystring of every json object

Removed unused stuff
  • Loading branch information
signedav authored and nyalldawson committed Sep 14, 2018
1 parent 8d4ffac commit 75b9c66c990c340e19d9a72dd993772518f9b790
@@ -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();
@@ -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 )
{
@@ -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 );
}
}
@@ -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;

@@ -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 )
@@ -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())

0 comments on commit 75b9c66

Please sign in to comment.
You can’t perform that action at this time.