Bug report #9453

ERROR: schema "topology" does not exist

Added by Sandro Santilli almost 6 years ago. Updated almost 6 years ago.

Status:Closed
Priority:Normal
Assignee:Sandro Santilli
Category:Data Provider/PostGIS
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:18045

Description

Metadata tables of topology are queried even if topology is not available, resulting in an error.
This is when connecting to a PostGIS database with no topology, error shown in the log.
No idea about possible consequences of that (if any) but it doesn't sound clean to raise an error.
QGIS already checks for topology availability, so has all the information to decide NOT to query topology metadata when topology isn't available.

This is with current master

Associated revisions

Revision 7456eb79
Added by Jürgen Fischer almost 6 years ago

postgres provider: don't look for topology layers without topology support (fixes #9453)

Revision 673406d2
Added by Jürgen Fischer almost 6 years ago

postgres provider: don't look for topology layers without topology support (fixes #9453)

Revision da4c4292
Added by Sandro Santilli almost 6 years ago

Fix query to detect postgis topology availability.

Closes #9453

Revision f8028087
Added by Sandro Santilli almost 6 years ago

Fix query to detect postgis topology availability.

Closes #9453

History

#1 Updated by Jürgen Fischer almost 6 years ago

  • Status changed from Open to Closed

#2 Updated by Sandro Santilli almost 6 years ago

  • Status changed from Closed to Reopened

Sorry but I cannot confirm the fix. Could be a problem on my side but as of f45e112 I still see the error:

src/providers/postgres/qgspostgresconn.cpp: 385: (getTableInfo) getting table info: SELECT l.table_name,l.schema_name,l.feature_column,CASE WHEN l.feature_type = 1 THEN 'MULTIPOINT' WHEN l.feature_type = 2 THEN 'MULTILINESTRING' WHEN l.feature_type = 3 THEN 'MULTIPOLYGON' WHEN l.feature_type = 4 THEN 'GEOMETRYCOLLECTION' END AS type,(SELECT srid FROM topology.topology t WHERE l.topology_id=t.id),c.relkind FROM topology.layer l,pg_class c,pg_namespace n WHERE c.relname=l.table_name AND l.schema_name=n.nspname AND n.oid=c.relnamespace AND has_schema_privilege(n.nspname,'usage') AND has_table_privilege('"'||n.nspname||'"."'||c.relname||'"','select') ORDER BY n.nspname,c.relname,l.feature_column
src/providers/postgres/qgspostgresconn.cpp: 805: (PQexec) Not logged erroneous query: SELECT l.table_name,l.schema_name,l.feature_column,CASE WHEN l.feature_type = 1 THEN 'MULTIPOINT' WHEN l.feature_type = 2 THEN 'MULTILINESTRING' WHEN l.feature_type = 3 THEN 'MULTIPOLYGON' WHEN l.feature_type = 4 THEN 'GEOMETRYCOLLECTION' END AS type,(SELECT srid FROM topology.topology t WHERE l.topology_id=t.id),c.relkind FROM topology.layer l,pg_class c,pg_namespace n WHERE c.relname=l.table_name AND l.schema_name=n.nspname AND n.oid=c.relnamespace AND has_schema_privilege(n.nspname,'usage') AND has_table_privilege('"'||n.nspname||'"."'||c.relname||'"','select') ORDER BY n.nspname,c.relname,l.feature_column returned 7 [ERROR:  schema "topology" does not exist
LINE 1: ...pology t WHERE l.topology_id=t.id),c.relkind FROM topology.l...
                                                             ^
]
WARNING:  there is no transaction in progress

#3 Updated by Sandro Santilli almost 6 years ago

  • Assignee set to Sandro Santilli

Found the bug, is in the function checking for topology support:

+ QgsPostgresResult result = PQexec( "SELECT count(c.oid) FROM pg_class AS c JOIN pg_namespace AS n ON c.relnamespace=n.oid WHERE n.nspname='topology' AND c.relname='topology'" );
+ if ( result.PQntuples() >= 1 )
+ {
+ mTopologyAvailable = true;
+ }
+ }

Should indeed be looking at the count, since the query is:

#4 Updated by Sandro Santilli almost 6 years ago

Besides, may I suggest to look at the "TOPOLOGY" label in output from postgis_full_version() instead ?

#5 Updated by Sandro Santilli almost 6 years ago

Like this (will test after lunch):

diff --git a/src/providers/postgres/qgspostgresconn.cpp b/src/providers/postgres/qgspostgresconn.cpp
index b4eaf1e..311a0fc 100644
--- a/src/providers/postgres/qgspostgresconn.cpp
+++ b/src/providers/postgres/qgspostgresconn.cpp
@@ -719,17 +719,10 @@ QString QgsPostgresConn::postgisVersion()
     {
       mProjAvailable = ( proj[0].indexOf( "=1" ) > -1 );
     }
-  }
-
-  // checking for topology support
-  QgsDebugMsg( "Checking for topology support" );
-  mTopologyAvailable = false;
-  if ( mPostgisVersionMajor > 1 )
-  {
-    QgsPostgresResult result = PQexec( "SELECT count(c.oid) FROM pg_class AS c JOIN pg_namespace AS n ON c.relnamespace=n.oid WHERE n.nspname='topology' AND c.relname='topology'" );
-    if ( result.PQntuples() >= 1 )
+    QStringList proj = postgisParts.filter( "TOPOLOGY" );
+    if ( proj.size() == 1 )
     {
-      mTopologyAvailable = true;
+      mTopologyAvailable = ( proj[0].indexOf( "=1" ) > -1 );
     }
   }

#6 Updated by Sandro Santilli almost 6 years ago

Sorry for the noise, the version string is extracted using "postgis_version()", not "postgis_full_version()", so can't check for TOPOLOGY. Also the topology.topology trick woudl support pre-2.0 installs of postgis topology which is good.

#7 Updated by Sandro Santilli almost 6 years ago

  • Status changed from Reopened to Closed

#8 Updated by Sandro Santilli almost 6 years ago

  • Resolution set to fixed/implemented
  • % Done changed from 0 to 100

Also available in: Atom PDF