Skip to content

Commit

Permalink
support "select union all"'s batch insert fix #71
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoht committed May 13, 2016
1 parent f63eaa0 commit 228a2b6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public final boolean visit(final SQLVariantRefExpr x) {

@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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 1 addition & 0 deletions sharding-jdbc-doc/content/post/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 #71](https://github.com/dangdangdotcom/sharding-jdbc/issues/71) 对于select union all形式的批量插入支持

### 缺陷修正

Expand Down

0 comments on commit 228a2b6

Please sign in to comment.