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.db;
07:
08: import java.sql.Connection;
09: import java.sql.PreparedStatement;
10: import java.sql.SQLException;
11: import java.sql.Statement;
12:
13: import org.h2.test.TestBase;
14:
15: /**
16: * Tests if prepared statements are re-compiled when required.
17: */
18: public class TestAutoRecompile extends TestBase {
19:
20: public void test() throws Exception {
21: deleteDb("autoRecompile");
22: Connection conn = getConnection("autoRecompile");
23: Statement stat = conn.createStatement();
24: stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
25: PreparedStatement prep = conn
26: .prepareStatement("SELECT * FROM TEST");
27: check(prep.executeQuery().getMetaData().getColumnCount(), 1);
28: stat.execute("ALTER TABLE TEST ADD COLUMN NAME VARCHAR(255)");
29: check(prep.executeQuery().getMetaData().getColumnCount(), 2);
30: stat.execute("DROP TABLE TEST");
31: stat
32: .execute("CREATE TABLE TEST(ID INT PRIMARY KEY, X INT, Y INT)");
33: check(prep.executeQuery().getMetaData().getColumnCount(), 3);
34: // TODO test auto-recompile with insert..select, views and so on
35:
36: prep = conn
37: .prepareStatement("INSERT INTO TEST VALUES(1, 2, 3)");
38: stat.execute("ALTER TABLE TEST ADD COLUMN Z INT");
39: try {
40: prep.execute();
41: error();
42: } catch (SQLException e) {
43: checkNotGeneralException(e);
44: }
45: try {
46: prep.execute();
47: error();
48: } catch (SQLException e) {
49: checkNotGeneralException(e);
50: }
51: conn.close();
52: }
53:
54: }
|