@@ -54,7 +54,8 @@ def __init__(self, iface, db, parent=None):
54
54
QWidget .__init__ (self , parent )
55
55
self .iface = iface
56
56
self .db = db
57
- self .allowMultiColumnPk = isinstance (db , PGDatabase ) # at the moment only PostGIS allows a primary key to span multiple columns, spatialite doesn't
57
+ self .allowMultiColumnPk = isinstance (db , PGDatabase ) # at the moment only PostgreSQL allows a primary key to span multiple columns, spatialite doesn't
58
+ self .aliasSubQuery = isinstance (db , PGDatabase ) # only PostgreSQL requires subqueries to be aliases
58
59
self .setupUi (self )
59
60
self .setWindowTitle (
60
61
u"%s - %s [%s]" % (self .windowTitle (), db .connection ().connectionName (), db .connection ().typeNameString ()))
@@ -270,15 +271,6 @@ def fillColumnCombos(self):
270
271
271
272
QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
272
273
273
- # get a new alias
274
- aliasIndex = 0
275
- while True :
276
- alias = "_%s__%d" % ("subQuery" , aliasIndex )
277
- escaped = re .compile ('\\ b("?)' + re .escape (alias ) + '\\ 1\\ b' )
278
- if not escaped .search (query ):
279
- break
280
- aliasIndex += 1
281
-
282
274
# remove a trailing ';' from query if present
283
275
if query .strip ().endswith (';' ):
284
276
query = query .strip ()[:- 1 ]
@@ -287,7 +279,19 @@ def fillColumnCombos(self):
287
279
cols = []
288
280
quotedCols = []
289
281
connector = self .db .connector
290
- sql = u"SELECT * FROM (%s\n ) AS %s WHERE 0=1" % (unicode (query ), connector .quoteId (alias ))
282
+ if self .aliasSubQuery :
283
+ # get a new alias
284
+ aliasIndex = 0
285
+ while True :
286
+ alias = "_subQuery__%d" % aliasIndex
287
+ escaped = re .compile ('\\ b("?)' + re .escape (alias ) + '\\ 1\\ b' )
288
+ if not escaped .search (query ):
289
+ break
290
+ aliasIndex += 1
291
+
292
+ sql = u"SELECT * FROM (%s\n ) AS %s LIMIT 0" % (unicode (query ), connector .quoteId (alias ))
293
+ else :
294
+ sql = u"SELECT * FROM (%s\n ) WHERE 1=0" % unicode (query )
291
295
292
296
c = None
293
297
try :
0 commit comments