01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.server;
07:
08: import java.sql.Connection;
09: import java.sql.ResultSet;
10: import java.sql.SQLException;
11: import java.sql.Statement;
12:
13: import org.h2.test.TestBase;
14:
15: /**
16: * Tests remote JDBC access with nested loops.
17: * This is not allowed in some databases.
18: */
19: public class TestNestedLoop extends TestBase {
20:
21: public void test() throws Exception {
22: deleteDb("nestedLoop");
23: Connection conn = getConnection("nestedLoop");
24: Statement stat = conn.createStatement();
25: stat
26: .execute("create table test(id int identity, name varchar)");
27: int len = getSize(1010, 10000);
28: for (int i = 0; i < len; i++) {
29: stat
30: .execute("insert into test(name) values('Hello World')");
31: }
32: ResultSet rs = stat.executeQuery("select id from test");
33: stat.executeQuery("select id from test");
34: try {
35: rs.next();
36: error("Result set should be closed");
37: } catch (SQLException e) {
38: checkNotGeneralException(e);
39: }
40: rs = stat.executeQuery("select id from test");
41: stat.close();
42: try {
43: rs.next();
44: error("Result set should be closed");
45: } catch (SQLException e) {
46: checkNotGeneralException(e);
47: }
48: stat = conn.createStatement();
49: rs = stat.executeQuery("select id from test");
50: Statement stat2 = conn.createStatement();
51: while (rs.next()) {
52: int id = rs.getInt(1);
53: ResultSet rs2 = stat2
54: .executeQuery("select * from test where id=" + id);
55: while (rs2.next()) {
56: check(rs2.getInt(1), id);
57: check(rs2.getString(2), "Hello World");
58: }
59: rs2 = stat2.executeQuery("select * from test where id="
60: + id);
61: while (rs2.next()) {
62: check(rs2.getInt(1), id);
63: check(rs2.getString(2), "Hello World");
64: }
65: }
66: conn.close();
67:
68: }
69:
70: }
|