Skip to content
Permalink
Browse files

db manager: only alias subqueries on postgres (fixes #13731)

Conflicts:
	python/plugins/db_manager/dlg_sql_window.py
  • Loading branch information
jef-n authored and rldhont committed Dec 2, 2015
1 parent edd3f8d commit 80c5cb6807254c1323f4c8fdc923b3dae6c928b7
Showing with 15 additions and 11 deletions.
  1. +15 −11 python/plugins/db_manager/dlg_sql_window.py
@@ -54,7 +54,8 @@ def __init__(self, iface, db, parent=None):
QWidget.__init__(self, parent)
self.iface = iface
self.db = db
self.allowMultiColumnPk = isinstance(db, PGDatabase) # at the moment only PostGIS allows a primary key to span multiple columns, spatialite doesn't
self.allowMultiColumnPk = isinstance(db, PGDatabase) # at the moment only PostgreSQL allows a primary key to span multiple columns, spatialite doesn't
self.aliasSubQuery = isinstance(db, PGDatabase) # only PostgreSQL requires subqueries to be aliases
self.setupUi(self)
self.setWindowTitle(
u"%s - %s [%s]" % (self.windowTitle(), db.connection().connectionName(), db.connection().typeNameString()))
@@ -270,15 +271,6 @@ def fillColumnCombos(self):

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

# get a new alias
aliasIndex = 0
while True:
alias = "_%s__%d" % ("subQuery", aliasIndex)
escaped = re.compile('\\b("?)' + re.escape(alias) + '\\1\\b')
if not escaped.search(query):
break
aliasIndex += 1

# remove a trailing ';' from query if present
if query.strip().endswith(';'):
query = query.strip()[:-1]
@@ -287,7 +279,19 @@ def fillColumnCombos(self):
cols = []
quotedCols = []
connector = self.db.connector
sql = u"SELECT * FROM (%s\n) AS %s WHERE 0=1" % (unicode(query), connector.quoteId(alias))
if self.aliasSubQuery:
# get a new alias
aliasIndex = 0
while True:
alias = "_subQuery__%d" % aliasIndex
escaped = re.compile('\\b("?)' + re.escape(alias) + '\\1\\b')
if not escaped.search(query):
break
aliasIndex += 1

sql = u"SELECT * FROM (%s\n) AS %s LIMIT 0" % (unicode(query), connector.quoteId(alias))
else:
sql = u"SELECT * FROM (%s\n) WHERE 1=0" % unicode(query)

c = None
try:

0 comments on commit 80c5cb6

Please sign in to comment.
You can’t perform that action at this time.