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.
补充测试用例 alibaba#5847
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
core/src/test/java/com/alibaba/druid/bvt/sql/postgresql/issues/Issue5847.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,51 @@ | ||
package com.alibaba.druid.bvt.sql.postgresql.issues; | ||
|
||
import java.util.List; | ||
|
||
import com.alibaba.druid.DbType; | ||
import com.alibaba.druid.sql.SQLUtils; | ||
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.assertEquals; | ||
|
||
/** | ||
* 优化括号解析之后的sql验证 | ||
* | ||
* @author lizongbo | ||
* @see <a href="https://github.com/alibaba/druid/issues/5847">Issue来源</a> | ||
*/ | ||
public class Issue5847 { | ||
|
||
@Test | ||
public void test_parse() { | ||
for (String sql : new String[]{ | ||
"select * from tb_test limit 10 offset ( (2 - 1) * 1 );", | ||
}) { | ||
SQLStatementParser parser1 = SQLParserUtils.createSQLStatementParser(sql, DbType.postgresql); | ||
List<SQLStatement> statementList1 = parser1.parseStatementList(); | ||
System.out.println("原始的sql===" + sql); | ||
String sqleNew = statementList1.get(0).toString(); | ||
System.out.println("生成的sql===" + sqleNew); | ||
SQLStatementParser parser2 = SQLParserUtils.createSQLStatementParser(sqleNew, DbType.postgresql); | ||
List<SQLStatement> statementList2 = parser2.parseStatementList(); | ||
String sqleNew2 = statementList2.get(0).toString(); | ||
System.out.println("再次解析生成的sql===" + sqleNew); | ||
assertEquals(sqleNew, sqleNew2); | ||
|
||
assertEquals("SELECT *\n" | ||
+ "FROM tb_test\n" | ||
+ "LIMIT 10 OFFSET ((2 - 1) * 1);", sqleNew2); | ||
|
||
String formattedSql = SQLUtils.format(sql, DbType.dm); | ||
System.out.println(formattedSql); | ||
assertEquals("SELECT *\n" | ||
+ "FROM tb_test\n" | ||
+ "LIMIT 10 OFFSET ((2 - 1) * 1);", formattedSql); | ||
|
||
} | ||
} | ||
} |