提交 31868fb7 authored 作者: Marko Tiigi's avatar Marko Tiigi

Initial commit, prohibiting empty predicate for IN clause.

上级 749aa5a5
...@@ -2176,6 +2176,9 @@ public class Parser { ...@@ -2176,6 +2176,9 @@ public class Parser {
} else if (readIf("IN")) { } else if (readIf("IN")) {
read("("); read("(");
if (readIf(")")) { if (readIf(")")) {
if (database.getMode().prohibitEmptyInPredicate) {
throw getSyntaxError();
}
r = ValueExpression.get(ValueBoolean.get(false)); r = ValueExpression.get(ValueBoolean.get(false));
} else { } else {
if (isSelect()) { if (isSelect()) {
......
...@@ -150,6 +150,8 @@ public class Mode { ...@@ -150,6 +150,8 @@ public class Mode {
*/ */
public boolean supportPoundSymbolForColumnNames; public boolean supportPoundSymbolForColumnNames;
public boolean prohibitEmptyInPredicate;
private final String name; private final String name;
static { static {
...@@ -168,6 +170,7 @@ public class Mode { ...@@ -168,6 +170,7 @@ public class Mode {
mode.supportedClientInfoPropertiesRegEx = mode.supportedClientInfoPropertiesRegEx =
Pattern.compile("ApplicationName|ClientAccountingInformation|" + Pattern.compile("ApplicationName|ClientAccountingInformation|" +
"ClientUser|ClientCorrelationToken"); "ClientUser|ClientCorrelationToken");
mode.prohibitEmptyInPredicate = true;
add(mode); add(mode);
mode = new Mode("Derby"); mode = new Mode("Derby");
...@@ -216,6 +219,7 @@ public class Mode { ...@@ -216,6 +219,7 @@ public class Mode {
// JDBC4CommentClientInfoProvider.java // JDBC4CommentClientInfoProvider.java
mode.supportedClientInfoPropertiesRegEx = mode.supportedClientInfoPropertiesRegEx =
Pattern.compile(".*"); Pattern.compile(".*");
mode.prohibitEmptyInPredicate = true;
add(mode); add(mode);
mode = new Mode("Oracle"); mode = new Mode("Oracle");
...@@ -228,6 +232,7 @@ public class Mode { ...@@ -228,6 +232,7 @@ public class Mode {
// https://docs.oracle.com/database/121/JJDBC/jdbcvers.htm#JJDBC29006 // https://docs.oracle.com/database/121/JJDBC/jdbcvers.htm#JJDBC29006
mode.supportedClientInfoPropertiesRegEx = mode.supportedClientInfoPropertiesRegEx =
Pattern.compile(".*\\..*"); Pattern.compile(".*\\..*");
mode.prohibitEmptyInPredicate = true;
add(mode); add(mode);
mode = new Mode("PostgreSQL"); mode = new Mode("PostgreSQL");
...@@ -242,6 +247,7 @@ public class Mode { ...@@ -242,6 +247,7 @@ public class Mode {
// org/postgresql/jdbc4/AbstractJdbc4Connection.java // org/postgresql/jdbc4/AbstractJdbc4Connection.java
mode.supportedClientInfoPropertiesRegEx = mode.supportedClientInfoPropertiesRegEx =
Pattern.compile("ApplicationName"); Pattern.compile("ApplicationName");
mode.prohibitEmptyInPredicate = true;
add(mode); add(mode);
} }
......
...@@ -218,6 +218,11 @@ public class TestCompatibility extends TestBase { ...@@ -218,6 +218,11 @@ public class TestCompatibility extends TestBase {
prep.setInt(1, 2); prep.setInt(1, 2);
prep.executeQuery(); prep.executeQuery();
stat.execute("DROP TABLE TEST IF EXISTS"); stat.execute("DROP TABLE TEST IF EXISTS");
stat.execute("DROP TABLE TEST IF EXISTS");
stat.execute("CREATE TABLE TEST(ID INT)");
stat.executeQuery("SELECT * FROM TEST WHERE ID IN ()");
stat.execute("DROP TABLE TEST IF EXISTS");
} }
private void testLog(double expected, Statement stat) throws SQLException { private void testLog(double expected, Statement stat) throws SQLException {
......
...@@ -37,6 +37,7 @@ public class TestCompatibilityOracle extends TestBase { ...@@ -37,6 +37,7 @@ public class TestCompatibilityOracle extends TestBase {
testDecimalScale(); testDecimalScale();
testPoundSymbolInColumnName(); testPoundSymbolInColumnName();
testToDate(); testToDate();
testForbidEmptyInClause();
} }
private void testTreatEmptyStringsAsNull() throws SQLException { private void testTreatEmptyStringsAsNull() throws SQLException {
...@@ -161,6 +162,22 @@ public class TestCompatibilityOracle extends TestBase { ...@@ -161,6 +162,22 @@ public class TestCompatibilityOracle extends TestBase {
conn.close(); conn.close();
} }
private void testForbidEmptyInClause() throws SQLException {
deleteDb("oracle");
Connection conn = getConnection("oracle;MODE=Oracle");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE A (ID NUMBER, X VARCHAR2(1))");
try {
stat.executeQuery("SELECT * FROM A WHERE ID IN ()");
fail();
}
catch (SQLException e) {
} finally {
conn.close();
}
}
private void assertResultDate(String expected, Statement stat, String sql) private void assertResultDate(String expected, Statement stat, String sql)
throws SQLException { throws SQLException {
SimpleDateFormat iso8601 = new SimpleDateFormat( SimpleDateFormat iso8601 = new SimpleDateFormat(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论