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

Initial commit, prohibiting empty predicate for IN clause.

上级 749aa5a5
......@@ -2176,6 +2176,9 @@ public class Parser {
} else if (readIf("IN")) {
read("(");
if (readIf(")")) {
if (database.getMode().prohibitEmptyInPredicate) {
throw getSyntaxError();
}
r = ValueExpression.get(ValueBoolean.get(false));
} else {
if (isSelect()) {
......
......@@ -150,6 +150,8 @@ public class Mode {
*/
public boolean supportPoundSymbolForColumnNames;
public boolean prohibitEmptyInPredicate;
private final String name;
static {
......@@ -168,6 +170,7 @@ public class Mode {
mode.supportedClientInfoPropertiesRegEx =
Pattern.compile("ApplicationName|ClientAccountingInformation|" +
"ClientUser|ClientCorrelationToken");
mode.prohibitEmptyInPredicate = true;
add(mode);
mode = new Mode("Derby");
......@@ -216,6 +219,7 @@ public class Mode {
// JDBC4CommentClientInfoProvider.java
mode.supportedClientInfoPropertiesRegEx =
Pattern.compile(".*");
mode.prohibitEmptyInPredicate = true;
add(mode);
mode = new Mode("Oracle");
......@@ -228,6 +232,7 @@ public class Mode {
// https://docs.oracle.com/database/121/JJDBC/jdbcvers.htm#JJDBC29006
mode.supportedClientInfoPropertiesRegEx =
Pattern.compile(".*\\..*");
mode.prohibitEmptyInPredicate = true;
add(mode);
mode = new Mode("PostgreSQL");
......@@ -242,6 +247,7 @@ public class Mode {
// org/postgresql/jdbc4/AbstractJdbc4Connection.java
mode.supportedClientInfoPropertiesRegEx =
Pattern.compile("ApplicationName");
mode.prohibitEmptyInPredicate = true;
add(mode);
}
......
......@@ -218,6 +218,11 @@ public class TestCompatibility extends TestBase {
prep.setInt(1, 2);
prep.executeQuery();
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 {
......
......@@ -37,6 +37,7 @@ public class TestCompatibilityOracle extends TestBase {
testDecimalScale();
testPoundSymbolInColumnName();
testToDate();
testForbidEmptyInClause();
}
private void testTreatEmptyStringsAsNull() throws SQLException {
......@@ -161,6 +162,22 @@ public class TestCompatibilityOracle extends TestBase {
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)
throws SQLException {
SimpleDateFormat iso8601 = new SimpleDateFormat(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论