提交 dc05455d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Check if we are in select statement to throw proper error in ExpressionColumn.getValue()

上级 969f44a9
......@@ -187,8 +187,12 @@ public class ExpressionColumn extends Expression {
Value value = columnResolver.getValue(column);
if (value == null) {
columnResolver.getValue(column);
if (select == null) {
throw DbException.get(ErrorCode.NULL_NOT_ALLOWED, getSQL());
} else {
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
}
if (column.getEnumerators() != null && value != ValueNull.INSTANCE) {
return ValueEnum.get(column.getEnumerators(), value.getInt());
}
......
......@@ -51,6 +51,7 @@ public class TestCases extends TestBase {
testLargeKeys();
testExtraSemicolonInDatabaseURL();
testGroupSubquery();
testSelfReferentialColumn();
testCountDistinctNotNull();
testDependencies();
testDropTable();
......@@ -234,6 +235,32 @@ public class TestCases extends TestBase {
conn.close();
}
private void testSelfReferentialColumn() throws SQLException {
deleteDb("selfreferential");
Connection conn = getConnection("selfreferential");
Statement stat = conn.createStatement();
stat.execute("create table sr(id integer, usecount integer as usecount + 1)");
check: {
try {
stat.execute("insert into sr(id) values (1)");
} catch (SQLException ex) {
assertEquals(ErrorCode.getState(ErrorCode.NULL_NOT_ALLOWED), ex.getSQLState());
break check;
}
fail("Exception expected");
}
check: {
try {
stat.execute("select max(id), usecount from sr");
} catch (SQLException ex) {
assertEquals(ErrorCode.getState(ErrorCode.MUST_GROUP_BY_COLUMN_1), ex.getSQLState());
break check;
}
fail("Exception expected");
}
conn.close();
}
private void testCountDistinctNotNull() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论