提交 8f94e925 编写于 作者: G gaoht

support "select union all"'s batch insert fix #72

上级 f63eaa0c
......@@ -108,6 +108,9 @@ public abstract class AbstractMySQLVisitor extends MySqlOutputVisitor implements
@Override
public final boolean visit(final SQLExprTableSource x) {
if ("dual".equalsIgnoreCase(SQLUtil.getExactlyValue(x.getExpr().toString()))) {
return super.visit(x);
}
return visit(x, getParseContext().addTable(x));
}
......
......@@ -32,6 +32,9 @@ public class MySQLInsertVisitor extends AbstractMySQLVisitor {
@Override
public boolean visit(final MySqlInsertStatement x) {
getParseContext().setCurrentTable(x.getTableName().toString(), Optional.fromNullable(x.getAlias()));
if (null == x.getValues()) {
return super.visit(x);
}
for (int i = 0; i < x.getColumns().size(); i++) {
getParseContext().addCondition(x.getColumns().get(i).toString(), x.getTableName().toString(), BinaryOperator.EQUAL, x.getValues().getValues().get(i), getDatabaseType(), getParameters());
}
......
......@@ -47,4 +47,13 @@
</condition-context>
</condition-contexts>
</assert>
<assert id="assertInsertBatch1" sql="INSERT INTO `order` o ('order_id', 'state') (SELECT 1, 'RUNNING' FROM dual UNION ALL SELECT 2, 'RUNNING' FROM dual )" expected-sql="INSERT INTO [Token(order)] o ('order_id', 'state') SELECT 1, 'RUNNING' FROM dual UNION ALL SELECT 2, 'RUNNING' FROM dual">
<tables>
<table name="order" alias="o" />
</tables>
<condition-contexts>
<condition-context/>
</condition-contexts>
</assert>
</asserts>
......@@ -15,6 +15,7 @@ weight = 1
### 功能提升
1. [ISSUE #66](https://github.com/dangdangdotcom/sharding-jdbc/issues/66) 在JDBC层的Statement增加对get/set MaxFieldSize,MaxRows和QueryTimeout的支持
1. [ISSUE #72](https://github.com/dangdangdotcom/sharding-jdbc/issues/72) 对于select union all形式的批量插入支持
### 缺陷修正
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册