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