Skip to content
Permalink
Browse files

Correctly handle bigint PostgreSQL values

Fixes #36011
  • Loading branch information
espinafre committed Apr 27, 2020
1 parent 2454613 commit d1497bfb8b2152b46c9cab2c53ac7b6975a7060e
@@ -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() );
@@ -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 )
{
@@ -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 )
{
@@ -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" ) );

0 comments on commit d1497bf

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