Skip to content
Permalink
Browse files

Fix PG views PK

Fixes #34167
  • Loading branch information
elpaso committed Jan 31, 2020
1 parent 430d8c2 commit b7bdb9a7bfae575017df0cfcc71edb18dbe8fc04
Showing with 92 additions and 90 deletions.
  1. +1 −1 src/providers/postgres/qgspgtablemodel.cpp
  2. +91 −89 src/providers/postgres/qgspostgresconn.cpp
@@ -45,7 +45,7 @@ QgsPgTableModel::QgsPgTableModel()

void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProperty )
{
QgsDebugMsg( layerProperty.toString() );
QgsDebugMsgLevel( layerProperty.toString(), 3 );

// is there already a root item with the given scheme Name?
QStandardItem *schemaItem = nullptr;
@@ -553,7 +553,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
// The following query returns only tables that exist and the user has SELECT privilege on.
// Can't use regclass here because table must exist, else error occurs.
sql = QString( "SELECT %1,%2,%3,%4,%5,%6,c.relkind,obj_description(c.oid),"
"array_agg(a.attname), "
"array_agg(a.attname ORDER BY a.attnum), "
"count(CASE WHEN t.typname IN (%9) THEN 1 ELSE NULL END) "
", %8 "
" FROM %7 l,pg_class c,pg_namespace n,pg_attribute a,pg_type t"
@@ -824,7 +824,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
",pg_namespace.nspname"
",pg_class.relkind"
",obj_description(pg_class.oid)"
",array_agg(a.attname)"
",array_agg(a.attname ORDER BY a.attnum)"
" FROM "
" pg_class"
",pg_namespace"
@@ -1758,7 +1758,7 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l

}

QgsDebugMsg( "Layer types,srids and dims query: " + query );
QgsDebugMsgLevel( "Layer types,srids and dims query: " + query, 3 );

QgsPostgresResult res( PQexec( query ) );
if ( res.PQresultStatus() != PGRES_TUPLES_OK )
@@ -1773,31 +1773,33 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
auto srids_and_types = QgsPostgresStringUtils::parseArray( res.PQgetvalue( i, 1 ) );
QgsPostgresLayerProperty &layerProperty = *layerProperties[idx];

QgsDebugMsg( QStringLiteral(
"Layer %1.%2.%3 has %4 srid/type combinations"
)
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( srids_and_types.length() )
);
QgsDebugMsgLevel( QStringLiteral(
"Layer %1.%2.%3 has %4 srid/type combinations"
)
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( srids_and_types.length() )
, 3
);

/* Gather found types */
QList< std::pair<QgsWkbTypes::Type, int> > foundCombinations;
for ( const auto &sridAndTypeVariant : srids_and_types )
{
QString sridAndTypeString = sridAndTypeVariant.toString();

QgsDebugMsg( QStringLiteral(
"Analyzing layer's %1.%2.%3 sridAndType %4"
" against %6 found combinations"
)
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( sridAndTypeString )
.arg( foundCombinations.length() )
);
QgsDebugMsgLevel( QStringLiteral(
"Analyzing layer's %1.%2.%3 sridAndType %4"
" against %6 found combinations"
)
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( sridAndTypeString )
.arg( foundCombinations.length() )
, 3
);

if ( sridAndTypeString == "NULL" ) continue;

@@ -1831,84 +1833,84 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l

if ( multiCurveType == knownMultiCurveType )
{
QgsDebugMsg( QStringLiteral(
"Upgrading type[%1] of layer %2.%3.%4 "
"to multiCurved type %5" )
.arg( j )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( multiCurveType )
);
QgsDebugMsgLevel( QStringLiteral(
"Upgrading type[%1] of layer %2.%3.%4 "
"to multiCurved type %5" )
.arg( j )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( multiCurveType ), 3
);
foundCombinations[j].first = multiCurveType;
break;
}
else if ( multiType == knownMultiType )
{
QgsDebugMsg( QStringLiteral(
"Upgrading type[%1] of layer %2.%3.%4 "
"to multi type %5" )
.arg( j )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( multiType )
);
QgsDebugMsgLevel( QStringLiteral(
"Upgrading type[%1] of layer %2.%3.%4 "
"to multi type %5" )
.arg( j )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( multiType ), 3
);
foundCombinations[j].first = multiType;
break;
}
else if ( curveType == knownCurveType )
{
QgsDebugMsg( QStringLiteral(
"Upgrading type[%1] of layer %2.%3.%4 "
"to curved type %5" )
.arg( j )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( multiType )
);
QgsDebugMsgLevel( QStringLiteral(
"Upgrading type[%1] of layer %2.%3.%4 "
"to curved type %5" )
.arg( j )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( multiType ), 3
);
foundCombinations[j].first = curveType;
break;
}
}

if ( j < foundCombinations.length() )
{
QgsDebugMsg( QStringLiteral(
"Pre-existing compatible combination %1/%2 "
"found for layer %3.%4.%5 "
)
.arg( j ) .arg( foundCombinations.length() )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
);
QgsDebugMsgLevel( QStringLiteral(
"Pre-existing compatible combination %1/%2 "
"found for layer %3.%4.%5 "
)
.arg( j ) .arg( foundCombinations.length() )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName ), 3
);
continue; // already found
}

QgsDebugMsg( QStringLiteral(
"Setting typeSridCombination[%1] of layer %2.%3.%4 "
"to srid %5 and type %6" )
.arg( j )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( srid )
.arg( type )
);
QgsDebugMsgLevel( QStringLiteral(
"Setting typeSridCombination[%1] of layer %2.%3.%4 "
"to srid %5 and type %6" )
.arg( j )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( srid )
.arg( type ), 3
);

foundCombinations << std::make_pair( type, srid );
}

QgsDebugMsg( QStringLiteral(
"Completed scan of %1 srid/type combinations "
"for layer of layer %2.%3.%4 " )
.arg( srids_and_types.length() )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
);
QgsDebugMsgLevel( QStringLiteral(
"Completed scan of %1 srid/type combinations "
"for layer of layer %2.%3.%4 " )
.arg( srids_and_types.length() )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName ), 2
);

/* Rewrite srids and types to match found combinations
* of srids and types */
@@ -1919,20 +1921,20 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
layerProperty.types << comb.first;
layerProperty.srids << comb.second;
}
QgsDebugMsg( QStringLiteral(
"Final layer %1.%2.%3 types: %4" )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( layerProperty.types.length() )
);
QgsDebugMsg( QStringLiteral(
"Final layer %1.%2.%3 srids: %4" )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( layerProperty.srids.length() )
);
QgsDebugMsgLevel( QStringLiteral(
"Final layer %1.%2.%3 types: %4" )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( layerProperty.types.length() ), 2
);
QgsDebugMsgLevel( QStringLiteral(
"Final layer %1.%2.%3 srids: %4" )
.arg( layerProperty.schemaName,
layerProperty.tableName,
layerProperty.geometryColName )
.arg( layerProperty.srids.length() ), 2
);
}
}

0 comments on commit b7bdb9a

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