Skip to content

Commit

Permalink
Some more Oid type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jun 12, 2019
1 parent ad8c5a6 commit c90583c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -122,7 +122,7 @@ int QgsPostgresResult::PQftablecol( int col )
return ::PQftablecol( mRes, col );
}

int QgsPostgresResult::PQftype( int col )
Oid QgsPostgresResult::PQftype( int col )
{
Q_ASSERT( mRes );
return ::PQftype( mRes, col );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresconn.h
Expand Up @@ -170,7 +170,7 @@ class QgsPostgresResult
int PQnfields();
QString PQfname( int col );
unsigned int PQftable( int col );
int PQftype( int col );
Oid PQftype( int col );
int PQfmod( int col );
int PQftablecol( int col );
Oid PQoidValue();
Expand Down
24 changes: 12 additions & 12 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -749,7 +749,7 @@ bool QgsPostgresProvider::loadFields()
sql = QStringLiteral( "SELECT oid,typname,typtype,typelem,typlen FROM pg_type" );
QgsPostgresResult typeResult( connectionRO()->PQexec( sql ) );

QMap<unsigned int, PGTypeInfo> typeMap;
QMap<Oid, PGTypeInfo> typeMap;
for ( int i = 0; i < typeResult.PQntuples(); ++i )
{
PGTypeInfo typeInfo =
Expand All @@ -763,16 +763,16 @@ bool QgsPostgresProvider::loadFields()
}


QMap<int, QMap<int, QString> > fmtFieldTypeMap, descrMap, defValMap, identityMap;
QMap<int, QMap<int, int> > attTypeIdMap;
QMap<int, QMap<int, bool> > notNullMap, uniqueMap;
QMap<Oid, QMap<int, QString> > fmtFieldTypeMap, descrMap, defValMap, identityMap;
QMap<Oid, QMap<int, Oid> > attTypeIdMap;
QMap<Oid, QMap<int, bool> > notNullMap, uniqueMap;
if ( result.PQnfields() > 0 )
{
// Collect table oids
QSet<unsigned int> tableoids;
for ( int i = 0; i < result.PQnfields(); i++ )
{
unsigned int tableoid = result.PQftable( i );
Oid tableoid = result.PQftable( i );
if ( tableoid > 0 )
{
tableoids.insert( tableoid );
Expand All @@ -783,7 +783,7 @@ bool QgsPostgresProvider::loadFields()
{
QStringList tableoidsList;
const auto constTableoids = tableoids;
for ( int tableoid : constTableoids )
for ( Oid tableoid : constTableoids )
{
tableoidsList.append( QString::number( tableoid ) );
}
Expand All @@ -805,12 +805,12 @@ bool QgsPostgresProvider::loadFields()
QgsPostgresResult fmtFieldTypeResult( connectionRO()->PQexec( sql ) );
for ( int i = 0; i < fmtFieldTypeResult.PQntuples(); ++i )
{
int attrelid = fmtFieldTypeResult.PQgetvalue( i, 0 ).toInt();
int attnum = fmtFieldTypeResult.PQgetvalue( i, 1 ).toInt();
Oid attrelid = fmtFieldTypeResult.PQgetvalue( i, 0 ).toUInt();
int attnum = fmtFieldTypeResult.PQgetvalue( i, 1 ).toInt(); // Int2
QString formatType = fmtFieldTypeResult.PQgetvalue( i, 2 );
QString descr = fmtFieldTypeResult.PQgetvalue( i, 3 );
QString defVal = fmtFieldTypeResult.PQgetvalue( i, 4 );
int attType = fmtFieldTypeResult.PQgetvalue( i, 5 ).toInt();
Oid attType = fmtFieldTypeResult.PQgetvalue( i, 5 ).toUInt();
bool attNotNull = fmtFieldTypeResult.PQgetvalue( i, 6 ).toInt();
bool uniqueConstraint = fmtFieldTypeResult.PQgetvalue( i, 7 ).toInt();
QString attIdentity = connectionRO()->pgVersion() >= 100000 ? fmtFieldTypeResult.PQgetvalue( i, 8 ) : " ";
Expand All @@ -834,12 +834,12 @@ bool QgsPostgresProvider::loadFields()
if ( fieldName == mGeometryColumn )
continue;

int fldtyp = result.PQftype( i );
Oid fldtyp = result.PQftype( i );
int fldMod = result.PQfmod( i );
int fieldPrec = -1;
int tableoid = result.PQftable( i );
unsigned int tableoid = result.PQftable( i );
int attnum = result.PQftablecol( i );
int atttypid = attTypeIdMap[tableoid][attnum];
Oid atttypid = attTypeIdMap[tableoid][attnum];

const PGTypeInfo &typeInfo = typeMap.value( fldtyp );
QString fieldTypeName = typeInfo.typeName;
Expand Down

0 comments on commit c90583c

Please sign in to comment.