? src/interfaces/jdbc/org/postgresql/copy ? src/interfaces/jdbc/org/postgresql/jdbc2/.AbstractJdbc2ResultSet.java.swp ? src/interfaces/jdbc/org/postgresql/test/jdbc2/.UpdateableResultTest.java.swp ? src/interfaces/jdbc/org/postgresql/test/jdbc2/CopyTest.notjava ? src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetMetaDataTest.java Index: src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v retrieving revision 1.27 diff -c -r1.27 AbstractJdbc2ResultSet.java *** src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java 29 Nov 2003 19:52:10 -0000 1.27 --- src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java 11 Dec 2003 22:26:02 -0000 *************** *** 519,525 **** { doingUpdates = false; ! clearRowBuffer(); } } --- 519,525 ---- { doingUpdates = false; ! clearRowBuffer(true); } } *************** *** 662,668 **** this_row = rowBuffer; // need to clear this in case of another insert ! clearRowBuffer(); } --- 662,668 ---- this_row = rowBuffer; // need to clear this in case of another insert ! clearRowBuffer(false); } *************** *** 707,713 **** // make sure the underlying data is null ! clearRowBuffer(); onInsertRow = true; doingUpdates = false; --- 707,713 ---- // make sure the underlying data is null ! clearRowBuffer(false); onInsertRow = true; doingUpdates = false; *************** *** 715,725 **** } ! private synchronized void clearRowBuffer() throws SQLException { // rowBuffer is the temporary storage for the row rowBuffer = new byte[fields.length][]; // clear the updateValues hashTable for the next set of updates updateValues.clear(); --- 715,730 ---- } ! private synchronized void clearRowBuffer(boolean copyCurrentRow) throws SQLException { // rowBuffer is the temporary storage for the row rowBuffer = new byte[fields.length][]; + + // inserts want an empty array while updates want a copy of the current row + if (copyCurrentRow) { + System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length); + } // clear the updateValues hashTable for the next set of updates updateValues.clear(); Index: src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java,v retrieving revision 1.7 diff -c -r1.7 UpdateableResultTest.java *** src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java 11 Sep 2002 05:38:45 -0000 1.7 --- src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java 11 Dec 2003 22:26:02 -0000 *************** *** 15,39 **** public class UpdateableResultTest extends TestCase { public UpdateableResultTest( String name ) { super( name ); } public void testUpdateable() { try { - Connection con = TestUtil.openDB(); - TestUtil.createTable(con, "updateable", "id int primary key, name text, notselected text"); - TestUtil.createTable(con, "second", "id1 int primary key, name1 text"); - - // put some dummy data into second - Statement st2 = con.createStatement(); - st2.execute( "insert into second values (1,'anyvalue' )"); - st2.close(); - Statement st = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE ); ResultSet rs = st.executeQuery( "select * from updateable"); assertNotNull( rs ); --- 15,93 ---- public class UpdateableResultTest extends TestCase { + private Connection con; public UpdateableResultTest( String name ) { super( name ); } + protected void setUp() throws Exception + { + con = TestUtil.openDB(); + TestUtil.createTable(con, "updateable", "id int primary key, name text, notselected text"); + TestUtil.createTable(con, "second", "id1 int primary key, name1 text"); + + // put some dummy data into second + Statement st2 = con.createStatement(); + st2.execute( "insert into second values (1,'anyvalue' )"); + st2.close(); + + } + + protected void tearDown() throws Exception + { + TestUtil.dropTable(con, "updateable"); + TestUtil.dropTable(con, "second"); + TestUtil.closeDB(con); + } + + public void testCancelRowUpdates() throws Exception + { + Statement st = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE ); + ResultSet rs = st.executeQuery( "select * from second"); + + // make sure we're dealing with the correct row. + rs.first(); + assertEquals(1,rs.getInt(1)); + assertEquals("anyvalue",rs.getString(2)); + + // update, cancel and make sure nothings changed. + rs.updateInt(1,99); + rs.cancelRowUpdates(); + assertEquals(1,rs.getInt(1)); + assertEquals("anyvalue",rs.getString(2)); + + // real update + rs.updateInt(1,999); + rs.updateRow(); + assertEquals(999,rs.getInt(1)); + assertEquals("anyvalue",rs.getString(2)); + + // scroll some and make sure the update is still there + rs.beforeFirst(); + rs.next(); + assertEquals(999,rs.getInt(1)); + assertEquals("anyvalue",rs.getString(2)); + + + // make sure the update got to the db and the driver isn't lying to us. + rs.close(); + rs = st.executeQuery( "select * from second"); + rs.first(); + assertEquals(999,rs.getInt(1)); + assertEquals("anyvalue",rs.getString(2)); + + rs.close(); + st.close(); + } + + + public void testUpdateable() { try { Statement st = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE ); ResultSet rs = st.executeQuery( "select * from updateable"); assertNotNull( rs ); *************** *** 123,134 **** st.close(); - TestUtil.dropTable( con, "updateable" ); - TestUtil.dropTable( con, "second" ); - TestUtil.closeDB( con ); } catch (Exception ex) { fail(ex.getMessage()); } } --- 177,186 ---- st.close(); } catch (Exception ex) { + ex.printStackTrace(); fail(ex.getMessage()); } }