Skip to content

Commit

Permalink
postgresql provider: don't require access to geometry_columns
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 5, 2012
1 parent dde9ed7 commit c58debc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 44 deletions.
62 changes: 28 additions & 34 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -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++;
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -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 ) )
Expand All @@ -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" );
}
}
}
Expand Down

0 comments on commit c58debc

Please sign in to comment.