Skip to content

Commit 23d4948

Browse files
sivaraamwumpz
authored andcommitted
Limit: properly retain 'ALL' in queries with 'LIMIT ALL' (#904)
1 parent 808e320 commit 23d4948

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/main/java/net/sf/jsqlparser/statement/select/Limit.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ public String toString() {
5757
if (limitNull) {
5858
retVal += "NULL";
5959
} else {
60-
if (null != offset) {
61-
retVal += offset + ", ";
62-
}
63-
if (null != rowCount) {
64-
retVal += rowCount;
60+
if (limitAll) {
61+
retVal += "ALL";
62+
} else {
63+
if (null != offset) {
64+
retVal += offset + ", ";
65+
}
66+
if (null != rowCount) {
67+
retVal += rowCount;
68+
}
6569
}
6670
}
6771

src/main/java/net/sf/jsqlparser/util/deparser/LimitDeparser.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ public void deParse(Limit limit) {
2424
if (limit.isLimitNull()) {
2525
buffer.append("NULL");
2626
} else {
27-
if (null != limit.getOffset()) {
28-
buffer.append(limit.getOffset()).append(", ");
29-
}
27+
if (limit.isLimitAll()) {
28+
buffer.append("ALL");
29+
} else {
30+
if (null != limit.getOffset()) {
31+
buffer.append(limit.getOffset()).append(", ");
32+
}
3033

31-
if (null != limit.getRowCount()) {
32-
buffer.append(limit.getRowCount());
34+
if (null != limit.getRowCount()) {
35+
buffer.append(limit.getRowCount());
36+
}
3337
}
3438
}
3539
}

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,18 @@ public void testLimit2() throws JSQLParserException {
339339
assertTrue(((PlainSelect) select.getSelectBody()).getLimit().isLimitNull());
340340
assertSqlCanBeParsedAndDeparsed(statement);
341341

342+
statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT ALL OFFSET 5";
343+
select = (Select) parserManager.parse(new StringReader(statement));
344+
offset = ((PlainSelect) select.getSelectBody()).getLimit().getOffset();
345+
rowCount = ((PlainSelect) select.getSelectBody()).getLimit().getRowCount();
346+
347+
assertNull(offset);
348+
assertNull(rowCount);
349+
assertEquals(5, ((PlainSelect) select.getSelectBody()).getOffset().getOffset());
350+
assertTrue(((PlainSelect) select.getSelectBody()).getLimit().isLimitAll());
351+
assertFalse(((PlainSelect) select.getSelectBody()).getLimit().isLimitNull());
352+
assertSqlCanBeParsedAndDeparsed(statement);
353+
342354
statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT 0 OFFSET 3";
343355
select = (Select) parserManager.parse(new StringReader(statement));
344356
offset = ((PlainSelect) select.getSelectBody()).getLimit().getOffset();

0 commit comments

Comments
 (0)