Skip to content
Permalink
Browse files
[postgis] Native boolean support
  • Loading branch information
m-kuhn committed Apr 10, 2017
1 parent 5ab8e71 commit cfb8552b14c950ee5dbf6dcb37d83d79c5a6a440
Showing with 34 additions and 8 deletions.
  1. +34 −8 src/providers/postgres/qgspostgresprovider.cpp
@@ -227,6 +227,9 @@ QgsPostgresProvider::QgsPostgresProvider( QString const &uri )
<< QgsVectorDataProvider::NativeType( tr( "Array of number (integer - 64bit)" ), QStringLiteral( "int8[]" ), QVariant::List, -1, -1, -1, -1, QVariant::LongLong )
<< QgsVectorDataProvider::NativeType( tr( "Array of number (double)" ), QStringLiteral( "double precision[]" ), QVariant::List, -1, -1, -1, -1, QVariant::Double )
<< QgsVectorDataProvider::NativeType( tr( "Array of text" ), QStringLiteral( "text[]" ), QVariant::StringList, -1, -1, -1, -1, QVariant::String )

// boolean
<< QgsVectorDataProvider::NativeType( tr( "Boolean" ), QStringLiteral( "bool" ), QVariant::Bool, -1, -1, -1, -1 )
);

QString key;
@@ -898,7 +901,6 @@ bool QgsPostgresProvider::loadFields()
fieldSize = -1;
}
else if ( fieldTypeName == QLatin1String( "text" ) ||
fieldTypeName == QLatin1String( "bool" ) ||
fieldTypeName == QLatin1String( "geometry" ) ||
fieldTypeName == QLatin1String( "inet" ) ||
fieldTypeName == QLatin1String( "money" ) ||
@@ -956,6 +958,12 @@ bool QgsPostgresProvider::loadFields()
fieldSubType = QVariant::String;
fieldSize = -1;
}
else if ( fieldTypeName == QLatin1String( "bool" ) )
{
// enum
fieldType = QVariant::Bool;
fieldSize = -1;
}
else
{
QgsMessageLog::logMessage( tr( "Field %1 ignored, because of unsupported type %2" ).arg( fieldName, fieldTypeName ), tr( "PostGIS" ) );
@@ -3615,6 +3623,12 @@ bool QgsPostgresProvider::convertField( QgsField &field, const QMap<QString, QVa
fieldPrec = -1;
break;

case QVariant::Bool:
fieldType = QStringLiteral( "bool" );
fieldPrec = -1;
fieldSize = -1;
break;

default:
return false;
}
@@ -4106,20 +4120,32 @@ static QVariant parseArray( const QString &txt, QVariant::Type type, QVariant::T

QVariant QgsPostgresProvider::convertValue( QVariant::Type type, QVariant::Type subType, const QString &value )
{
QVariant result;
switch ( type )
{
case QVariant::Map:
return parseHstore( value );
result = parseHstore( value );
break;
case QVariant::StringList:
case QVariant::List:
return parseArray( value, type, subType );
result = parseArray( value, type, subType );
break;
case QVariant::Bool:
if ( value == QChar( 't' ) )
result = true;
else if ( value == QChar( 'f' ) )
result = false;
else
result = QVariant( type );
break;
default:
{
QVariant v( value );
if ( !v.convert( type ) || value.isNull() ) return QVariant( type );
return v;
}
result = value;
if ( !result.convert( type ) || value.isNull() )
result = QVariant( type );
break;
}

return result;
}

QList<QgsVectorLayer *> QgsPostgresProvider::searchLayers( const QList<QgsVectorLayer *> &layers, const QString &connectionInfo, const QString &schema, const QString &tableName )

1 comment on commit cfb8552

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids commented on cfb8552 Sep 4, 2017

@m-kuhn I think this break porting projects having expressions with "my_bool" = 't'. In my project, this breaks layer symbology. Is there any mean to have some project translation for this or is it too tricky?

Please sign in to comment.