Skip to content
Permalink
Browse files

postgres provider: use min()/max() before casting (followup bf56457; f…

…ixes #12306)

(cherry picked from commit 7ce195ebec7330f101bb6922055a079958bfd58a)
  • Loading branch information
jef-n committed Mar 4, 2015
1 parent 3d6554e commit 377c1dba6222e5a4925f9309c4f1b1c9e70c6f48
@@ -1170,34 +1170,35 @@ qint64 QgsPostgresConn::getBinaryInt( QgsPostgresResult &queryResult, int row, i
return oid;
}

QString QgsPostgresConn::fieldExpression( const QgsField &fld )
QString QgsPostgresConn::fieldExpression( const QgsField &fld, QString expr )
{
const QString &type = fld.typeName();
expr = expr.arg( quotedIdentifier( fld.name() ) );
if ( type == "money" )
{
return QString( "cash_out(%1)" ).arg( quotedIdentifier( fld.name() ) );
return QString( "cash_out(%1)" ).arg( expr );
}
else if ( type.startsWith( "_" ) )
{
return QString( "array_out(%1)" ).arg( quotedIdentifier( fld.name() ) );
return QString( "array_out(%1)" ).arg( expr );
}
else if ( type == "bool" )
{
return QString( "boolout(%1)" ).arg( quotedIdentifier( fld.name() ) );
return QString( "boolout(%1)" ).arg( expr );
}
else if ( type == "geometry" )
{
return QString( "%1(%2)" )
.arg( majorVersion() < 2 ? "asewkt" : "st_asewkt" )
.arg( quotedIdentifier( fld.name() ) );
.arg( expr );
}
else if ( type == "geography" )
{
return QString( "st_astext(%1)" ).arg( quotedIdentifier( fld.name() ) );
return QString( "st_astext(%1)" ).arg( expr );
}
else
{
return quotedIdentifier( fld.name() ) + "::text";
return expr + "::text";
}
}

@@ -285,7 +285,7 @@ class QgsPostgresConn : public QObject

qint64 getBinaryInt( QgsPostgresResult &queryResult, int row, int col );

QString fieldExpression( const QgsField &fld );
QString fieldExpression( const QgsField &fld, QString expr = "%1" );

QString connInfo() const { return mConnInfo; }

@@ -1234,8 +1234,8 @@ QVariant QgsPostgresProvider::minimumValue( int index )
{
// get the field name
const QgsField &fld = field( index );
QString sql = QString( "SELECT min(%1) FROM %2" )
.arg( connectionRO()->fieldExpression( fld ) )
QString sql = QString( "SELECT %1 FROM %2" )
.arg( connectionRO()->fieldExpression( fld, "min(%1)" ) )
.arg( mQuery );

if ( !mSqlWhereClause.isEmpty() )
@@ -1407,8 +1407,8 @@ QVariant QgsPostgresProvider::maximumValue( int index )
{
// get the field name
const QgsField &fld = field( index );
QString sql = QString( "SELECT max(%1) FROM %2" )
.arg( connectionRO()->fieldExpression( fld ) )
QString sql = QString( "SELECT %1 FROM %2" )
.arg( connectionRO()->fieldExpression( fld, "max(%1)" ) )
.arg( mQuery );

if ( !mSqlWhereClause.isEmpty() )

0 comments on commit 377c1db

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