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

Fix NPE in Query.initExpression()

上级 84092ec5
...@@ -519,13 +519,11 @@ public abstract class Query extends Prepared { ...@@ -519,13 +519,11 @@ public abstract class Query extends Prepared {
} }
} }
if (!isAlias) { if (!isAlias) {
if (mustBeInResult) { if (expressionSQL == null
if (session.getDatabase().getMode().getEnum() != ModeEnum.MySQL) { || mustBeInResult && session.getDatabase().getMode().getEnum() != ModeEnum.MySQL
if (!checkOrderOther(session, e, expressionSQL)) { && !checkOrderOther(session, e, expressionSQL)) {
throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT, e.getSQL()); throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT, e.getSQL());
} }
}
}
expressions.add(e); expressions.add(e);
String sql = e.getSQL(); String sql = e.getSQL();
expressionSQL.add(sql); expressionSQL.add(sql);
...@@ -549,14 +547,12 @@ public abstract class Query extends Prepared { ...@@ -549,14 +547,12 @@ public abstract class Query extends Prepared {
if (expr.isConstant()) { if (expr.isConstant()) {
return true; return true;
} }
if (expressionSQL != null) {
String exprSQL = expr.getSQL(); String exprSQL = expr.getSQL();
for (String sql: expressionSQL) { for (String sql: expressionSQL) {
if (session.getDatabase().equalsIdentifiers(exprSQL, sql)) { if (session.getDatabase().equalsIdentifiers(exprSQL, sql)) {
return true; return true;
} }
} }
}
if (expr instanceof Function) { if (expr instanceof Function) {
Function function = (Function) expr; Function function = (Function) expr;
if (!function.isDeterministic()) { if (!function.isDeterministic()) {
......
...@@ -252,3 +252,18 @@ SELECT A, COUNT(B) FROM TEST GROUP BY A OFFSET 1; ...@@ -252,3 +252,18 @@ SELECT A, COUNT(B) FROM TEST GROUP BY A OFFSET 1;
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
CREATE TABLE TEST1(A INT, B INT, C INT) AS SELECT 1, 2, 3;
> ok
CREATE TABLE TEST2(A INT, B INT, C INT) AS SELECT 4, 5, 6;
> ok
SELECT A, B FROM TEST1 UNION SELECT A, B FROM TEST2 ORDER BY 1.1;
> exception ORDER_BY_NOT_IN_RESULT
DROP TABLE TEST1;
> ok
DROP TABLE TEST2;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论