Skip to content

Commit

Permalink
fix #5022
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 18, 2012
1 parent a1ac714 commit 4c0dd44
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
111 changes: 51 additions & 60 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -299,11 +299,11 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
{
int nColumns = 0;
int nGTables = 0;

QgsPostgresResult result;
QgsPostgresLayerProperty layerProperty;

QgsDebugMsg( "Entering." );

mLayersSupported.clear();

for ( int i = 0; i < 2; i++ )
Expand Down Expand Up @@ -349,6 +349,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
if ( result.PQresultStatus() != PGRES_TUPLES_OK )
{
PQexecNR( "COMMIT" );
return false;
}
else
{
Expand Down Expand Up @@ -388,7 +389,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
if ( nColumns == 0 )
{
QgsMessageLog::logMessage( tr( "Database connection was successful, but the accessible tables could not be determined." ), tr( "PostGIS" ) );
nColumns = -1;
}

//search for geometry columns in tables that are not in the geometry_columns metatable
Expand Down Expand Up @@ -427,10 +427,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
sql += " AND (pg_namespace.nspname,pg_class.relname) NOT IN (SELECT f_table_schema,f_table_name FROM geography_columns)";
}
}
else
{
nColumns = 0;
}

sql += " AND pg_class.relkind IN ('v','r')"; // only from views and relations (tables)

Expand All @@ -443,38 +439,36 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
QgsMessageLog::logMessage( tr( "Database connection was successful, but the accessible tables could not be determined. The error message from the database was:\n%1\n" )
.arg( result.PQresultErrorMessage() ),
tr( "PostGIS" ) );
if ( nColumns == 0 )
nColumns = -1;
PQexecNR( "COMMIT" );
return false;
}
else if ( result.PQntuples() > 0 )
{
for ( int i = 0; i < result.PQntuples(); i++ )
{
// Have the column name, schema name and the table name. The concept of a
// catalog doesn't exist in postgresql so we ignore that, but we
// do need to get the geometry type.

// Make the assumption that the geometry type for the first
// row is the same as for all other rows.

QString table = result.PQgetvalue( i, 0 ); // relname
QString schema = result.PQgetvalue( i, 1 ); // nspname
QString column = result.PQgetvalue( i, 2 ); // attname
QString relkind = result.PQgetvalue( i, 3 ); // relation kind

QgsDebugMsg( QString( "%1.%2.%3: %4" ).arg( schema ).arg( table ).arg( column ).arg( relkind ) );

layerProperty.type = QString::null;
layerProperty.schemaName = schema;
layerProperty.tableName = table;
layerProperty.geometryColName = column;
layerProperty.pkCols = relkind == "v" ? pkCandidates( schema, table ) : QStringList();
layerProperty.sql = "";
layerProperty.isGeography = false; // TODO might be geography after all

mLayersSupported << layerProperty;
nColumns++;
}
for ( int i = 0; i < result.PQntuples(); i++ )
{
// Have the column name, schema name and the table name. The concept of a
// catalog doesn't exist in postgresql so we ignore that, but we
// do need to get the geometry type.

// Make the assumption that the geometry type for the first
// row is the same as for all other rows.

QString table = result.PQgetvalue( i, 0 ); // relname
QString schema = result.PQgetvalue( i, 1 ); // nspname
QString column = result.PQgetvalue( i, 2 ); // attname
QString relkind = result.PQgetvalue( i, 3 ); // relation kind

QgsDebugMsg( QString( "%1.%2.%3: %4" ).arg( schema ).arg( table ).arg( column ).arg( relkind ) );

layerProperty.type = QString::null;
layerProperty.schemaName = schema;
layerProperty.tableName = table;
layerProperty.geometryColName = column;
layerProperty.pkCols = relkind == "v" ? pkCandidates( schema, table ) : QStringList();
layerProperty.sql = "";
layerProperty.isGeography = false; // TODO might be geography after all

mLayersSupported << layerProperty;
nColumns++;
}
}

Expand Down Expand Up @@ -506,31 +500,28 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
QgsMessageLog::logMessage( tr( "Database connection was successful, but the accessible tables could not be determined.\nThe error message from the database was:\n%1" )
.arg( result.PQresultErrorMessage() ),
tr( "PostGIS" ) );
if ( nColumns == 0 )
nColumns = -1;
return -1;
}
else if ( result.PQntuples() > 0 )
{
for ( int i = 0; i < result.PQntuples(); i++ )
{
QString table = result.PQgetvalue( i, 0 ); // relname
QString schema = result.PQgetvalue( i, 1 ); // nspname
QString relkind = result.PQgetvalue( i, 2 ); // relation kind

QgsDebugMsg( QString( "%1.%2: %3" ).arg( schema ).arg( table ).arg( relkind ) );

layerProperty.type = QString::null;
layerProperty.schemaName = schema;
layerProperty.tableName = table;
layerProperty.geometryColName = QString::null;
layerProperty.pkCols = relkind == "v" ? pkCandidates( schema, table ) : QStringList();
layerProperty.srid = "";
layerProperty.sql = "";
layerProperty.isGeography = false;

mLayersSupported << layerProperty;
nColumns++;
}
for ( int i = 0; i < result.PQntuples(); i++ )
{
QString table = result.PQgetvalue( i, 0 ); // relname
QString schema = result.PQgetvalue( i, 1 ); // nspname
QString relkind = result.PQgetvalue( i, 2 ); // relation kind

QgsDebugMsg( QString( "%1.%2: %3" ).arg( schema ).arg( table ).arg( relkind ) );

layerProperty.type = QString::null;
layerProperty.schemaName = schema;
layerProperty.tableName = table;
layerProperty.geometryColName = QString::null;
layerProperty.pkCols = relkind == "v" ? pkCandidates( schema, table ) : QStringList();
layerProperty.srid = "";
layerProperty.sql = "";
layerProperty.isGeography = false;

mLayersSupported << layerProperty;
nColumns++;
}
}

Expand All @@ -539,7 +530,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
QgsMessageLog::logMessage( tr( "Database connection was successful, but no accessible tables were found. Please verify that you have SELECT privilege on a table carrying PostGIS geometry." ), tr( "PostGIS" ) );
}

return nColumns > 0;
return true;
}

bool QgsPostgresConn::supportedLayers( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables )
Expand Down
11 changes: 10 additions & 1 deletion src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -28,12 +28,21 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
return children;

QVector<QgsPostgresLayerProperty> layerProperties;
if ( !mConn->supportedLayers( layerProperties, false, true, false ) )
if ( !mConn->supportedLayers( layerProperties,
QgsPostgresConn::geometryColumnsOnly( mName ),
QgsPostgresConn::publicSchemaOnly( mName ),
QgsPostgresConn::allowGeometrylessTables( mName ) ) )
{
children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
return children;
}

if ( layerProperties.isEmpty() )
{
children.append( new QgsErrorItem( this, tr( "No layers found." ), mPath + "/error" ) );
return children;
}

QgsGeomColumnTypeThread *columnTypeThread = 0;

foreach( QgsPostgresLayerProperty layerProperty, layerProperties )
Expand Down

0 comments on commit 4c0dd44

Please sign in to comment.