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

Commit8839b85

Browse files
author
Barry Lind
committed
Additional jdbc regression tests submitted by Oliver Jowett. Some tests are
currently commented out, pending fixes for the bugs these tests uncovered. Modified Files: jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java jdbc/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java Added Files: jdbc/org/postgresql/test/jdbc2/CursorFetchTest.java
1 parent66d0041 commit8839b85

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
packageorg.postgresql.test.jdbc2;
2+
3+
importjava.sql.*;
4+
5+
importjunit.framework.TestCase;
6+
7+
importorg.postgresql.test.TestUtil;
8+
9+
/*
10+
* Tests for using non-zero setFetchSize().
11+
*/
12+
publicclassCursorFetchTestextendsTestCase
13+
{
14+
privateConnectioncon;
15+
16+
publicCursorFetchTest(Stringname)
17+
{
18+
super(name);
19+
}
20+
21+
protectedvoidsetUp()throwsException
22+
{
23+
con =TestUtil.openDB();
24+
TestUtil.createTable(con,"test_fetch","value integer");
25+
con.setAutoCommit(false);
26+
}
27+
28+
protectedvoidtearDown()throwsException
29+
{
30+
con.rollback();
31+
con.setAutoCommit(true);
32+
TestUtil.dropTable(con,"test_fetch");
33+
TestUtil.closeDB(con);
34+
}
35+
36+
protectedvoidcreateRows(intcount)throwsException
37+
{
38+
PreparedStatementstmt =con.prepareStatement("insert into test_fetch(value) values(?)");
39+
for (inti =0;i <count; ++i) {
40+
stmt.setInt(1,i);
41+
stmt.executeUpdate();
42+
}
43+
}
44+
45+
// Test various fetchsizes.
46+
publicvoidtestBasicFetch()throwsException
47+
{
48+
createRows(100);
49+
50+
PreparedStatementstmt =con.prepareStatement("select * from test_fetch order by value");
51+
int[]testSizes = {0,1,49,50,51,99,100,101 };
52+
for (inti =0;i <testSizes.length; ++i) {
53+
stmt.setFetchSize(testSizes[i]);
54+
ResultSetrs =stmt.executeQuery();
55+
56+
intcount =0;
57+
while (rs.next()) {
58+
assertEquals("query value error with fetch size " +testSizes[i],count,rs.getInt(1));
59+
++count;
60+
}
61+
62+
assertEquals("total query size error with fetch size " +testSizes[i],100,count);
63+
}
64+
}
65+
66+
// Test odd queries that should not be transformed into cursor-based fetches.
67+
publicvoidTODO_FAILS_testInsert()throwsException
68+
{
69+
// INSERT should not be transformed.
70+
PreparedStatementstmt =con.prepareStatement("insert into test_fetch(value) values(1)");
71+
stmt.setFetchSize(100);// Should be meaningless.
72+
stmt.executeUpdate();
73+
}
74+
75+
publicvoidTODO_FAILS_testMultistatement()throwsException
76+
{
77+
// Queries with multiple statements should not be transformed.
78+
79+
createRows(100);// 0 .. 99
80+
PreparedStatementstmt =con.prepareStatement("insert into test_fetch(value) values(100); select * from test_fetch order by value");
81+
stmt.setFetchSize(10);
82+
ResultSetrs =stmt.executeQuery();
83+
84+
intcount =0;
85+
while (rs.next()) {
86+
assertEquals(count,rs.getInt(1));
87+
++count;
88+
}
89+
90+
assertEquals(101,count);
91+
}
92+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static TestSuite suite()
6161
suite.addTestSuite(UpdateableResultTest.class );
6262

6363
suite.addTestSuite(CallableStmtTest.class );
64+
suite.addTestSuite(CursorFetchTest.class);
6465

6566
// That's all folks
6667
returnsuite;

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,37 @@ public void testBytea() throws Exception
229229
TestUtil.dropTable(con,"testsps_bytea");
230230
}
231231
}
232+
233+
// Check statements are not transformed when they shouldn't be.
234+
publicvoidTODO_FAILS_testCreateTable()throwsException {
235+
// CREATE TABLE isn't supported by PREPARE; the driver should realize this and
236+
// still complete without error.
237+
PreparedStatementpstmt =con.prepareStatement("CREATE TABLE testsps_bad(data int)");
238+
((PGStatement)pstmt).setUseServerPrepare(true);
239+
pstmt.executeUpdate();
240+
TestUtil.dropTable(con,"testsps_bad");
241+
}
242+
243+
publicvoidTODO_FAILS_testMultistatement()throwsException {
244+
// Shouldn't try to PREPARE this one, if we do we get:
245+
// PREPARE x(int,int) AS INSERT .... $1 ; INSERT ... $2 -- syntax error
246+
try {
247+
TestUtil.createTable(con,"testsps_multiple","data int");
248+
PreparedStatementpstmt =con.prepareStatement("INSERT INTO testsps_multiple(data) VALUES (?); INSERT INTO testsps_multiple(data) VALUES (?)");
249+
((PGStatement)pstmt).setUseServerPrepare(true);
250+
pstmt.setInt(1,1);
251+
pstmt.setInt(2,2);
252+
pstmt.executeUpdate();// Two inserts.
253+
254+
pstmt.setInt(1,3);
255+
pstmt.setInt(2,4);
256+
pstmt.executeUpdate();// Two more inserts.
257+
258+
ResultSetcheck =con.createStatement().executeQuery("SELECT COUNT(*) FROM testsps_multiple");
259+
assertTrue(check.next());
260+
assertEquals(4,check.getInt(1));
261+
}finally {
262+
TestUtil.dropTable(con,"testsps_multiple");
263+
}
264+
}
232265
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp