Skip to content

Commit ffe3c31

Browse files
authoredJun 13, 2019
Merge pull request #30184 from elpaso/bugfix-gh30041-pg-oid-overflow
An attempt to fix oid overflow in regclass
2 parents 586d216 + c94310d commit ffe3c31

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed
 

‎src/providers/postgres/qgspostgresconn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ QString QgsPostgresResult::PQfname( int col )
110110
return QString::fromUtf8( ::PQfname( mRes, col ) );
111111
}
112112

113-
int QgsPostgresResult::PQftable( int col )
113+
unsigned int QgsPostgresResult::PQftable( int col )
114114
{
115115
Q_ASSERT( mRes );
116116
return ::PQftable( mRes, col );
@@ -122,7 +122,7 @@ int QgsPostgresResult::PQftablecol( int col )
122122
return ::PQftablecol( mRes, col );
123123
}
124124

125-
int QgsPostgresResult::PQftype( int col )
125+
Oid QgsPostgresResult::PQftype( int col )
126126
{
127127
Q_ASSERT( mRes );
128128
return ::PQftype( mRes, col );

‎src/providers/postgres/qgspostgresconn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ class QgsPostgresResult
169169

170170
int PQnfields();
171171
QString PQfname( int col );
172-
int PQftable( int col );
173-
int PQftype( int col );
172+
unsigned int PQftable( int col );
173+
Oid PQftype( int col );
174174
int PQfmod( int col );
175175
int PQftablecol( int col );
176176
Oid PQoidValue();

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ bool QgsPostgresProvider::loadFields()
749749
sql = QStringLiteral( "SELECT oid,typname,typtype,typelem,typlen FROM pg_type" );
750750
QgsPostgresResult typeResult( connectionRO()->PQexec( sql ) );
751751

752-
QMap<int, PGTypeInfo> typeMap;
752+
QMap<Oid, PGTypeInfo> typeMap;
753753
for ( int i = 0; i < typeResult.PQntuples(); ++i )
754754
{
755755
PGTypeInfo typeInfo =
@@ -759,20 +759,20 @@ bool QgsPostgresProvider::loadFields()
759759
/* typeElem = */ typeResult.PQgetvalue( i, 3 ),
760760
/* typeLen = */ typeResult.PQgetvalue( i, 4 ).toInt()
761761
};
762-
typeMap.insert( typeResult.PQgetvalue( i, 0 ).toInt(), typeInfo );
762+
typeMap.insert( typeResult.PQgetvalue( i, 0 ).toUInt(), typeInfo );
763763
}
764764

765765

766-
QMap<int, QMap<int, QString> > fmtFieldTypeMap, descrMap, defValMap, identityMap;
767-
QMap<int, QMap<int, int> > attTypeIdMap;
768-
QMap<int, QMap<int, bool> > notNullMap, uniqueMap;
766+
QMap<Oid, QMap<int, QString> > fmtFieldTypeMap, descrMap, defValMap, identityMap;
767+
QMap<Oid, QMap<int, Oid> > attTypeIdMap;
768+
QMap<Oid, QMap<int, bool> > notNullMap, uniqueMap;
769769
if ( result.PQnfields() > 0 )
770770
{
771771
// Collect table oids
772-
QSet<int> tableoids;
772+
QSet<unsigned int> tableoids;
773773
for ( int i = 0; i < result.PQnfields(); i++ )
774774
{
775-
int tableoid = result.PQftable( i );
775+
Oid tableoid = result.PQftable( i );
776776
if ( tableoid > 0 )
777777
{
778778
tableoids.insert( tableoid );
@@ -783,7 +783,7 @@ bool QgsPostgresProvider::loadFields()
783783
{
784784
QStringList tableoidsList;
785785
const auto constTableoids = tableoids;
786-
for ( int tableoid : constTableoids )
786+
for ( Oid tableoid : constTableoids )
787787
{
788788
tableoidsList.append( QString::number( tableoid ) );
789789
}
@@ -805,12 +805,12 @@ bool QgsPostgresProvider::loadFields()
805805
QgsPostgresResult fmtFieldTypeResult( connectionRO()->PQexec( sql ) );
806806
for ( int i = 0; i < fmtFieldTypeResult.PQntuples(); ++i )
807807
{
808-
int attrelid = fmtFieldTypeResult.PQgetvalue( i, 0 ).toInt();
809-
int attnum = fmtFieldTypeResult.PQgetvalue( i, 1 ).toInt();
808+
Oid attrelid = fmtFieldTypeResult.PQgetvalue( i, 0 ).toUInt();
809+
int attnum = fmtFieldTypeResult.PQgetvalue( i, 1 ).toInt(); // Int2
810810
QString formatType = fmtFieldTypeResult.PQgetvalue( i, 2 );
811811
QString descr = fmtFieldTypeResult.PQgetvalue( i, 3 );
812812
QString defVal = fmtFieldTypeResult.PQgetvalue( i, 4 );
813-
int attType = fmtFieldTypeResult.PQgetvalue( i, 5 ).toInt();
813+
Oid attType = fmtFieldTypeResult.PQgetvalue( i, 5 ).toUInt();
814814
bool attNotNull = fmtFieldTypeResult.PQgetvalue( i, 6 ).toInt();
815815
bool uniqueConstraint = fmtFieldTypeResult.PQgetvalue( i, 7 ).toInt();
816816
QString attIdentity = connectionRO()->pgVersion() >= 100000 ? fmtFieldTypeResult.PQgetvalue( i, 8 ) : " ";
@@ -834,12 +834,12 @@ bool QgsPostgresProvider::loadFields()
834834
if ( fieldName == mGeometryColumn )
835835
continue;
836836

837-
int fldtyp = result.PQftype( i );
837+
Oid fldtyp = result.PQftype( i );
838838
int fldMod = result.PQfmod( i );
839839
int fieldPrec = -1;
840-
int tableoid = result.PQftable( i );
840+
unsigned int tableoid = result.PQftable( i );
841841
int attnum = result.PQftablecol( i );
842-
int atttypid = attTypeIdMap[tableoid][attnum];
842+
Oid atttypid = attTypeIdMap[tableoid][attnum];
843843

844844
const PGTypeInfo &typeInfo = typeMap.value( fldtyp );
845845
QString fieldTypeName = typeInfo.typeName;
@@ -3232,7 +3232,7 @@ bool QgsPostgresProvider::setSubsetString( const QString &theSQL, bool updateFea
32323232
*/
32333233
long QgsPostgresProvider::featureCount() const
32343234
{
3235-
int featuresCounted = mShared->featuresCounted();
3235+
long featuresCounted = mShared->featuresCounted();
32363236
if ( featuresCounted >= 0 )
32373237
return featuresCounted;
32383238

0 commit comments

Comments
 (0)
Please sign in to comment.