1 5 package org.h2.test.db; 6 7 import java.sql.Connection ; 8 import java.sql.PreparedStatement ; 9 import java.sql.SQLException ; 10 import java.sql.Statement ; 11 12 import org.h2.test.TestBase; 13 14 public class TestAutoRecompile extends TestBase { 15 16 public void test() throws Exception { 17 deleteDb("autoRecompile"); 18 Connection conn=getConnection("autoRecompile"); 19 Statement stat = conn.createStatement(); 20 stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)"); 21 PreparedStatement prep = conn.prepareStatement("SELECT * FROM TEST"); 22 check(prep.executeQuery().getMetaData().getColumnCount(), 1); 23 stat.execute("ALTER TABLE TEST ADD COLUMN NAME VARCHAR(255)"); 24 check(prep.executeQuery().getMetaData().getColumnCount(), 2); 25 stat.execute("DROP TABLE TEST"); 26 stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, X INT, Y INT)"); 27 check(prep.executeQuery().getMetaData().getColumnCount(), 3); 28 30 prep = conn.prepareStatement("INSERT INTO TEST VALUES(1, 2, 3)"); 31 stat.execute("ALTER TABLE TEST ADD COLUMN Z INT"); 32 try { 33 prep.execute(); 34 error("must fail"); 35 } catch(SQLException e) { 36 checkNotGeneralException(e); 37 } 38 try { 39 prep.execute(); 40 error("must fail"); 41 } catch(SQLException e) { 42 checkNotGeneralException(e); 43 } 44 conn.close(); 45 } 46 47 } 48 | Popular Tags |