|
| 1 | +/* |
| 2 | + * Copyright 1999-2017 Alibaba Group Holding Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.alibaba.druid.bvt.sql.oracle.select; |
| 17 | + |
| 18 | +import com.alibaba.druid.DbType; |
| 19 | +import com.alibaba.druid.sql.SQLUtils; |
| 20 | +import com.alibaba.druid.sql.ast.SQLStatement; |
| 21 | +import junit.framework.TestCase; |
| 22 | + |
| 23 | +public class OracleSelectTest_fetch_offset_row extends TestCase { |
| 24 | + public void test_fetch_offset_row() { |
| 25 | + assertFormatted( |
| 26 | + "SELECT * FROM t FETCH FIRST 1 ROW ONLY;", |
| 27 | + "SELECT *\nFROM t\nFETCH FIRST 1 ROWS ONLY;"); |
| 28 | + assertFormatted( |
| 29 | + "SELECT * FROM t FETCH FIRST 2 ROWS ONLY;", |
| 30 | + "SELECT *\nFROM t\nFETCH FIRST 2 ROWS ONLY;"); |
| 31 | + assertFormatted( |
| 32 | + "SELECT * FROM t OFFSET 1 ROW;", |
| 33 | + "SELECT *\nFROM t\nOFFSET 1 ROWS;"); |
| 34 | + assertFormatted( |
| 35 | + "SELECT * FROM t OFFSET 2 ROWS;", |
| 36 | + "SELECT *\nFROM t\nOFFSET 2 ROWS;"); |
| 37 | + assertFormatted( |
| 38 | + "SELECT * FROM t OFFSET 1 ROW FETCH NEXT 1 ROW ONLY;", |
| 39 | + "SELECT *\nFROM t\nOFFSET 1 ROWS FETCH FIRST 1 ROWS ONLY;"); |
| 40 | + } |
| 41 | + |
| 42 | + private void assertFormatted(String sql, String expected) { |
| 43 | + SQLStatement statement = SQLUtils.parseSingleStatement(sql, DbType.oracle); |
| 44 | + String formatted = SQLUtils.toSQLString(statement, DbType.oracle); |
| 45 | + |
| 46 | + assertEquals(expected, formatted); |
| 47 | + assertNotNull(SQLUtils.parseSingleStatement(formatted, DbType.oracle)); |
| 48 | + } |
| 49 | +} |
0 commit comments