1 34 package smallsql.junit; 35 36 import java.sql.*; 37 38 41 public class TestScrollable extends BasicTestCase { 42 43 public void testLastWithWhere() throws Exception { 44 Connection con = AllTests.getConnection(); 45 try{ 46 con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))"); 47 assertRowCount( 0, "Select * from Scrollable"); 48 49 con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')"); 50 assertRowCount( 1, "Select * from Scrollable"); 51 assertRowCount( 0, "Select * from Scrollable Where 1=0"); 52 53 ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE) 54 .executeQuery("Select * from Scrollable Where 1=0"); 55 56 assertFalse("There should be no rows:", rs.last()); 57 try{ 58 rs.getString("v"); 59 fail("SQLException 'No current row' should be throw"); 60 }catch(SQLException e){ 61 } 63 }finally{ 64 dropTable( con, "Scrollable"); 65 } 66 } 67 68 69 public void testNextWithWhere() throws Exception { 70 Connection con = AllTests.getConnection(); 71 try{ 72 con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))"); 73 assertRowCount( 0, "Select * from Scrollable"); 74 75 con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')"); 76 assertRowCount( 1, "Select * from Scrollable"); 77 assertRowCount( 0, "Select * from Scrollable Where 1=0"); 78 79 ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE) 80 .executeQuery("Select * from Scrollable Where 1=0"); 81 82 assertFalse("There should be no rows:", rs.next()); 83 try{ 84 rs.getString("v"); 85 fail("SQLException 'No current row' should be throw"); 86 }catch(SQLException e){ 87 } 89 }finally{ 90 dropTable( con, "Scrollable"); 91 } 92 } 93 94 95 public void testFirstWithWhere() throws Exception { 96 Connection con = AllTests.getConnection(); 97 try{ 98 con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))"); 99 assertRowCount( 0, "Select * from Scrollable"); 100 101 con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')"); 102 assertRowCount( 1, "Select * from Scrollable"); 103 assertRowCount( 0, "Select * from Scrollable Where 1=0"); 104 105 ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE) 106 .executeQuery("Select * from Scrollable Where 1=0"); 107 108 assertFalse("There should be no rows:", rs.first()); 109 try{ 110 rs.getString("v"); 111 fail("SQLException 'No current row' should be throw"); 112 }catch(SQLException e){ 113 } 115 }finally{ 116 dropTable( con, "Scrollable"); 117 } 118 } 119 120 121 public void testPreviousWithWhere() throws Exception { 122 Connection con = AllTests.getConnection(); 123 try{ 124 con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))"); 125 assertRowCount( 0, "Select * from Scrollable"); 126 127 con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')"); 128 assertRowCount( 1, "Select * from Scrollable"); 129 assertRowCount( 0, "Select * from Scrollable Where 1=0"); 130 131 ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE) 132 .executeQuery("Select * from Scrollable Where 1=0"); 133 134 rs.afterLast(); 135 assertFalse("There should be no rows:", rs.previous()); 136 try{ 137 rs.getString("v"); 138 fail("SQLException 'No current row' should be throw"); 139 }catch(SQLException e){ 140 } 142 }finally{ 143 dropTable( con, "Scrollable"); 144 } 145 } 146 147 148 public void testAbsolute() throws Exception { 149 Connection con = AllTests.getConnection(); 150 try{ 151 con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))"); 152 assertRowCount( 0, "Select * from Scrollable"); 153 154 con.createStatement().execute("Insert Into Scrollable(v) Values('qwert1')"); 155 con.createStatement().execute("Insert Into Scrollable(v) Values('qwert2')"); 156 con.createStatement().execute("Insert Into Scrollable(v) Values('qwert3')"); 157 158 ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE) 159 .executeQuery("Select * from Scrollable"); 160 161 assertTrue(rs.absolute(2)); 162 assertEquals("qwert2", rs.getString("v")); 163 164 assertTrue(rs.absolute(1)); 165 assertEquals("qwert1", rs.getString("v")); 166 167 assertTrue(rs.absolute(-1)); 168 assertEquals("qwert3", rs.getString("v")); 169 170 assertFalse(rs.absolute(4)); 171 }finally{ 172 dropTable( con, "Scrollable"); 173 } 174 } 175 176 177 } 178 | Popular Tags |