forked from alibaba/druid
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化merge sql 输出逻辑,确保解析后输出顺序保持不变 alibaba#5631
优化merge sql 输出逻辑,确保解析后输出顺序保持不变 alibaba#5631
- Loading branch information
Showing
6 changed files
with
91 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
core/src/test/java/com/alibaba/druid/bvt/sql/oracle/issues/Issue5631.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.alibaba.druid.bvt.sql.oracle.issues; | ||
|
||
import com.alibaba.druid.DbType; | ||
import com.alibaba.druid.bvt.sql.mysql.issues.Issue5421; | ||
import com.alibaba.druid.sql.ast.SQLStatement; | ||
import com.alibaba.druid.sql.parser.SQLParserUtils; | ||
import com.alibaba.druid.sql.parser.SQLStatementParser; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* 验证 Oracle merge sql的顺序问题 | ||
* | ||
* @author lizongbo | ||
* @see <a href="https://github.com/alibaba/druid/issues/5631">Issue来源</a> | ||
*/ | ||
public class Issue5631 { | ||
|
||
@Test | ||
public void test_merge_into() throws Exception { | ||
for (DbType dbType : new DbType[]{DbType.oracle}) { | ||
for (String sql : new String[]{ | ||
"MERGE INTO target_table\n" | ||
+ "USING source_table ON (target_table.id = source_table.id)\n" | ||
+ "WHEN NOT MATCHED THEN INSERT (id, column1) VALUES (source_table.id, source_table.column1)\n" | ||
+ "WHEN MATCHED THEN UPDATE SET target_table.column1 = source_table.column1", | ||
"MERGE INTO target_table\n" | ||
+ "USING source_table ON (target_table.id = source_table.id)\n" | ||
+ "WHEN MATCHED THEN UPDATE SET target_table.column1 = source_table.column1\n" | ||
+ "WHEN NOT MATCHED THEN INSERT (id, column1) VALUES (source_table.id, source_table.column1)", | ||
}) { | ||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType); | ||
SQLStatement statement = parser.parseStatement(); | ||
System.out.println(dbType + "原始的sql===" + sql); | ||
System.out.println(dbType + "原始sql归一化===" + Issue5421.normalizeSql(sql)); | ||
String newSql = statement.toString(); | ||
System.out.println(dbType + "初次解析生成的sql===" + newSql); | ||
System.out.println(dbType + "初次解析生成的sql归一化===" + Issue5421.normalizeSql(newSql)); | ||
parser = SQLParserUtils.createSQLStatementParser(newSql, dbType); | ||
statement = parser.parseStatement(); | ||
System.out.println(dbType + "重新解析sql归一化===" + Issue5421.normalizeSql(statement.toString())); | ||
assertTrue(Issue5421.normalizeSql(sql).equalsIgnoreCase(Issue5421.normalizeSql(statement.toString()))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters