Skip to content

Commit d1497bf

Browse files
committedApr 27, 2020
Correctly handle bigint PostgreSQL values
Fixes #36011
1 parent 2454613 commit d1497bf

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed
 

‎src/providers/postgres/qgspostgresfeatureiterator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,11 @@ void QgsPostgresFeatureIterator::getFeatureAttribute( int idx, QgsPostgresResult
857857
}
858858
break;
859859
}
860+
case QVariant::LongLong:
861+
{
862+
v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), QString::number( mConn->getBinaryInt( queryResult, row, col ) ), fld.typeName() );
863+
break;
864+
}
860865
default:
861866
{
862867
v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), queryResult.PQgetvalue( row, col ), fld.typeName() );

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,14 @@ QVariant QgsPostgresProvider::minimumValue( int index ) const
17681768
sql = QStringLiteral( "SELECT %1 FROM (%2) foo" ).arg( connectionRO()->fieldExpression( fld ), sql );
17691769

17701770
QgsPostgresResult rmin( connectionRO()->PQexec( sql ) );
1771-
return convertValue( fld.type(), fld.subType(), rmin.PQgetvalue( 0, 0 ), fld.typeName() );
1771+
if ( fld.type() == QVariant::LongLong )
1772+
{
1773+
return convertValue( fld.type(), fld.subType(), QString::number( connectionRO()->getBinaryInt( rmin, 0, 0 ) ), fld.typeName() );
1774+
}
1775+
else
1776+
{
1777+
return convertValue( fld.type(), fld.subType(), rmin.PQgetvalue( 0, 0 ), fld.typeName() );
1778+
}
17721779
}
17731780
catch ( PGFieldNotFound )
17741781
{
@@ -2033,7 +2040,14 @@ QVariant QgsPostgresProvider::maximumValue( int index ) const
20332040

20342041
QgsPostgresResult rmax( connectionRO()->PQexec( sql ) );
20352042

2036-
return convertValue( fld.type(), fld.subType(), rmax.PQgetvalue( 0, 0 ), fld.typeName() );
2043+
if ( fld.type() == QVariant::LongLong )
2044+
{
2045+
return convertValue( fld.type(), fld.subType(), QString::number( connectionRO()->getBinaryInt( rmax, 0, 0 ) ), fld.typeName() );
2046+
}
2047+
else
2048+
{
2049+
return convertValue( fld.type(), fld.subType(), rmax.PQgetvalue( 0, 0 ), fld.typeName() );
2050+
}
20372051
}
20382052
catch ( PGFieldNotFound )
20392053
{
@@ -2070,7 +2084,16 @@ QVariant QgsPostgresProvider::defaultValue( int fieldId ) const
20702084
QgsPostgresResult res( connectionRO()->PQexec( QStringLiteral( "SELECT %1" ).arg( defVal ) ) );
20712085

20722086
if ( res.result() )
2073-
return convertValue( fld.type(), fld.subType(), res.PQgetvalue( 0, 0 ), fld.typeName() );
2087+
{
2088+
if ( fld.type() == QVariant::LongLong )
2089+
{
2090+
return convertValue( fld.type(), fld.subType(), QString::number( connectionRO()->getBinaryInt( res, 0, 0 ) ), fld.typeName() );
2091+
}
2092+
else
2093+
{
2094+
return convertValue( fld.type(), fld.subType(), res.PQgetvalue( 0, 0 ), fld.typeName() );
2095+
}
2096+
}
20742097
else
20752098
{
20762099
pushError( tr( "Could not execute query" ) );

0 commit comments

Comments
 (0)
Please sign in to comment.