Bug report #19343

Comment in last line of Query in DB Manager makes "Load now!" fail

Added by Johannes Kroeger almost 2 years ago. Updated almost 2 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:DB Manager
Affected QGIS version:2.18.21 Regression?:No
Operating System: Easy fix?:Yes
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:27171

Description

If one has a SQL comment in the last line of a (PostGIS) query in the DB manager, QGIS will fail to load the layer with a syntax error hidden in the PostGIS messages log.

SQL: SELECT * FROM (SELECT row_number() over () AS _uid_,* FROM (myoriginalquery
--some comment I wrote) AS _subq_1_
) AS "subQuery_0" LIMIT 1

This is due to QGIS appending its surrounding code directly after the last character and this makes it just part of the comment
Always adding a linebreak after the user's lines should solve this:

SQL: SELECT * FROM (SELECT row_number() over () AS _uid_,* FROM (myoriginalquery
--some comment I wrote
) AS _subq_1_
) AS "subQuery_0" LIMIT 1

I would fix and test this but cannot understand the code :) It will probably apply in multiple providers:

https://github.com/qgis/QGIS/search?q=AS+%22subQuery_0%22+LIMIT+1&unscoped_q=AS+%22subQuery_0%22+LIMIT+1

Associated revisions

Revision 870d0784
Added by Jürgen Fischer almost 2 years ago

db manager: also add newline when adding a unique id field (fixes #19343)

Revision ca2abb56
Added by Jürgen Fischer almost 2 years ago

db manager: also add newline when adding a unique id field (fixes #19343)

(cherry picked from commit 870d078479352d61edd902ab9d2ca48e98db9148)

Revision ef6ce4ec
Added by Jürgen Fischer almost 2 years ago

db manager: also add newline when adding a unique id field (fixes #19343)

(cherry picked from commit 870d078479352d61edd902ab9d2ca48e98db9148)

History

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

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

Also available in: Atom PDF