1 30 31 32 package org.hsqldb.test; 33 34 import java.sql.Connection ; 35 import java.sql.PreparedStatement ; 36 import java.sql.SQLException ; 37 38 import junit.framework.TestCase; 39 import junit.framework.TestResult; 40 41 53 public class TestBug778213 extends TestBase { 54 55 public TestBug778213(String name) { 56 super(name); 57 } 58 59 60 public void test() throws Exception { 61 62 Connection conn = newConnection(); 63 PreparedStatement pstmt; 64 int updateCount; 65 66 try { 67 pstmt = conn.prepareStatement("drop table test if exists"); 68 69 pstmt.executeUpdate(); 70 71 pstmt = conn.prepareStatement("create table test(id int)"); 72 updateCount = pstmt.executeUpdate(); 73 74 assertTrue("expected update count of zero", updateCount == 0); 75 76 pstmt = conn.prepareStatement("drop table test"); 77 updateCount = pstmt.executeUpdate(); 78 79 assertTrue("expected update count of zero", updateCount == 0); 80 } catch (Exception e) { 81 assertTrue("unable to prepare or execute DDL", false); 82 } finally { 83 conn.close(); 84 } 85 86 conn = newConnection(); 87 88 try { 89 pstmt = conn.prepareStatement("create table test(id int)"); 90 91 assertTrue("got data expecting update count", !pstmt.execute()); 92 } catch (Exception e) { 93 assertTrue("unable to prepare or execute DDL", false); 94 } finally { 95 conn.close(); 96 } 97 98 conn = newConnection(); 99 100 boolean exception = true; 101 102 try { 103 pstmt = conn.prepareStatement("drop table test"); 104 105 pstmt.executeQuery(); 106 } catch (SQLException e) { 107 exception = false; 108 } finally { 109 conn.close(); 110 } 111 112 if (exception) { 113 assertTrue("no exception thrown for executeQuery(DDL)", false); 114 } 115 116 conn = newConnection(); 117 118 try { 119 pstmt = conn.prepareStatement("call identity()"); 120 121 pstmt.execute(); 122 } catch (Exception e) { 123 assertTrue("unable to prepare or execute call", false); 124 } finally { 125 conn.close(); 126 } 127 128 exception = false; 129 conn = newConnection(); 130 131 try { 132 pstmt = conn.prepareStatement("create table test(id int)"); 133 134 pstmt.addBatch(); 135 } catch (SQLException e) { 136 exception = true; 137 } finally { 138 conn.close(); 139 } 140 141 if (exception) { 142 assertTrue("not expected exception batching prepared DDL", false); 143 } 144 145 conn = newConnection(); 146 147 try { 148 pstmt = conn.prepareStatement("create table test(id int)"); 149 150 assertTrue("expected null ResultSetMetadata for prepared DDL", 151 null == pstmt.getMetaData()); 152 } finally { 153 conn.close(); 154 } 155 156 conn = newConnection(); 157 158 172 173 } 175 176 177 public static void main(String [] args) throws Exception { 178 179 TestResult result; 180 TestCase test; 181 java.util.Enumeration failures; 182 int count; 183 184 result = new TestResult(); 185 test = new TestBug778213("test"); 186 187 test.run(result); 188 189 count = result.failureCount(); 190 191 System.out.println("TestBug778213 failure count: " + count); 192 193 failures = result.failures(); 194 195 while (failures.hasMoreElements()) { 196 System.out.println(failures.nextElement()); 197 } 198 } 199 } 200 | Popular Tags |