Skip to content

Commit

Permalink
Correctly handle bigint PostgreSQL values
Browse files Browse the repository at this point in the history
Fixes #36011
  • Loading branch information
espinafre committed Apr 27, 2020
1 parent 2454613 commit d1497bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -857,6 +857,11 @@ void QgsPostgresFeatureIterator::getFeatureAttribute( int idx, QgsPostgresResult
}
break;
}
case QVariant::LongLong:
{
v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), QString::number( mConn->getBinaryInt( queryResult, row, col ) ), fld.typeName() );
break;
}
default:
{
v = QgsPostgresProvider::convertValue( fld.type(), fld.subType(), queryResult.PQgetvalue( row, col ), fld.typeName() );
Expand Down
29 changes: 26 additions & 3 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -1768,7 +1768,14 @@ QVariant QgsPostgresProvider::minimumValue( int index ) const
sql = QStringLiteral( "SELECT %1 FROM (%2) foo" ).arg( connectionRO()->fieldExpression( fld ), sql );

QgsPostgresResult rmin( connectionRO()->PQexec( sql ) );
return convertValue( fld.type(), fld.subType(), rmin.PQgetvalue( 0, 0 ), fld.typeName() );
if ( fld.type() == QVariant::LongLong )
{
return convertValue( fld.type(), fld.subType(), QString::number( connectionRO()->getBinaryInt( rmin, 0, 0 ) ), fld.typeName() );
}
else
{
return convertValue( fld.type(), fld.subType(), rmin.PQgetvalue( 0, 0 ), fld.typeName() );
}
}
catch ( PGFieldNotFound )
{
Expand Down Expand Up @@ -2033,7 +2040,14 @@ QVariant QgsPostgresProvider::maximumValue( int index ) const

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

return convertValue( fld.type(), fld.subType(), rmax.PQgetvalue( 0, 0 ), fld.typeName() );
if ( fld.type() == QVariant::LongLong )
{
return convertValue( fld.type(), fld.subType(), QString::number( connectionRO()->getBinaryInt( rmax, 0, 0 ) ), fld.typeName() );
}
else
{
return convertValue( fld.type(), fld.subType(), rmax.PQgetvalue( 0, 0 ), fld.typeName() );
}
}
catch ( PGFieldNotFound )
{
Expand Down Expand Up @@ -2070,7 +2084,16 @@ QVariant QgsPostgresProvider::defaultValue( int fieldId ) const
QgsPostgresResult res( connectionRO()->PQexec( QStringLiteral( "SELECT %1" ).arg( defVal ) ) );

if ( res.result() )
return convertValue( fld.type(), fld.subType(), res.PQgetvalue( 0, 0 ), fld.typeName() );
{
if ( fld.type() == QVariant::LongLong )
{
return convertValue( fld.type(), fld.subType(), QString::number( connectionRO()->getBinaryInt( res, 0, 0 ) ), fld.typeName() );
}
else
{
return convertValue( fld.type(), fld.subType(), res.PQgetvalue( 0, 0 ), fld.typeName() );
}
}
else
{
pushError( tr( "Could not execute query" ) );
Expand Down

0 comments on commit d1497bf

Please sign in to comment.