mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add sql parser testcases
This commit is contained in:
@@ -288,9 +288,14 @@ public class SQLSelectParser extends SQLParser {
|
||||
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("ROLLUP");
|
||||
|
||||
groupBy.setWithRollUp(true);
|
||||
|
||||
if (identifierEquals("CUBE")) {
|
||||
lexer.nextToken();
|
||||
groupBy.setWithCube(true);
|
||||
} else {
|
||||
acceptIdentifier("ROLLUP");
|
||||
groupBy.setWithRollUp(true);
|
||||
}
|
||||
}
|
||||
|
||||
queryBlock.setGroupBy(groupBy);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.db2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.DB2Test;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class DB2SelectTest_6 extends DB2Test {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "SELECT all id FROM DSN81010.EMP;";
|
||||
|
||||
DB2StatementParser parser = new DB2StatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
Assert.assertEquals(1, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("DSN81010.EMP")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "last_name")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
|
||||
|
||||
Assert.assertEquals("SELECT ALL id" //
|
||||
+ "\nFROM DSN81010.EMP", //
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
|
||||
Assert.assertEquals("select all id" //
|
||||
+ "\nfrom DSN81010.EMP", //
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.db2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.DB2Test;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class DB2SelectTest_7 extends DB2Test {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "SELECT distinct id FROM DSN81010.EMP;";
|
||||
|
||||
DB2StatementParser parser = new DB2StatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
Assert.assertEquals(1, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("DSN81010.EMP")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "last_name")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
|
||||
|
||||
Assert.assertEquals("SELECT DISTINCT id" //
|
||||
+ "\nFROM DSN81010.EMP", //
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
|
||||
Assert.assertEquals("select distinct id" //
|
||||
+ "\nfrom DSN81010.EMP", //
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.db2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.DB2Test;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class DB2SelectTest_8 extends DB2Test {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "SELECT unique id FROM DSN81010.EMP where id = 1;";
|
||||
|
||||
DB2StatementParser parser = new DB2StatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
Assert.assertEquals(1, visitor.getColumns().size());
|
||||
Assert.assertEquals(1, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("DSN81010.EMP")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "last_name")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
|
||||
|
||||
Assert.assertEquals("SELECT UNIQUE id" //
|
||||
+ "\nFROM DSN81010.EMP"
|
||||
+ "\nWHERE id = 1", //
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
|
||||
Assert.assertEquals("select unique id" //
|
||||
+ "\nfrom DSN81010.EMP"
|
||||
+ "\nwhere id = 1", //
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,15 @@ package com.alibaba.druid.bvt.sql.mysql;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class SELECT_Syntax_Test extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
@@ -33,9 +35,10 @@ public class SELECT_Syntax_Test extends TestCase {
|
||||
SQLStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
|
||||
String text = output(stmtList);
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals("SELECT year, SUM(profit)\nFROM sales\nGROUP BY year WITH ROLLUP;", text);
|
||||
Assert.assertEquals("SELECT year, SUM(profit)\nFROM sales\nGROUP BY year WITH ROLLUP", SQLUtils.toMySqlString(stmt));
|
||||
Assert.assertEquals("select year, sum(profit)\nfrom sales\ngroup by year with rollup", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
@@ -48,6 +51,18 @@ public class SELECT_Syntax_Test extends TestCase {
|
||||
|
||||
Assert.assertEquals("SELECT *\nFROM T\nFOR UPDATE;", text);
|
||||
}
|
||||
|
||||
public void test_with_cube() throws Exception {
|
||||
String sql = "SELECT year, SUM(profit) FROM sales GROUP BY year WITH CUBE;";
|
||||
|
||||
SQLStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals("SELECT year, SUM(profit)\nFROM sales\nGROUP BY year WITH CUBE", SQLUtils.toMySqlString(stmt));
|
||||
Assert.assertEquals("select year, sum(profit)\nfrom sales\ngroup by year with cube", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
String sql = "SELECT * FROM T LOCK IN SHARE MODE;";
|
||||
@@ -177,10 +192,43 @@ public class SELECT_Syntax_Test extends TestCase {
|
||||
|
||||
SQLStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
String text = output(stmtList);
|
||||
Assert.assertEquals("SELECT s1\nFROM t1\nWHERE s1 NOT IN (SELECT s1\n\tFROM t2)", SQLUtils.toMySqlString(stmt));
|
||||
Assert.assertEquals("select s1\nfrom t1\nwhere s1 not in (select s1\n\tfrom t2)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
public void test_13() throws Exception {
|
||||
String sql = "SELECT s1 FROM t1 WHERE s1 IN (SELECT s1 FROM t2);";
|
||||
|
||||
Assert.assertEquals("SELECT s1\nFROM t1\nWHERE s1 NOT IN (SELECT s1\n\tFROM t2);", text);
|
||||
SQLStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals("SELECT s1\nFROM t1\nWHERE s1 IN (SELECT s1\n\tFROM t2)", SQLUtils.toMySqlString(stmt));
|
||||
Assert.assertEquals("select s1\nfrom t1\nwhere s1 in (select s1\n\tfrom t2)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
public void test_14() throws Exception {
|
||||
String sql = "SELECT s1 FROM t1 WHERE s1 IN (?, ?, ?);";
|
||||
|
||||
SQLStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals("SELECT s1\nFROM t1\nWHERE s1 IN (?, ?, ?)", SQLUtils.toMySqlString(stmt));
|
||||
Assert.assertEquals("select s1\nfrom t1\nwhere s1 in (?, ?, ?)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
public void test_15() throws Exception {
|
||||
String sql = "SELECT s1 FROM t1 WHERE s1 NOT IN (?, ?, ?);";
|
||||
|
||||
SQLStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals("SELECT s1\nFROM t1\nWHERE s1 NOT IN (?, ?, ?)", SQLUtils.toMySqlString(stmt));
|
||||
Assert.assertEquals("select s1\nfrom t1\nwhere s1 not in (?, ?, ?)", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
private String output(List<SQLStatement> stmtList) {
|
||||
|
||||
@@ -35,13 +35,13 @@ public class OracleSelectTest27 extends OracleTest {
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
@@ -38,8 +39,29 @@ public class OracleSelectTest37 extends OracleTest {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals("SELECT resource_value, COUNT(resource_value) AS nums, http_method"
|
||||
+ "\nFROM ("
|
||||
+ "\n\tSELECT *"
|
||||
+ "\n\tFROM audit_url_log"
|
||||
+ "\n\tWHERE project_id = ?"
|
||||
+ "\n\t\tAND to_char(begin_time, 'yyyy-MM-dd') >= ?"
|
||||
+ "\n\t\tAND to_char(begin_time, 'yyyy-MM-dd') <= ?"
|
||||
+ "\n)"
|
||||
+ "\nGROUP BY resource_value, http_method"
|
||||
+ "\nHAVING COUNT(resource_value) >= ?", SQLUtils.toOracleString(stmt));
|
||||
|
||||
Assert.assertEquals("select resource_value, count(resource_value) as nums, http_method"
|
||||
+ "\nfrom ("
|
||||
+ "\n\tselect *"
|
||||
+ "\n\tfrom audit_url_log"
|
||||
+ "\n\twhere project_id = ?"
|
||||
+ "\n\t\tand to_char(begin_time, 'yyyy-MM-dd') >= ?"
|
||||
+ "\n\t\tand to_char(begin_time, 'yyyy-MM-dd') <= ?"
|
||||
+ "\n)"
|
||||
+ "\ngroup by resource_value, http_method"
|
||||
+ "\nhaving count(resource_value) >= ?", SQLUtils.toOracleString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
|
||||
@@ -36,13 +36,13 @@ public class OracleSelectTest7 extends OracleTest {
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import org.junit.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class SQLServerRowNumberTest2 extends TestCase {
|
||||
|
||||
@@ -34,20 +35,49 @@ public class SQLServerRowNumberTest2 extends TestCase {
|
||||
" ) AS temp_table" + //
|
||||
" WHERE RowNumber BETWEEN ? AND ?";
|
||||
|
||||
String expect = "SELECT *" +
|
||||
"\nFROM (SELECT ROW_NUMBER() OVER (ORDER BY FAlertDate DESC, FAlertLevel, FAlertType) AS RowNumber, *" +
|
||||
"\n\tFROM monitor_business" +
|
||||
"\n\tWHERE FRemoveAlert = ?" +
|
||||
"\n\t) temp_table" +
|
||||
"\nWHERE RowNumber BETWEEN ? AND ?";
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
Assert.assertEquals("SELECT *" +
|
||||
"\nFROM (SELECT ROW_NUMBER() OVER (ORDER BY FAlertDate DESC, FAlertLevel, FAlertType) AS RowNumber, *" +
|
||||
"\n\tFROM monitor_business" +
|
||||
"\n\tWHERE FRemoveAlert = ?" +
|
||||
"\n\t) temp_table" +
|
||||
"\nWHERE RowNumber BETWEEN ? AND ?", SQLUtils.toSQLServerString(stmt));
|
||||
|
||||
Assert.assertEquals("select *" +
|
||||
"\nfrom (select row_number() over (order by FAlertDate desc, FAlertLevel, FAlertType) as RowNumber, *" +
|
||||
"\n\tfrom monitor_business" +
|
||||
"\n\twhere FRemoveAlert = ?" +
|
||||
"\n\t) temp_table" +
|
||||
"\nwhere RowNumber between ? and ?", SQLUtils.toSQLServerString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
|
||||
public void test_isEmpty_2() throws Exception {
|
||||
String sql = "SELECT * FROM ("
|
||||
+ //
|
||||
" SELECT ROW_NUMBER() OVER (ORDER BY FAlertDate Desc, FAlertLevel, FAlertType) AS RowNumber, *"
|
||||
+ //
|
||||
" from monitor_business" + //
|
||||
" where FRemoveAlert = ?" + //
|
||||
" ) AS temp_table" + //
|
||||
" WHERE RowNumber NOT BETWEEN ? AND ?";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.outputSqlServer(stmt);
|
||||
Assert.assertEquals("SELECT *" +
|
||||
"\nFROM (SELECT ROW_NUMBER() OVER (ORDER BY FAlertDate DESC, FAlertLevel, FAlertType) AS RowNumber, *" +
|
||||
"\n\tFROM monitor_business" +
|
||||
"\n\tWHERE FRemoveAlert = ?" +
|
||||
"\n\t) temp_table" +
|
||||
"\nWHERE RowNumber NOT BETWEEN ? AND ?", SQLUtils.toSQLServerString(stmt));
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
System.out.println(text);
|
||||
Assert.assertEquals("select *" +
|
||||
"\nfrom (select row_number() over (order by FAlertDate desc, FAlertLevel, FAlertType) as RowNumber, *" +
|
||||
"\n\tfrom monitor_business" +
|
||||
"\n\twhere FRemoveAlert = ?" +
|
||||
"\n\t) temp_table" +
|
||||
"\nwhere RowNumber not between ? and ?", SQLUtils.toSQLServerString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SQLServerSelectTest13 extends TestCase {
|
||||
" AND a.time_add <= ? " + //
|
||||
" ) a " + //
|
||||
"WHERE " + //
|
||||
" a. ROW BETWEEN (?+ 1) " + //
|
||||
" a. ROW NOT BETWEEN (?+ 1) " + //
|
||||
"AND (?+?)"; //
|
||||
|
||||
String expect = "SELECT a.*" +
|
||||
@@ -81,7 +81,7 @@ public class SQLServerSelectTest13 extends TestCase {
|
||||
"\n\t\tAND a.time_add >= ?" +
|
||||
"\n\t\tAND a.time_add <= ?" +
|
||||
"\n\t) a" +
|
||||
"\nWHERE a.ROW BETWEEN ? + 1 AND ? + ?";
|
||||
"\nWHERE a.ROW NOT BETWEEN ? + 1 AND ? + ?";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
Reference in New Issue
Block a user