Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit605c1e6

Browse files
author
Dave Cramer
committed
cancel row updates sets values to null by Kris Jurka
1 parent06ec904 commit605c1e6

File tree

2 files changed

+74
-17
lines changed

2 files changed

+74
-17
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Copyright (c) 2003, PostgreSQL Global Development Group
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.27 2003/11/29 19:52:10 pgsql Exp $
12+
* $PostgreSQL: pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.28 2003/12/12 18:34:14 davec Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -519,7 +519,7 @@ public synchronized void cancelRowUpdates()
519519
{
520520
doingUpdates =false;
521521

522-
clearRowBuffer();
522+
clearRowBuffer(true);
523523
}
524524
}
525525

@@ -662,7 +662,7 @@ public synchronized void insertRow()
662662
this_row =rowBuffer;
663663

664664
// need to clear this in case of another insert
665-
clearRowBuffer();
665+
clearRowBuffer(false);
666666

667667

668668
}
@@ -707,20 +707,25 @@ public synchronized void moveToInsertRow()
707707

708708

709709
// make sure the underlying data is null
710-
clearRowBuffer();
710+
clearRowBuffer(false);
711711

712712
onInsertRow =true;
713713
doingUpdates =false;
714714

715715
}
716716

717717

718-
privatesynchronizedvoidclearRowBuffer()
718+
privatesynchronizedvoidclearRowBuffer(booleancopyCurrentRow)
719719
throwsSQLException
720720
{
721721
// rowBuffer is the temporary storage for the row
722722
rowBuffer =newbyte[fields.length][];
723723

724+
// inserts want an empty array while updates want a copy of the current row
725+
if (copyCurrentRow) {
726+
System.arraycopy(this_row,0,rowBuffer,0,this_row.length);
727+
}
728+
724729
// clear the updateValues hashTable for the next set of updates
725730
updateValues.clear();
726731

‎src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,79 @@
1515

1616
publicclassUpdateableResultTestextendsTestCase
1717
{
18+
privateConnectioncon;
1819

1920
publicUpdateableResultTest(Stringname )
2021
{
2122
super(name );
2223
}
2324

25+
protectedvoidsetUp()throwsException
26+
{
27+
con =TestUtil.openDB();
28+
TestUtil.createTable(con,"updateable","id int primary key, name text, notselected text");
29+
TestUtil.createTable(con,"second","id1 int primary key, name1 text");
30+
31+
// put some dummy data into second
32+
Statementst2 =con.createStatement();
33+
st2.execute("insert into second values (1,'anyvalue' )");
34+
st2.close();
35+
36+
}
37+
38+
protectedvoidtearDown()throwsException
39+
{
40+
TestUtil.dropTable(con,"updateable");
41+
TestUtil.dropTable(con,"second");
42+
TestUtil.closeDB(con);
43+
}
44+
45+
publicvoidtestCancelRowUpdates()throwsException
46+
{
47+
Statementst =con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE );
48+
ResultSetrs =st.executeQuery("select * from second");
49+
50+
// make sure we're dealing with the correct row.
51+
rs.first();
52+
assertEquals(1,rs.getInt(1));
53+
assertEquals("anyvalue",rs.getString(2));
54+
55+
// update, cancel and make sure nothings changed.
56+
rs.updateInt(1,99);
57+
rs.cancelRowUpdates();
58+
assertEquals(1,rs.getInt(1));
59+
assertEquals("anyvalue",rs.getString(2));
60+
61+
// real update
62+
rs.updateInt(1,999);
63+
rs.updateRow();
64+
assertEquals(999,rs.getInt(1));
65+
assertEquals("anyvalue",rs.getString(2));
66+
67+
// scroll some and make sure the update is still there
68+
rs.beforeFirst();
69+
rs.next();
70+
assertEquals(999,rs.getInt(1));
71+
assertEquals("anyvalue",rs.getString(2));
72+
73+
74+
// make sure the update got to the db and the driver isn't lying to us.
75+
rs.close();
76+
rs =st.executeQuery("select * from second");
77+
rs.first();
78+
assertEquals(999,rs.getInt(1));
79+
assertEquals("anyvalue",rs.getString(2));
80+
81+
rs.close();
82+
st.close();
83+
}
84+
85+
86+
2487
publicvoidtestUpdateable()
2588
{
2689
try
2790
{
28-
Connectioncon =TestUtil.openDB();
29-
TestUtil.createTable(con,"updateable","id int primary key, name text, notselected text");
30-
TestUtil.createTable(con,"second","id1 int primary key, name1 text");
31-
32-
// put some dummy data into second
33-
Statementst2 =con.createStatement();
34-
st2.execute("insert into second values (1,'anyvalue' )");
35-
st2.close();
36-
3791
Statementst =con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE );
3892
ResultSetrs =st.executeQuery("select * from updateable");
3993
assertNotNull(rs );
@@ -123,12 +177,10 @@ public void testUpdateable()
123177

124178
st.close();
125179

126-
TestUtil.dropTable(con,"updateable" );
127-
TestUtil.dropTable(con,"second" );
128-
TestUtil.closeDB(con );
129180
}
130181
catch (Exceptionex)
131182
{
183+
ex.printStackTrace();
132184
fail(ex.getMessage());
133185
}
134186
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp