Skip to content

Commit 5598cbf

Browse files
author
Dave Cramer
committed
Added test for newly implemented updateable result sets
1 parent 603c46d commit 5598cbf

File tree

2 files changed

+142
-3
lines changed

2 files changed

+142
-3
lines changed

src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@ public class JDBC2Tests extends TestSuite
1616
*/
1717
public static String getURL()
1818
{
19-
return System.getProperty("database");
19+
//return System.getProperty("database");
20+
return "test";
2021
}
2122

2223
/*
2324
* Returns the Postgresql username
2425
*/
2526
public static String getUser()
2627
{
27-
return System.getProperty("username");
28+
return "davec";
29+
//return System.getProperty("username");
2830
}
2931

3032
/*
3133
* Returns the user's password
3234
*/
3335
public static String getPassword()
3436
{
35-
return System.getProperty("password");
37+
return null;
38+
//return System.getProperty("password");
3639
}
3740

3841
/*
@@ -226,6 +229,7 @@ public static TestSuite suite()
226229

227230
// Fastpath/LargeObject
228231
suite.addTestSuite(BlobTest.class);
232+
suite.addTestSuite( UpdateableResultTest.class );
229233

230234
// That's all folks
231235
return suite;
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package org.postgresql.test.jdbc2;
2+
3+
import java.sql.*;
4+
import junit.framework.TestCase;
5+
6+
import org.postgresql.test.JDBC2Tests;
7+
/**
8+
* <p>Title: </p>
9+
* <p>Description: </p>
10+
* <p>Copyright: Copyright (c) 2001</p>
11+
* <p>Company: </p>
12+
* @author unascribed
13+
* @version 1.0
14+
*/
15+
16+
public class UpdateableResultTest extends TestCase
17+
{
18+
19+
public UpdateableResultTest( String name )
20+
{
21+
super( name );
22+
}
23+
24+
public void testUpdateable()
25+
{
26+
try
27+
{
28+
Connection con = JDBC2Tests.openDB();
29+
JDBC2Tests.createTable(con, "updateable","id int primary key, name text, notselected text");
30+
JDBC2Tests.createTable(con, "second","id1 int primary key, name1 text");
31+
32+
Statement st1 = con.createStatement();
33+
boolean retVal = st1.execute( "insert into updateable ( id, name, notselected ) values (1, 'jake', 'avalue')" );
34+
assert( retVal== false );
35+
36+
retVal = st1.execute( "insert into second (id1, name1) values (1, 'jake')" );
37+
assertTrue( !retVal );
38+
st1.close();
39+
40+
Statement st = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
41+
ResultSet rs = st.executeQuery( "select id, name, notselected from updateable" );
42+
43+
assertNotNull(rs);
44+
45+
while (rs.next())
46+
{
47+
rs.updateInt( "id",2 );
48+
rs.updateString( "name","dave" );
49+
rs.updateRow();
50+
assertTrue( rs.getInt("id") == 2 );
51+
assertTrue( rs.getString("name").equals("dave"));
52+
assertTrue( rs.getString("notselected").equals("avalue") );
53+
54+
rs.deleteRow();
55+
rs.moveToInsertRow();
56+
rs.updateInt("id",3);
57+
rs.updateString("name", "paul");
58+
59+
rs.insertRow();
60+
61+
assertTrue( rs.getInt("id") == 3 );
62+
assertTrue( rs.getString("name").equals("paul"));
63+
assertTrue( rs.getString("notselected") == null );
64+
65+
}
66+
67+
rs.close();
68+
69+
rs = st.executeQuery("select id1, id, name, name1 from updateable, second" );
70+
try
71+
{
72+
while( rs.next() )
73+
{
74+
rs.updateInt( "id",2 );
75+
rs.updateString( "name","dave" );
76+
rs.updateRow();
77+
}
78+
79+
80+
assertTrue( "should not get here, update should fail", false );
81+
}
82+
catch (SQLException ex){}
83+
84+
try
85+
{
86+
rs = st.executeQuery("select oid,* from updateable");
87+
if ( rs.first() )
88+
{
89+
rs.updateInt( "id", 3 );
90+
rs.updateString( "name", "dave3");
91+
rs.updateRow();
92+
assertTrue(rs.getInt("id") == 3 );
93+
assertTrue(rs.getString("name").equals("dave3"));
94+
95+
rs.moveToInsertRow();
96+
rs.updateInt( "id", 4 );
97+
rs.updateString( "name", "dave4" );
98+
99+
rs.insertRow();
100+
rs.updateInt("id", 5 );
101+
rs.updateString( "name", "dave5" );
102+
rs.insertRow();
103+
104+
rs.moveToCurrentRow();
105+
assertTrue(rs.getInt("id") == 3 );
106+
assertTrue(rs.getString("name").equals("dave3"));
107+
108+
assertTrue( rs.next() );
109+
assertTrue(rs.getInt("id") == 4 );
110+
assertTrue(rs.getString("name").equals("dave4"));
111+
112+
assertTrue( rs.next() );
113+
assertTrue(rs.getInt("id") == 5 );
114+
assertTrue(rs.getString("name").equals("dave5"));
115+
116+
}
117+
}
118+
catch(SQLException ex)
119+
{
120+
fail(ex.getMessage());
121+
}
122+
123+
st.close();
124+
125+
JDBC2Tests.dropTable( con,"updateable" );
126+
JDBC2Tests.closeDB( con );
127+
}
128+
catch (Exception ex)
129+
{
130+
fail(ex.getMessage());
131+
}
132+
}
133+
134+
135+
}

0 commit comments

Comments
 (0)