Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ad9e26

Browse files
committed
bug fix for ORDER BY users provided statements (issue #354)
1 parent ebd1d30 commit 1ad9e26

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

lib/core/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,15 @@ def limitQuery(self, num, query, field=None, uniqueField=None):
822822
limitedQuery += " %s" % limitStr
823823

824824
elif Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2):
825-
if " ORDER BY " in limitedQuery and "(SELECT " in limitedQuery:
826-
orderBy = limitedQuery[limitedQuery.index(" ORDER BY "):]
825+
if " ORDER BY " in limitedQuery and "SELECT " in limitedQuery:
827826
limitedQuery = limitedQuery[:limitedQuery.index(" ORDER BY ")]
828827

829828
if query.startswith("SELECT "):
830829
delimiter = queries[Backend.getIdentifiedDbms()].delimiter.query
831830
limitedQuery = "%s FROM (%s,%s" % (untilFrom, untilFrom.replace(delimiter, ','), limitStr)
832831
else:
833832
limitedQuery = "%s FROM (SELECT %s,%s" % (untilFrom, ','.join(f for f in field), limitStr)
833+
834834
limitedQuery = limitedQuery % fromFrom
835835
limitedQuery += "=%d" % (num + 1)
836836

xml/queries.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
<length query="LENGTH(%s)"/>
210210
<isnull query="NVL(%s,' ')"/>
211211
<delimiter query="||"/>
212-
<limit query="ROWNUM AS LIMIT %s ORDER BY 1 ASC) WHERE LIMIT"/>
212+
<limit query="ROWNUM AS LIMIT %s) WHERE LIMIT"/>
213213
<limitregexp query="ROWNUM\s+AS\s+.+?\s+FROM\s+.+?\)\s+WHERE\s+.+?\s*=\s*[\d]+|ROWNUM\s*=\s*[\d]+"/>
214214
<limitgroupstart/>
215215
<limitgroupstop/>

0 commit comments

Comments
 (0)