001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.test;
032:
033: import java.sql.Connection;
034: import java.sql.PreparedStatement;
035: import java.sql.SQLException;
036:
037: import junit.framework.TestCase;
038: import junit.framework.TestResult;
039:
040: /**
041: * HSQLDB TestBug778213 Junit test case. <p>
042: *
043: * Test to ensure that DDL can be executed through the
044: * HSQLDB PreparedStatement interface implementation and
045: * that the behaviour of the prepared statement object is
046: * nominally correct under "prepared" DDL.
047: *
048: * @author boucherb@users
049: * @version 1.7.2
050: * @since 1.7.2
051: */
052: public class TestBug778213 extends TestBase {
053:
054: public TestBug778213(String name) {
055: super (name);
056: }
057:
058: /* Implements the TestBug778213_Part3 test */
059: public void test() throws Exception {
060:
061: Connection conn = newConnection();
062: PreparedStatement pstmt;
063: int updateCount;
064:
065: try {
066: pstmt = conn.prepareStatement("drop table test if exists");
067:
068: pstmt.executeUpdate();
069:
070: pstmt = conn.prepareStatement("create table test(id int)");
071: updateCount = pstmt.executeUpdate();
072:
073: assertTrue("expected update count of zero",
074: updateCount == 0);
075:
076: pstmt = conn.prepareStatement("drop table test");
077: updateCount = pstmt.executeUpdate();
078:
079: assertTrue("expected update count of zero",
080: updateCount == 0);
081: } catch (Exception e) {
082: assertTrue("unable to prepare or execute DDL", false);
083: } finally {
084: conn.close();
085: }
086:
087: conn = newConnection();
088:
089: try {
090: pstmt = conn.prepareStatement("create table test(id int)");
091:
092: assertTrue("got data expecting update count", !pstmt
093: .execute());
094: } catch (Exception e) {
095: assertTrue("unable to prepare or execute DDL", false);
096: } finally {
097: conn.close();
098: }
099:
100: conn = newConnection();
101:
102: boolean exception = true;
103:
104: try {
105: pstmt = conn.prepareStatement("drop table test");
106:
107: pstmt.executeQuery();
108: } catch (SQLException e) {
109: exception = false;
110: } finally {
111: conn.close();
112: }
113:
114: if (exception) {
115: assertTrue("no exception thrown for executeQuery(DDL)",
116: false);
117: }
118:
119: conn = newConnection();
120:
121: try {
122: pstmt = conn.prepareStatement("call identity()");
123:
124: pstmt.execute();
125: } catch (Exception e) {
126: assertTrue("unable to prepare or execute call", false);
127: } finally {
128: conn.close();
129: }
130:
131: exception = false;
132: conn = newConnection();
133:
134: try {
135: pstmt = conn.prepareStatement("create table test(id int)");
136:
137: pstmt.addBatch();
138: } catch (SQLException e) {
139: exception = true;
140: } finally {
141: conn.close();
142: }
143:
144: if (exception) {
145: assertTrue("not expected exception batching prepared DDL",
146: false);
147: }
148:
149: conn = newConnection();
150:
151: try {
152: pstmt = conn.prepareStatement("create table test(id int)");
153:
154: assertTrue(
155: "expected null ResultSetMetadata for prepared DDL",
156: null == pstmt.getMetaData());
157: } finally {
158: conn.close();
159: }
160:
161: conn = newConnection();
162:
163: //#ifdef JDBC3
164: /*
165:
166: try {
167: pstmt = conn.prepareStatement("create table test(id int)");
168:
169: assertTrue("expected zero parameter for prepared DDL",
170: 0 == pstmt.getParameterMetaData().getParameterCount());
171:
172: } finally {
173: conn.close();
174: }
175:
176: */
177:
178: //#endif JDBC3
179: }
180:
181: /* Runs TestBug778213_Part3 test from the command line*/
182: public static void main(String[] args) throws Exception {
183:
184: TestResult result;
185: TestCase test;
186: java.util.Enumeration failures;
187: int count;
188:
189: result = new TestResult();
190: test = new TestBug778213("test");
191:
192: test.run(result);
193:
194: count = result.failureCount();
195:
196: System.out.println("TestBug778213 failure count: " + count);
197:
198: failures = result.failures();
199:
200: while (failures.hasMoreElements()) {
201: System.out.println(failures.nextElement());
202: }
203: }
204: }
|