Skip to content

Commit c58debc

Browse files
committed
postgresql provider: don't require access to geometry_columns
1 parent dde9ed7 commit c58debc

File tree

2 files changed

+39
-44
lines changed

2 files changed

+39
-44
lines changed

src/providers/postgres/qgspostgresconn.cpp

+28-34
Original file line numberDiff line numberDiff line change
@@ -349,44 +349,38 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
349349
if ( result.PQresultStatus() != PGRES_TUPLES_OK )
350350
{
351351
PQexecNR( "COMMIT" );
352-
353-
if ( i == 0 )
354-
return false;
355-
356352
continue;
357353
}
358-
else
354+
355+
nGTables++;
356+
357+
for ( int idx = 0; idx < result.PQntuples(); idx++ )
359358
{
360-
nGTables++;
359+
QString tableName = result.PQgetvalue( idx, 0 );
360+
QString schemaName = result.PQgetvalue( idx, 1 );
361+
QString column = result.PQgetvalue( idx, 2 );
362+
QString type = result.PQgetvalue( idx, 3 );
363+
QString srid = result.PQgetvalue( idx, 4 );
364+
QString relkind = result.PQgetvalue( idx, 5 );
365+
366+
QgsDebugMsg( QString( "%1 : %2.%3.%4: %5 %6 %7" )
367+
.arg( gtableName )
368+
.arg( schemaName ).arg( tableName ).arg( column )
369+
.arg( type )
370+
.arg( srid )
371+
.arg( relkind ) );
372+
373+
layerProperty.type = type;
374+
layerProperty.schemaName = schemaName;
375+
layerProperty.tableName = tableName;
376+
layerProperty.geometryColName = column;
377+
layerProperty.pkCols = relkind == "v" ? pkCandidates( schemaName, tableName ) : QStringList();
378+
layerProperty.srid = srid;
379+
layerProperty.sql = "";
380+
layerProperty.isGeography = i == 1;
361381

362-
for ( int idx = 0; idx < result.PQntuples(); idx++ )
363-
{
364-
QString tableName = result.PQgetvalue( idx, 0 );
365-
QString schemaName = result.PQgetvalue( idx, 1 );
366-
QString column = result.PQgetvalue( idx, 2 );
367-
QString type = result.PQgetvalue( idx, 3 );
368-
QString srid = result.PQgetvalue( idx, 4 );
369-
QString relkind = result.PQgetvalue( idx, 5 );
370-
371-
QgsDebugMsg( QString( "%1 : %2.%3.%4: %5 %6 %7" )
372-
.arg( gtableName )
373-
.arg( schemaName ).arg( tableName ).arg( column )
374-
.arg( type )
375-
.arg( srid )
376-
.arg( relkind ) );
377-
378-
layerProperty.type = type;
379-
layerProperty.schemaName = schemaName;
380-
layerProperty.tableName = tableName;
381-
layerProperty.geometryColName = column;
382-
layerProperty.pkCols = relkind == "v" ? pkCandidates( schemaName, tableName ) : QStringList();
383-
layerProperty.srid = srid;
384-
layerProperty.sql = "";
385-
layerProperty.isGeography = i == 1;
386-
387-
mLayersSupported << layerProperty;
388-
nColumns++;
389-
}
382+
mLayersSupported << layerProperty;
383+
nColumns++;
390384
}
391385
}
392386

src/providers/postgres/qgspostgresprovider.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -2682,10 +2682,14 @@ bool QgsPostgresProvider::getGeometryDetails()
26822682
detectedType = result.PQgetvalue( 0, 0 );
26832683
detectedSrid = result.PQgetvalue( 0, 1 );
26842684
}
2685+
else
2686+
{
2687+
mConnectionRO->PQexecNR( "COMMIT" );
2688+
}
26852689

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

2698-
if ( result.PQresultStatus() == PGRES_TUPLES_OK )
2702+
if ( result.PQntuples() == 1 )
26992703
{
2700-
if ( result.PQntuples() == 1 )
2701-
{
2702-
detectedType = result.PQgetvalue( 0, 0 );
2703-
detectedSrid = result.PQgetvalue( 0, 1 );
2704-
mIsGeography = true;
2705-
}
2704+
detectedType = result.PQgetvalue( 0, 0 );
2705+
detectedSrid = result.PQgetvalue( 0, 1 );
2706+
mIsGeography = true;
27062707
}
27072708
else
27082709
{
2709-
mConnectionRO->PQexecNR( "ROLLBACK" );
2710+
mConnectionRO->PQexecNR( "COMMIT" );
27102711
}
27112712
}
27122713
}

0 commit comments

Comments
 (0)