Skip to content

Commit

Permalink
fix #5883
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 4, 2012
1 parent b121a2f commit 6aa7524
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
29 changes: 15 additions & 14 deletions src/providers/postgres/qgspostgresconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,28 +1021,29 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
{
QString table;

if ( !layerProperty.schemaName.isEmpty() )
{
table = QString("%1.%2").arg( quotedIdentifier( layerProperty.schemaName ) ).arg( layerProperty.tableName );
}
else
{
// Query
table = layerProperty.tableName;
}


// it is possible that the where clause restricts the feature type or srid
if ( useEstimatedMetadata )
{
table = QString( "(SELECT %1 FROM %2.%3 WHERE %1 IS NOT NULL%4 LIMIT %5) AS t" )
table = QString( "(SELECT %1 FROM %2 WHERE %1 IS NOT NULL%3 LIMIT %4) AS t" )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( quotedIdentifier( layerProperty.schemaName ) )
.arg( quotedIdentifier( layerProperty.tableName ) )
.arg( table )
.arg( layerProperty.sql.isEmpty() ? "" : QString( " AND (%1)" ).arg( layerProperty.sql ) )
.arg( sGeomTypeSelectLimit );
}
else if ( !layerProperty.schemaName.isEmpty() )
{
table = QString( "%1.%2%3" )
.arg( quotedIdentifier( layerProperty.schemaName ) )
.arg( quotedIdentifier( layerProperty.tableName ) )
.arg( layerProperty.sql.isEmpty() ? "" : QString( " WHERE %1" ).arg( layerProperty.sql ) );
}
else
else if( !layerProperty.sql.isEmpty() )
{
table = QString( "%1%2" )
.arg( layerProperty.tableName )
.arg( layerProperty.sql.isEmpty() ? "" : QString( " WHERE %1" ).arg( layerProperty.sql ) );
table += QString( " WHERE %1" ).arg( layerProperty.sql );
}

QString query = QString( "SELECT DISTINCT"
Expand Down
12 changes: 10 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2778,8 +2778,16 @@ bool QgsPostgresProvider::getGeometryDetails()
if ( QgsPostgresConn::wkbTypeFromPostgis( detectedType ) == QGis::WKBUnknown )
{
QgsPostgresLayerProperty layerProperty;
layerProperty.schemaName = schemaName;
layerProperty.tableName = tableName;
if( !mIsQuery )
{
layerProperty.schemaName = schemaName;
layerProperty.tableName = tableName;
}
else
{
layerProperty.schemaName = "";
layerProperty.tableName = mQuery;
}
layerProperty.geometryColName = mGeometryColumn;
layerProperty.isGeography = mIsGeography;

Expand Down

0 comments on commit 6aa7524

Please sign in to comment.