Skip to content
Permalink
Browse files
postgresql provider: don't require access to geometry_columns
  • Loading branch information
jef-n committed Mar 5, 2012
1 parent dde9ed7 commit c58debc638f2c87933dd371710bd107d3c7a5092
Showing with 39 additions and 44 deletions.
  1. +28 −34 src/providers/postgres/qgspostgresconn.cpp
  2. +11 −10 src/providers/postgres/qgspostgresprovider.cpp
@@ -349,44 +349,38 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
if ( result.PQresultStatus() != PGRES_TUPLES_OK )
{
PQexecNR( "COMMIT" );

if ( i == 0 )
return false;

continue;
}
else

nGTables++;

for ( int idx = 0; idx < result.PQntuples(); idx++ )
{
nGTables++;
QString tableName = result.PQgetvalue( idx, 0 );
QString schemaName = result.PQgetvalue( idx, 1 );
QString column = result.PQgetvalue( idx, 2 );
QString type = result.PQgetvalue( idx, 3 );
QString srid = result.PQgetvalue( idx, 4 );
QString relkind = result.PQgetvalue( idx, 5 );

QgsDebugMsg( QString( "%1 : %2.%3.%4: %5 %6 %7" )
.arg( gtableName )
.arg( schemaName ).arg( tableName ).arg( column )
.arg( type )
.arg( srid )
.arg( relkind ) );

layerProperty.type = type;
layerProperty.schemaName = schemaName;
layerProperty.tableName = tableName;
layerProperty.geometryColName = column;
layerProperty.pkCols = relkind == "v" ? pkCandidates( schemaName, tableName ) : QStringList();
layerProperty.srid = srid;
layerProperty.sql = "";
layerProperty.isGeography = i == 1;

for ( int idx = 0; idx < result.PQntuples(); idx++ )
{
QString tableName = result.PQgetvalue( idx, 0 );
QString schemaName = result.PQgetvalue( idx, 1 );
QString column = result.PQgetvalue( idx, 2 );
QString type = result.PQgetvalue( idx, 3 );
QString srid = result.PQgetvalue( idx, 4 );
QString relkind = result.PQgetvalue( idx, 5 );

QgsDebugMsg( QString( "%1 : %2.%3.%4: %5 %6 %7" )
.arg( gtableName )
.arg( schemaName ).arg( tableName ).arg( column )
.arg( type )
.arg( srid )
.arg( relkind ) );

layerProperty.type = type;
layerProperty.schemaName = schemaName;
layerProperty.tableName = tableName;
layerProperty.geometryColName = column;
layerProperty.pkCols = relkind == "v" ? pkCandidates( schemaName, tableName ) : QStringList();
layerProperty.srid = srid;
layerProperty.sql = "";
layerProperty.isGeography = i == 1;

mLayersSupported << layerProperty;
nColumns++;
}
mLayersSupported << layerProperty;
nColumns++;
}
}

@@ -2682,10 +2682,14 @@ bool QgsPostgresProvider::getGeometryDetails()
detectedType = result.PQgetvalue( 0, 0 );
detectedSrid = result.PQgetvalue( 0, 1 );
}
else
{
mConnectionRO->PQexecNR( "COMMIT" );
}

if ( !detectedType.isEmpty() )
if ( detectedType.isEmpty() )
{
// check geometry columns
// check geography columns
sql = QString( "SELECT upper(type),srid FROM geography_columns WHERE f_table_name=%1 AND f_geography_column=%2 AND f_table_schema=%3" )
.arg( quotedValue( tableName ) )
.arg( quotedValue( geomCol ) )
@@ -2695,18 +2699,15 @@ bool QgsPostgresProvider::getGeometryDetails()
result = mConnectionRO->PQexec( sql, false );
QgsDebugMsg( QString( "Geography column query returned %1" ).arg( result.PQntuples() ) );

if ( result.PQresultStatus() == PGRES_TUPLES_OK )
if ( result.PQntuples() == 1 )
{
if ( result.PQntuples() == 1 )
{
detectedType = result.PQgetvalue( 0, 0 );
detectedSrid = result.PQgetvalue( 0, 1 );
mIsGeography = true;
}
detectedType = result.PQgetvalue( 0, 0 );
detectedSrid = result.PQgetvalue( 0, 1 );
mIsGeography = true;
}
else
{
mConnectionRO->PQexecNR( "ROLLBACK" );
mConnectionRO->PQexecNR( "COMMIT" );
}
}
}

0 comments on commit c58debc

Please sign in to comment.