@@ -345,15 +345,15 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
345
345
346
346
// The following query returns only tables that exist and the user has SELECT privilege on.
347
347
// Can't use regclass here because table must exist, else error occurs.
348
- sql = QString ( " SELECT %1,%2,%3,%4,c.relkind"
349
- " FROM %5 l,pg_class c,pg_namespace n"
348
+ sql = QString ( " SELECT %1,%2,%3,%4,%5, c.relkind"
349
+ " FROM %6 l,pg_class c,pg_namespace n"
350
350
" WHERE c.relname=%1"
351
351
" AND %2=n.nspname"
352
352
" AND n.oid=c.relnamespace"
353
353
" AND has_schema_privilege(n.nspname,'usage')"
354
354
" AND has_table_privilege('\" '||n.nspname||'\" .\" '||c.relname||'\" ','select')" // user has select privilege
355
355
)
356
- .arg ( tableName ).arg ( schemaName ).arg ( columnName ).arg ( typeName ).arg ( gtableName );
356
+ .arg ( tableName ).arg ( schemaName ).arg ( columnName ).arg ( typeName ).arg ( sridName ). arg ( gtableName );
357
357
358
358
if ( searchPublicOnly )
359
359
sql += " AND n.nspname='public'" ;
@@ -388,7 +388,16 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
388
388
layerProperty.schemaName = schemaName;
389
389
layerProperty.tableName = tableName;
390
390
layerProperty.geometryColName = column;
391
- layerProperty.pkCols = relkind == " v" ? pkCandidates ( schemaName, tableName ) : QStringList ();
391
+
392
+ if ( relkind == " v" )
393
+ {
394
+ layerProperty.pkCols = pkCandidates ( schemaName, tableName );
395
+ if ( layerProperty.pkCols .isEmpty () )
396
+ {
397
+ QgsDebugMsg ( " no key columns found." );
398
+ continue ;
399
+ }
400
+ }
392
401
layerProperty.srid = srid;
393
402
layerProperty.sql = " " ;
394
403
layerProperty.isGeography = i == 1 ;
@@ -472,18 +481,26 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
472
481
// Make the assumption that the geometry type for the first
473
482
// row is the same as for all other rows.
474
483
475
- QString table = result.PQgetvalue ( i, 0 ); // relname
476
- QString schema = result.PQgetvalue ( i, 1 ); // nspname
477
- QString column = result.PQgetvalue ( i, 2 ); // attname
478
- QString relkind = result.PQgetvalue ( i, 3 ); // relation kind
484
+ QString tableName = result.PQgetvalue ( i, 0 ); // relname
485
+ QString schemaName = result.PQgetvalue ( i, 1 ); // nspname
486
+ QString column = result.PQgetvalue ( i, 2 ); // attname
487
+ QString relkind = result.PQgetvalue ( i, 3 ); // relation kind
479
488
480
- QgsDebugMsg ( QString ( " %1.%2.%3: %4" ).arg ( schema ).arg ( table ).arg ( column ).arg ( relkind ) );
489
+ QgsDebugMsg ( QString ( " %1.%2.%3: %4" ).arg ( schemaName ).arg ( tableName ).arg ( column ).arg ( relkind ) );
481
490
482
491
layerProperty.type = QString::null;
483
- layerProperty.schemaName = schema ;
484
- layerProperty.tableName = table ;
492
+ layerProperty.schemaName = schemaName ;
493
+ layerProperty.tableName = tableName ;
485
494
layerProperty.geometryColName = column;
486
- layerProperty.pkCols = relkind == " v" ? pkCandidates ( schema, table ) : QStringList ();
495
+ if ( relkind == " v" )
496
+ {
497
+ layerProperty.pkCols = pkCandidates ( schemaName, tableName );
498
+ if ( layerProperty.pkCols .isEmpty () )
499
+ {
500
+ QgsDebugMsg ( " no key columns found." );
501
+ continue ;
502
+ }
503
+ }
487
504
layerProperty.sql = " " ;
488
505
layerProperty.isGeography = false ; // TODO might be geography after all
489
506
0 commit comments