Skip to content

Commit f20004c

Browse files
authoredJun 17, 2019
Merge pull request #30205 from elpaso/pg-oid-backport
Pg oid backport
2 parents cdaec4a + 2ba1a93 commit f20004c

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed
 

‎src/providers/postgres/qgspostgresconn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ QString QgsPostgresResult::PQfname( int col )
107107
return QString::fromUtf8( ::PQfname( mRes, col ) );
108108
}
109109

110-
int QgsPostgresResult::PQftable( int col )
110+
Oid QgsPostgresResult::PQftable( int col )
111111
{
112112
Q_ASSERT( mRes );
113113
return ::PQftable( mRes, col );
@@ -119,7 +119,7 @@ int QgsPostgresResult::PQftablecol( int col )
119119
return ::PQftablecol( mRes, col );
120120
}
121121

122-
int QgsPostgresResult::PQftype( int col )
122+
Oid QgsPostgresResult::PQftype( int col )
123123
{
124124
Q_ASSERT( mRes );
125125
return ::PQftype( mRes, col );

‎src/providers/postgres/qgspostgresconn.h

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

168168
int PQnfields();
169169
QString PQfname( int col );
170-
int PQftable( int col );
171-
int PQftype( int col );
170+
Oid PQftable( int col );
171+
Oid PQftype( int col );
172172
int PQfmod( int col );
173173
int PQftablecol( int col );
174174
Oid PQoidValue();

‎src/providers/postgres/qgspostgresprovider.cpp

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

755-
QMap<int, PGTypeInfo> typeMap;
755+
QMap<Oid, PGTypeInfo> typeMap;
756756
for ( int i = 0; i < typeResult.PQntuples(); ++i )
757757
{
758758
PGTypeInfo typeInfo =
@@ -762,20 +762,20 @@ bool QgsPostgresProvider::loadFields()
762762
/* typeElem = */ typeResult.PQgetvalue( i, 3 ),
763763
/* typeLen = */ typeResult.PQgetvalue( i, 4 ).toInt()
764764
};
765-
typeMap.insert( typeResult.PQgetvalue( i, 0 ).toInt(), typeInfo );
765+
typeMap.insert( typeResult.PQgetvalue( i, 0 ).toUInt(), typeInfo );
766766
}
767767

768768

769-
QMap<int, QMap<int, QString> > fmtFieldTypeMap, descrMap, defValMap;
770-
QMap<int, QMap<int, int> > attTypeIdMap;
771-
QMap<int, QMap<int, bool> > notNullMap, uniqueMap;
769+
QMap<Oid, QMap<int, QString> > fmtFieldTypeMap, descrMap, defValMap;
770+
QMap<Oid, QMap<int, Oid> > attTypeIdMap;
771+
QMap<Oid, QMap<int, bool> > notNullMap, uniqueMap;
772772
if ( result.PQnfields() > 0 )
773773
{
774774
// Collect table oids
775-
QSet<int> tableoids;
775+
QSet<Oid> tableoids;
776776
for ( int i = 0; i < result.PQnfields(); i++ )
777777
{
778-
int tableoid = result.PQftable( i );
778+
Oid tableoid = result.PQftable( i );
779779
if ( tableoid > 0 )
780780
{
781781
tableoids.insert( tableoid );
@@ -785,7 +785,8 @@ bool QgsPostgresProvider::loadFields()
785785
if ( !tableoids.isEmpty() )
786786
{
787787
QStringList tableoidsList;
788-
Q_FOREACH ( int tableoid, tableoids )
788+
const auto constTableoids = tableoids;
789+
for ( Oid tableoid : constTableoids )
789790
{
790791
tableoidsList.append( QString::number( tableoid ) );
791792
}
@@ -804,12 +805,12 @@ bool QgsPostgresProvider::loadFields()
804805
QgsPostgresResult fmtFieldTypeResult( connectionRO()->PQexec( sql ) );
805806
for ( int i = 0; i < fmtFieldTypeResult.PQntuples(); ++i )
806807
{
807-
int attrelid = fmtFieldTypeResult.PQgetvalue( i, 0 ).toInt();
808-
int attnum = fmtFieldTypeResult.PQgetvalue( i, 1 ).toInt();
808+
Oid attrelid = fmtFieldTypeResult.PQgetvalue( i, 0 ).toUInt();
809+
int attnum = fmtFieldTypeResult.PQgetvalue( i, 1 ).toInt(); // Int2
809810
QString formatType = fmtFieldTypeResult.PQgetvalue( i, 2 );
810811
QString descr = fmtFieldTypeResult.PQgetvalue( i, 3 );
811812
QString defVal = fmtFieldTypeResult.PQgetvalue( i, 4 );
812-
int attType = fmtFieldTypeResult.PQgetvalue( i, 5 ).toInt();
813+
Oid attType = fmtFieldTypeResult.PQgetvalue( i, 5 ).toUInt();
813814
bool attNotNull = fmtFieldTypeResult.PQgetvalue( i, 6 ).toInt();
814815
bool uniqueConstraint = fmtFieldTypeResult.PQgetvalue( i, 7 ).toInt();
815816
fmtFieldTypeMap[attrelid][attnum] = formatType;
@@ -830,12 +831,12 @@ bool QgsPostgresProvider::loadFields()
830831
if ( fieldName == mGeometryColumn )
831832
continue;
832833

833-
int fldtyp = result.PQftype( i );
834+
Oid fldtyp = result.PQftype( i );
834835
int fldMod = result.PQfmod( i );
835836
int fieldPrec = -1;
836-
int tableoid = result.PQftable( i );
837+
Oid tableoid = result.PQftable( i );
837838
int attnum = result.PQftablecol( i );
838-
int atttypid = attTypeIdMap[tableoid][attnum];
839+
Oid atttypid = attTypeIdMap[tableoid][attnum];
839840

840841
const PGTypeInfo &typeInfo = typeMap.value( fldtyp );
841842
QString fieldTypeName = typeInfo.typeName;
@@ -3169,7 +3170,7 @@ bool QgsPostgresProvider::setSubsetString( const QString &theSQL, bool updateFea
31693170
*/
31703171
long QgsPostgresProvider::featureCount() const
31713172
{
3172-
int featuresCounted = mShared->featuresCounted();
3173+
long featuresCounted = mShared->featuresCounted();
31733174
if ( featuresCounted >= 0 )
31743175
return featuresCounted;
31753176

0 commit comments

Comments
 (0)
Please sign in to comment.