Skip to content

Commit 403e722

Browse files
committed
Adding support for MySQL's SQL_NO_CACHE flag
1 parent de29e1e commit 403e722

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class PlainSelect extends ASTNodeAccessImpl implements SelectBody {
6060
private boolean useBrackets = false;
6161
private Wait wait;
6262
private boolean mySqlSqlCalcFoundRows = false;
63+
private boolean sqlNoCacheFlag = false;
6364

6465
public boolean isUseBrackets() {
6566
return useBrackets;
@@ -313,6 +314,9 @@ public String toString() {
313314
if (top != null) {
314315
sql.append(top).append(" ");
315316
}
317+
if (sqlNoCacheFlag) {
318+
sql.append("SQL_NO_CACHE").append(" ");
319+
}
316320
if (mySqlSqlCalcFoundRows) {
317321
sql.append("SQL_CALC_FOUND_ROWS").append(" ");
318322
}
@@ -465,7 +469,15 @@ public void setMySqlSqlCalcFoundRows(boolean mySqlCalcFoundRows) {
465469
this.mySqlSqlCalcFoundRows = mySqlCalcFoundRows;
466470
}
467471

472+
public void setMySqlSqlNoCache(boolean sqlNoCacheFlagSet) {
473+
this.sqlNoCacheFlag = sqlNoCacheFlagSet;
474+
}
475+
468476
public boolean getMySqlSqlCalcFoundRows() {
469477
return this.mySqlSqlCalcFoundRows;
470478
}
479+
480+
public boolean getMySqlSqlNoCache() {
481+
return this.sqlNoCacheFlag;
482+
}
471483
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public void visit(PlainSelect plainSelect) {
9797
buffer.append(top).append(" ");
9898
}
9999

100+
if (plainSelect.getMySqlSqlNoCache()) {
101+
buffer.append("SQL_NO_CACHE").append(" ");
102+
}
103+
100104
if (plainSelect.getMySqlSqlCalcFoundRows()) {
101105
buffer.append("SQL_CALC_FOUND_ROWS").append(" ");
102106
}

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
274274
| <K_UPSERT:"UPSERT">
275275
| <K_USE : "USE">
276276
| <K_SQL_CALC_FOUND_ROWS: "SQL_CALC_FOUND_ROWS">
277+
| <K_SQL_NO_CACHE: "SQL_NO_CACHE">
277278
| <K_USING:"USING">
278279
| <K_VALIDATE : "VALIDATE">
279280
| <K_VALUE:"VALUE">
@@ -1108,6 +1109,10 @@ PlainSelect PlainSelect() #PlainSelect:
11081109
(
11091110
<K_SQL_CALC_FOUND_ROWS> { plainSelect.setMySqlSqlCalcFoundRows(true); }
11101111
)
1112+
|
1113+
(
1114+
<K_SQL_NO_CACHE> { plainSelect.setMySqlSqlNoCache(true); }
1115+
)
11111116
]
11121117

11131118
[top = Top() { plainSelect.setTop(top); } ]

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,11 @@ public void testJsonExpression() throws JSQLParserException {
21532153
}
21542154
}
21552155

2156+
public void testSqlNoCache() throws JSQLParserException {
2157+
String stmt = "SELECT SQL_NO_CACHE sales.date FROM sales";
2158+
assertSqlCanBeParsedAndDeparsed(stmt);
2159+
}
2160+
21562161
public void testSelectInto1() throws JSQLParserException {
21572162
assertSqlCanBeParsedAndDeparsed("SELECT * INTO user_copy FROM user");
21582163
}

0 commit comments

Comments
 (0)