Skip to content

Commit 377c1db

Browse files
committedMar 4, 2015
postgres provider: use min()/max() before casting (followup bf56457; fixes #12306)
(cherry picked from commit 7ce195ebec7330f101bb6922055a079958bfd58a)
1 parent 3d6554e commit 377c1db

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed
 

‎src/providers/postgres/qgspostgresconn.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,34 +1170,35 @@ qint64 QgsPostgresConn::getBinaryInt( QgsPostgresResult &queryResult, int row, i
11701170
return oid;
11711171
}
11721172

1173-
QString QgsPostgresConn::fieldExpression( const QgsField &fld )
1173+
QString QgsPostgresConn::fieldExpression( const QgsField &fld, QString expr )
11741174
{
11751175
const QString &type = fld.typeName();
1176+
expr = expr.arg( quotedIdentifier( fld.name() ) );
11761177
if ( type == "money" )
11771178
{
1178-
return QString( "cash_out(%1)" ).arg( quotedIdentifier( fld.name() ) );
1179+
return QString( "cash_out(%1)" ).arg( expr );
11791180
}
11801181
else if ( type.startsWith( "_" ) )
11811182
{
1182-
return QString( "array_out(%1)" ).arg( quotedIdentifier( fld.name() ) );
1183+
return QString( "array_out(%1)" ).arg( expr );
11831184
}
11841185
else if ( type == "bool" )
11851186
{
1186-
return QString( "boolout(%1)" ).arg( quotedIdentifier( fld.name() ) );
1187+
return QString( "boolout(%1)" ).arg( expr );
11871188
}
11881189
else if ( type == "geometry" )
11891190
{
11901191
return QString( "%1(%2)" )
11911192
.arg( majorVersion() < 2 ? "asewkt" : "st_asewkt" )
1192-
.arg( quotedIdentifier( fld.name() ) );
1193+
.arg( expr );
11931194
}
11941195
else if ( type == "geography" )
11951196
{
1196-
return QString( "st_astext(%1)" ).arg( quotedIdentifier( fld.name() ) );
1197+
return QString( "st_astext(%1)" ).arg( expr );
11971198
}
11981199
else
11991200
{
1200-
return quotedIdentifier( fld.name() ) + "::text";
1201+
return expr + "::text";
12011202
}
12021203
}
12031204

‎src/providers/postgres/qgspostgresconn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class QgsPostgresConn : public QObject
285285

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

288-
QString fieldExpression( const QgsField &fld );
288+
QString fieldExpression( const QgsField &fld, QString expr = "%1" );
289289

290290
QString connInfo() const { return mConnInfo; }
291291

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,8 +1234,8 @@ QVariant QgsPostgresProvider::minimumValue( int index )
12341234
{
12351235
// get the field name
12361236
const QgsField &fld = field( index );
1237-
QString sql = QString( "SELECT min(%1) FROM %2" )
1238-
.arg( connectionRO()->fieldExpression( fld ) )
1237+
QString sql = QString( "SELECT %1 FROM %2" )
1238+
.arg( connectionRO()->fieldExpression( fld, "min(%1)" ) )
12391239
.arg( mQuery );
12401240

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

14141414
if ( !mSqlWhereClause.isEmpty() )

0 commit comments

Comments
 (0)
Please sign in to comment.