Skip to content

Commit d844f0f

Browse files
signedavnyalldawson
authored andcommitted
pg version check on json
and comparison with == to make it equal to the other checks and avoid confusions
1 parent 04d770d commit d844f0f

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

src/core/qgsfield.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ QString QgsField::displayString( const QVariant &v ) const
254254
if ( ok )
255255
return QLocale().toString( converted );
256256
}
257-
else if ( d->typeName.compare( "json" ) == 0 || d->typeName.compare( "jsonb" ) == 0 )
257+
else if ( d->typeName == QLatin1String( "json" ) || d->typeName == QLatin1String( "jsonb" ) )
258258
{
259259
QJsonDocument doc = QJsonDocument::fromVariant( v );
260260
return QString::fromUtf8( doc.toJson().data() );

src/gui/editorwidgets/qgslistwidgetfactory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ QgsEditorConfigWidget *QgsListWidgetFactory::configWidget( QgsVectorLayer *vl, i
4444
unsigned int QgsListWidgetFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
4545
{
4646
const QgsField field = vl->fields().field( fieldIdx );
47-
return ( field.type() == QVariant::List || field.type() == QVariant::StringList || field.typeName().compare( QLatin1String( "json" ) ) == 0 || field.typeName().compare( QLatin1String( "jsonb" ) ) == 0 ) && field.subType() != QVariant::Invalid ? 20 : 0;
47+
return ( field.type() == QVariant::List || field.type() == QVariant::StringList || field.typeName() == QLatin1String( "json" ) || field.typeName() == QLatin1String( "jsonb" ) ) && field.subType() != QVariant::Invalid ? 20 : 0;
4848
}

src/providers/postgres/qgspostgresprovider.cpp

+45-35
Original file line numberDiff line numberDiff line change
@@ -207,40 +207,50 @@ QgsPostgresProvider::QgsPostgresProvider( QString const &uri, const ProviderOpti
207207
#endif
208208

209209
//fill type names into sets
210-
setNativeTypes( QList<NativeType>()
211-
// integer types
212-
<< QgsVectorDataProvider::NativeType( tr( "Whole number (smallint - 16bit)" ), QStringLiteral( "int2" ), QVariant::Int, -1, -1, 0, 0 )
213-
<< QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 32bit)" ), QStringLiteral( "int4" ), QVariant::Int, -1, -1, 0, 0 )
214-
<< QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64bit)" ), QStringLiteral( "int8" ), QVariant::LongLong, -1, -1, 0, 0 )
215-
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), QStringLiteral( "numeric" ), QVariant::Double, 1, 20, 0, 20 )
216-
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), QStringLiteral( "decimal" ), QVariant::Double, 1, 20, 0, 20 )
217-
218-
// floating point
219-
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), QStringLiteral( "real" ), QVariant::Double, -1, -1, -1, -1 )
220-
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), QStringLiteral( "double precision" ), QVariant::Double, -1, -1, -1, -1 )
221-
222-
// string types
223-
<< QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), QStringLiteral( "char" ), QVariant::String, 1, 255, -1, -1 )
224-
<< QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar)" ), QStringLiteral( "varchar" ), QVariant::String, 1, 255, -1, -1 )
225-
<< QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), QStringLiteral( "text" ), QVariant::String, -1, -1, -1, -1 )
226-
227-
// date type
228-
<< QgsVectorDataProvider::NativeType( tr( "Date" ), QStringLiteral( "date" ), QVariant::Date, -1, -1, -1, -1 )
229-
<< QgsVectorDataProvider::NativeType( tr( "Time" ), QStringLiteral( "time" ), QVariant::Time, -1, -1, -1, -1 )
230-
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), QStringLiteral( "timestamp without time zone" ), QVariant::DateTime, -1, -1, -1, -1 )
231-
232-
// complex types
233-
<< QgsVectorDataProvider::NativeType( tr( "Map (hstore)" ), QStringLiteral( "hstore" ), QVariant::Map, -1, -1, -1, -1, QVariant::String )
234-
<< QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 32bit)" ), QStringLiteral( "int4[]" ), QVariant::List, -1, -1, -1, -1, QVariant::Int )
235-
<< QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 64bit)" ), QStringLiteral( "int8[]" ), QVariant::List, -1, -1, -1, -1, QVariant::LongLong )
236-
<< QgsVectorDataProvider::NativeType( tr( "Array of number (double)" ), QStringLiteral( "double precision[]" ), QVariant::List, -1, -1, -1, -1, QVariant::Double )
237-
<< QgsVectorDataProvider::NativeType( tr( "Array of text" ), QStringLiteral( "text[]" ), QVariant::StringList, -1, -1, -1, -1, QVariant::String )
238-
<< QgsVectorDataProvider::NativeType( tr( "Map (json)" ), QStringLiteral( "json" ), QVariant::Map, -1, -1, -1, -1, QVariant::String )
239-
<< QgsVectorDataProvider::NativeType( tr( "Map (jsonb)" ), QStringLiteral( "jsonb" ), QVariant::Map, -1, -1, -1, -1, QVariant::String )
240-
241-
// boolean
242-
<< QgsVectorDataProvider::NativeType( tr( "Boolean" ), QStringLiteral( "bool" ), QVariant::Bool, -1, -1, -1, -1 )
243-
);
210+
QList<NativeType> nativeTypes;
211+
212+
nativeTypes // integer types
213+
<< QgsVectorDataProvider::NativeType( tr( "Whole number (smallint - 16bit)" ), QStringLiteral( "int2" ), QVariant::Int, -1, -1, 0, 0 )
214+
<< QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 32bit)" ), QStringLiteral( "int4" ), QVariant::Int, -1, -1, 0, 0 )
215+
<< QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64bit)" ), QStringLiteral( "int8" ), QVariant::LongLong, -1, -1, 0, 0 )
216+
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), QStringLiteral( "numeric" ), QVariant::Double, 1, 20, 0, 20 )
217+
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), QStringLiteral( "decimal" ), QVariant::Double, 1, 20, 0, 20 )
218+
219+
// floating point
220+
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), QStringLiteral( "real" ), QVariant::Double, -1, -1, -1, -1 )
221+
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), QStringLiteral( "double precision" ), QVariant::Double, -1, -1, -1, -1 )
222+
223+
// string types
224+
<< QgsVectorDataProvider::NativeType( tr( "Text, fixed length (char)" ), QStringLiteral( "char" ), QVariant::String, 1, 255, -1, -1 )
225+
<< QgsVectorDataProvider::NativeType( tr( "Text, limited variable length (varchar)" ), QStringLiteral( "varchar" ), QVariant::String, 1, 255, -1, -1 )
226+
<< QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), QStringLiteral( "text" ), QVariant::String, -1, -1, -1, -1 )
227+
228+
// date type
229+
<< QgsVectorDataProvider::NativeType( tr( "Date" ), QStringLiteral( "date" ), QVariant::Date, -1, -1, -1, -1 )
230+
<< QgsVectorDataProvider::NativeType( tr( "Time" ), QStringLiteral( "time" ), QVariant::Time, -1, -1, -1, -1 )
231+
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), QStringLiteral( "timestamp without time zone" ), QVariant::DateTime, -1, -1, -1, -1 )
232+
233+
// complex types
234+
<< QgsVectorDataProvider::NativeType( tr( "Map (hstore)" ), QStringLiteral( "hstore" ), QVariant::Map, -1, -1, -1, -1, QVariant::String )
235+
<< QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 32bit)" ), QStringLiteral( "int4[]" ), QVariant::List, -1, -1, -1, -1, QVariant::Int )
236+
<< QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 64bit)" ), QStringLiteral( "int8[]" ), QVariant::List, -1, -1, -1, -1, QVariant::LongLong )
237+
<< QgsVectorDataProvider::NativeType( tr( "Array of number (double)" ), QStringLiteral( "double precision[]" ), QVariant::List, -1, -1, -1, -1, QVariant::Double )
238+
<< QgsVectorDataProvider::NativeType( tr( "Array of text" ), QStringLiteral( "text[]" ), QVariant::StringList, -1, -1, -1, -1, QVariant::String )
239+
240+
// boolean
241+
<< QgsVectorDataProvider::NativeType( tr( "Boolean" ), QStringLiteral( "bool" ), QVariant::Bool, -1, -1, -1, -1 )
242+
;
243+
244+
if ( connectionRO()->pgVersion() >= 90200 )
245+
{
246+
nativeTypes << QgsVectorDataProvider::NativeType( tr( "Map (json)" ), QStringLiteral( "json" ), QVariant::Map, -1, -1, -1, -1, QVariant::String );
247+
248+
if ( connectionRO()->pgVersion() >= 90400 )
249+
{
250+
nativeTypes << QgsVectorDataProvider::NativeType( tr( "Map (jsonb)" ), QStringLiteral( "jsonb" ), QVariant::Map, -1, -1, -1, -1, QVariant::String );
251+
}
252+
}
253+
setNativeTypes( nativeTypes );
244254

245255
QString key;
246256
switch ( mPrimaryKeyType )
@@ -4281,7 +4291,7 @@ QVariant QgsPostgresProvider::convertValue( QVariant::Type type, QVariant::Type
42814291
switch ( type )
42824292
{
42834293
case QVariant::Map:
4284-
if ( typeName.compare( QLatin1String( "json" ) ) == 0 || typeName.compare( QLatin1String( "jsonb" ) ) == 0 )
4294+
if ( typeName == QLatin1String( "json" ) || typeName == QLatin1String( "jsonb" ) )
42854295
result = parseJson( value );
42864296
else
42874297
result = parseHstore( value );

0 commit comments

Comments
 (0)