提交 0840ef36 authored 作者: Thomas Mueller's avatar Thomas Mueller

The wrong parameters were bound to subqueries with parameters.

上级 1f062c6d
......@@ -853,9 +853,9 @@ public class Select extends Query {
}
public String getPlanSQL() {
if (topTableFilter == null) {
return sqlStatement;
}
// can not use the field sqlStatement because the parameter
// indexes may be incorrect: ? may be in fact ?2 for a subquery
// but indexes may be set manually as well
StringBuffer buff = new StringBuffer();
Expression[] exprList = new Expression[expressions.size()];
expressions.toArray(exprList);
......@@ -872,17 +872,25 @@ public class Select extends Query {
}
buff.append("\nFROM ");
TableFilter filter = topTableFilter;
boolean join = false;
int id = 0;
if (filter != null) {
int i = 0;
do {
if (id > 0) {
if (i > 0) {
buff.append("\n");
}
buff.append(filter.getPlanSQL(join));
id++;
join = true;
buff.append(filter.getPlanSQL(i > 0));
i++;
filter = filter.getJoin();
} while (filter != null);
} else {
for (int i = 0; i < filters.size(); i++) {
if (i > 0) {
buff.append("\n");
}
filter = (TableFilter) filters.get(i);
buff.append(filter.getPlanSQL(i > 0));
}
}
if (condition != null) {
buff.append("\nWHERE " + StringUtils.unEnclose(condition.getSQL()));
}
......@@ -897,6 +905,16 @@ public class Select extends Query {
buff.append(StringUtils.unEnclose(g.getSQL()));
}
}
if (group != null) {
buff.append("\nGROUP BY ");
for (int i = 0; i < group.size(); i++) {
Expression g = (Expression) group.get(i);
if (i > 0) {
buff.append(", ");
}
buff.append(StringUtils.unEnclose(g.getSQL()));
}
}
if (having != null) {
// could be set in addGlobalCondition
// in this case the query is not run directly, just getPlanSQL is
......@@ -911,6 +929,16 @@ public class Select extends Query {
buff.append("\nORDER BY ");
buff.append(sort.getSQL(exprList, visibleColumnCount));
}
if (orderList != null) {
buff.append("\nORDER BY ");
for (int i = 0; i < orderList.size(); i++) {
if (i > 0) {
buff.append(", ");
}
SelectOrderBy o = (SelectOrderBy) orderList.get(i);
buff.append(StringUtils.unEnclose(o.getSQL()));
}
}
if (limit != null) {
buff.append("\nLIMIT ");
buff.append(StringUtils.unEnclose(limit.getSQL()));
......
......@@ -39,4 +39,24 @@ public class SelectOrderBy {
* If NULL should be appear at the end.
*/
public boolean nullsLast;
public String getSQL() {
StringBuffer buff = new StringBuffer();
if (columnIndexExpr != null) {
buff.append(columnIndexExpr.getSQL());
} else {
buff.append("=");
buff.append(expression.getSQL());
}
if (descending) {
buff.append(" DESC");
}
if (nullsFirst) {
buff.append(" NULLS FIRST");
} else if (nullsLast) {
buff.append(" NULLS LAST");
}
return buff.toString();
}
}
......@@ -149,12 +149,7 @@ public class TransactionCommand extends Prepared {
break;
case SHUTDOWN_IMMEDIATELY:
session.getUser().checkAdmin();
session.getDatabase().setPowerOffCount(1);
try {
session.getDatabase().checkPowerOff();
} catch (SQLException e) {
// ignore
}
session.getDatabase().shutdownImmediately();
break;
case SHUTDOWN: {
session.getUser().checkAdmin();
......
......@@ -157,6 +157,7 @@ public class ViewIndex extends BaseIndex {
for (int i = 0; originalParameters != null && i < originalParameters.size(); i++) {
Parameter orig = (Parameter) originalParameters.get(i);
Value value = orig.getValue(session);
idx = orig.getIndex();
Parameter param = (Parameter) paramList.get(idx++);
param.setValue(value);
}
......
......@@ -510,6 +510,7 @@ public class TableFilter implements ColumnResolver {
buff.append(' ');
buff.append(Parser.quoteIdentifier(alias));
}
if (index != null) {
buff.append(" /* ");
StringBuffer planBuff = new StringBuffer();
planBuff.append(index.getPlanSQL());
......@@ -527,6 +528,7 @@ public class TableFilter implements ColumnResolver {
plan = StringUtils.quoteRemarkSQL(plan);
buff.append(plan);
buff.append(" */");
}
if (join) {
buff.append(" ON ");
if (joinCondition == null) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论