*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ---------------
* TestScrollable.java
* ---------------
* Author: Volker Berlin
*
* Created on 14.08.2004
*/
package smallsql.junit;
import java.sql.*;
public class TestScrollable extends BasicTestCase {
public void testLastWithWhere() throws Exception{
Connection con = AllTests.getConnection();
try{
con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
assertRowCount( 0, "Select * from Scrollable");
con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')");
assertRowCount( 1, "Select * from Scrollable");
assertRowCount( 0, "Select * from Scrollable Where 1=0");
ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
.executeQuery("Select * from Scrollable Where 1=0");
assertFalse("There should be no rows:", rs.last());
try{
rs.getString("v");
fail("SQLException 'No current row' should be throw");
}catch(SQLException e){
}
}finally{
try{
con.createStatement().execute("Drop Table Scrollable");
}catch(Throwable e){}
}
}
public void testNextWithWhere() throws Exception{
Connection con = AllTests.getConnection();
try{
con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
assertRowCount( 0, "Select * from Scrollable");
con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')");
assertRowCount( 1, "Select * from Scrollable");
assertRowCount( 0, "Select * from Scrollable Where 1=0");
ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
.executeQuery("Select * from Scrollable Where 1=0");
assertFalse("There should be no rows:", rs.next());
try{
rs.getString("v");
fail("SQLException 'No current row' should be throw");
}catch(SQLException e){
}
}finally{
try{
con.createStatement().execute("Drop Table Scrollable");
}catch(Throwable e){}
}
}
public void testFirstWithWhere() throws Exception{
Connection con = AllTests.getConnection();
try{
con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
assertRowCount( 0, "Select * from Scrollable");
con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')");
assertRowCount( 1, "Select * from Scrollable");
assertRowCount( 0, "Select * from Scrollable Where 1=0");
ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
.executeQuery("Select * from Scrollable Where 1=0");
assertFalse("There should be no rows:", rs.first());
try{
rs.getString("v");
fail("SQLException 'No current row' should be throw");
}catch(SQLException e){
}
}finally{
try{
con.createStatement().execute("Drop Table Scrollable");
}catch(Throwable e){}
}
}
public void testPreviousWithWhere() throws Exception{
Connection con = AllTests.getConnection();
try{
con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
assertRowCount( 0, "Select * from Scrollable");
con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')");
assertRowCount( 1, "Select * from Scrollable");
assertRowCount( 0, "Select * from Scrollable Where 1=0");
ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
.executeQuery("Select * from Scrollable Where 1=0");
rs.afterLast();
assertFalse("There should be no rows:", rs.previous());
try{
rs.getString("v");
fail("SQLException 'No current row' should be throw");
}catch(SQLException e){
}
}finally{
try{
con.createStatement().execute("Drop Table Scrollable");
}catch(Throwable e){}
}
}
public void testAbsolute() throws Exception{
Connection con = AllTests.getConnection();
try{
con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
assertRowCount( 0, "Select * from Scrollable");
con.createStatement().execute("Insert Into Scrollable(v) Values('qwert1')");
con.createStatement().execute("Insert Into Scrollable(v) Values('qwert2')");
con.createStatement().execute("Insert Into Scrollable(v) Values('qwert3')");
ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
.executeQuery("Select * from Scrollable");
assertTrue(rs.absolute(2));
assertEquals("qwert2", rs.getString("v"));
assertTrue(rs.absolute(1));
assertEquals("qwert1", rs.getString("v"));
assertTrue(rs.absolute(-1));
assertEquals("qwert3", rs.getString("v"));
assertFalse(rs.absolute(4));
}finally{
try{
con.createStatement().execute("Drop Table Scrollable");
}catch(Throwable e){}
}
}
}