summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java/tests/sql
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2011-01-28 18:02:41 -0800
committerJesse Wilson <jessewilson@google.com>2011-01-28 18:02:41 -0800
commit99aa85175f733e896d6cc01e968933a02e997bc2 (patch)
treefb33029cd0a7a61645d2941738aa651256f0c834 /luni/src/test/java/tests/sql
parent38db242d16a5a31fd86c519b817ae94c5fc89417 (diff)
downloadlibcore-99aa85175f733e896d6cc01e968933a02e997bc2.zip
libcore-99aa85175f733e896d6cc01e968933a02e997bc2.tar.gz
libcore-99aa85175f733e896d6cc01e968933a02e997bc2.tar.bz2
Scrub libcore's SQLite and JDBC tests.
I've moved the tests to the libcore package because they're maintained by Androids, unlike the tests.* classes maintained by Apache Harmony. Change-Id: I23b5ca845517129f426addeabc38e43a8fee4299
Diffstat (limited to 'luni/src/test/java/tests/sql')
-rw-r--r--luni/src/test/java/tests/sql/AllTests.java43
-rwxr-xr-xluni/src/test/java/tests/sql/ConnectionTest.java2807
-rwxr-xr-xluni/src/test/java/tests/sql/PreparedStatementTest.java3250
-rw-r--r--luni/src/test/java/tests/sql/ResultSetGetterTests.java2183
-rwxr-xr-xluni/src/test/java/tests/sql/ResultSetMetaDataTest.java888
-rw-r--r--luni/src/test/java/tests/sql/ResultSetTest.java827
-rwxr-xr-xluni/src/test/java/tests/sql/SQLTest.java136
-rwxr-xr-xluni/src/test/java/tests/sql/StatementTest.java1836
8 files changed, 0 insertions, 11970 deletions
diff --git a/luni/src/test/java/tests/sql/AllTests.java b/luni/src/test/java/tests/sql/AllTests.java
deleted file mode 100644
index e782d84..0000000
--- a/luni/src/test/java/tests/sql/AllTests.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.sql;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test suite that includes all tests for the Math project.
- */
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All SQL test suites");
- // $JUnit-BEGIN$
- suite.addTest(tests.java.sql.AllTests.suite());
-
- // These don't do blackbox testing *and* crash JUnit on the RI
- // suite.addTest(tests.SQLite.AllTests.suite());
-
- suite.addTestSuite(tests.sql.ConnectionTest.class);
- suite.addTestSuite(tests.sql.PreparedStatementTest.class);
- suite.addTestSuite(tests.sql.ResultSetGetterTests.class);
- suite.addTestSuite(tests.sql.ResultSetMetaDataTest.class);
- suite.addTestSuite(tests.sql.ResultSetTest.class);
- suite.addTestSuite(tests.sql.StatementTest.class);
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/tests/sql/ConnectionTest.java b/luni/src/test/java/tests/sql/ConnectionTest.java
deleted file mode 100755
index efa8aa4..0000000
--- a/luni/src/test/java/tests/sql/ConnectionTest.java
+++ /dev/null
@@ -1,2807 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.sql;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
-import java.sql.SQLWarning;
-import java.sql.Savepoint;
-import java.sql.Statement;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import java.sql.CallableStatement;
-import java.util.Map;
-
-import junit.framework.Test;
-
-@TestTargetClass(Connection.class)
-public class ConnectionTest extends SQLTest {
-
- /**
- * @test {@link java.sql.Connection#createStatement()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "createStatement",
- args = {}
- )
- public void testCreateStatement() {
-
- Statement statement = null;
- try {
- statement = conn.createStatement();
- assertNotNull(statement);
- //check default values
- assertEquals(ResultSet.FETCH_UNKNOWN, statement.getFetchDirection());
- assertNull(statement.getWarnings());
- assertTrue(statement.getQueryTimeout() > 0);
- } catch (SQLException sqle) {
- fail("SQL Exception was thrown: " + sqle.getMessage());
- } catch (Exception e) {
- fail("Unexpected Exception " + e.getMessage());
- }
- try {
- conn.close();
- statement.executeQuery("select * from zoo");
- fail("SQLException is not thrown after close");
- } catch (SQLException e) {
- // expected
- }
- }
-
- /**
- * @test {@link java.sql.Connection#createStatement(int resultSetType, int
- * resultSetConcurrency)}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Exception tests fail.",
- method = "createStatement",
- args = {int.class, int.class}
- )
- @KnownFailure("Scrolling on a forward only RS not allowed. conn.close() does not wrap up")
- public void testCreateStatement_int_int() throws SQLException {
- Statement st = null;
- ResultSet rs = null;
-
- // test read only
- try {
- st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY);
- st.execute("select id, name from zoo");
- rs = st.getResultSet();
- try {
- rs.deleteRow();
- fail("Could delete row for READ_ONLY ResultSet");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- st.close();
- } catch (Exception ee) {
- }
- }
-
- // test forward only: scrolling not allowed
- try {
- st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY);
- st.execute("select id, name from zoo");
- rs = st.getResultSet();
- try {
- rs.absolute(1);
- rs.previous();
- fail("Could scroll backwards");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- st.close();
- } catch (Exception ee) {
- }
- }
-
- // test forward only
- try {
- st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY);
- st.execute("select id, name from zoo");
- rs = st.getResultSet();
- try {
- rs.last();
- rs.first();
- fail("Could scroll backwards");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- st.close();
- } catch (Exception ee) {
- }
- }
-
-
- // test updating ResultSets
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.execute("select name, family from zoo");
- rs = st.getResultSet();
- try {
- rs.insertRow();
- rs.updateObject("family", "bird");
- rs.next();
- rs.previous();
- assertEquals("parrot", (rs.getString(1)));
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.execute("select name, family from zoo");
- rs = st.getResultSet();
- try {
- rs.insertRow();
- rs.updateObject("family", "bird");
- rs.next();
- rs.previous();
- assertEquals("bird", (rs.getString(1)));
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- st.close();
- } catch (Exception ee) {
- }
- }
-
- conn.close();
-
- try {
- // exception is not specified for this case
- conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, -1);
- fail("Illigal arguments: should return exception.");
- } catch (SQLException sqle) {
- // expected
- }
-
- try {
- // exception is not specified for this case
- conn.createStatement(Integer.MIN_VALUE, ResultSet.CONCUR_READ_ONLY);
- fail("Illigal arguments: should return exception.");
- } catch (SQLException sqle) {
- // expected
- }
- }
-
- /**
- * @test java.sql.Connection#createStatement(int resultSetType, int
- * resultSetConcurrency, int resultSetHoldability)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "ResultSet.HOLD_CURSORS_AT_COMMIT",
- method = "createStatement",
- args = {int.class, int.class, int.class}
- )
- public void testCreateStatement_int_int_int() {
- Statement st = null;
- try {
- assertNotNull(conn);
- st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.HOLD_CURSORS_OVER_COMMIT);
- assertNotNull(st);
- st.execute("select id, name from zoo");
- ResultSet rs = st.getResultSet();
- rs.next();
- int pos = rs.getRow();
- conn.commit();
- assertEquals("ResultSet cursor position has changed",pos, rs.getRow());
- try {
- rs.close();
- } catch (SQLException sqle) {
- fail("Unexpected exception was thrown during closing ResultSet");
- }
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- if (st != null) st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY, -100);
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- //ok
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "ResultSet.CLOSE_CURSORS_AT_COMMIT as argument is not supported",
- method = "createStatement",
- args = {int.class, int.class, int.class}
- )
- @KnownFailure("not supported")
- public void testCreateStatementIntIntIntNotSupported() {
- Statement st = null;
- try {
- st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.CLOSE_CURSORS_AT_COMMIT);
- assertNotNull(st);
- st.execute("select id, name from zoo");
- ResultSet rs = st.getResultSet();
-
- try {
- rs.close();
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- if (st != null) {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
- }
-
- /**
- * @test java.sql.Connection#getMetaData()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "getMetaData",
- args = {}
- )
- @KnownFailure("conn.close() does not wrap up")
- public void testGetMetaData() throws SQLException{
- try {
- DatabaseMetaData md = conn.getMetaData();
- Connection con = md.getConnection();
- assertEquals(conn, con);
- } catch (SQLException e) {
- fail("SQLException is thrown");
- }
-
- conn.close();
- try {
- conn.getMetaData();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#clearWarnings()
- *
- * TODO clearWarnings is not supported
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "test fails. not supported. always returns null.",
- method = "clearWarnings",
- args = {}
- )
- @KnownFailure("not supported")
- public void testClearWarnings() throws SQLException {
-
- try {
- SQLWarning w = conn.getWarnings();
- assertNull(w);
- } catch (Exception e) {
- fail("Unexpected Exception: " + e.getMessage());
- }
-
-
- Statement st = null;
- try {
- st = conn.createStatement();
- st.execute("select animals from zoo");
- fail("SQLException was not thrown");
- } catch (SQLException e) {
- assertNotNull(conn.getWarnings());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- conn.clearWarnings();
- SQLWarning w = conn.getWarnings();
- assertNull(w);
- } catch (Exception e) {
- fail("Unexpected Exception: " + e.getMessage());
- }
-
- try {
- st = conn.createStatement();
- st.execute("select monkey from zoo");
- fail("SQLException was not thrown");
- } catch (SQLException e) {
- assertEquals("SQLite.Exception: error in prepare/compile",e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- //Test for correct functionality
- try {
- SQLWarning w = conn.getWarnings();
- assertNotNull(w);
- } catch (Exception e) {
- fail("Unexpected Exception: " + e.getMessage());
- }
-
- conn.close();
- try {
- conn.clearWarnings();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#getWarnings()
- *
- * TODO GetWarnings is not supported: returns null
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported. always returns null. SQLException test fails",
- method = "getWarnings",
- args = {}
- )
- @KnownFailure("not supported")
- public void testGetWarnings() throws SQLException {
- Statement st = null;
- int errorCode1 = -1;
- int errorCode2 = -1;
-
- try {
- st = conn.createStatement();
- st.execute("select animals from zoooo");
- fail("SQLException was not thrown");
- } catch (SQLException e) {
- // expected
- errorCode1 = e.getErrorCode();
- }
-
- try {
- SQLWarning wrs = conn.getWarnings();
- assertNull(wrs);
- } catch (Exception e) {
- fail("Change test implementation: get warnings is supported now");
- }
-
- // tests implementation: but errorcodes need to change too -> change impl.
- /*
- Statement st = null;
- int errorCode1 = -1;
- int errorCode2 = -1;
-
- try {
- st = conn.createStatement();
- st.execute("select animals from zoooo");
- fail("SQLException was not thrown");
- } catch (SQLException e) {
- // expected
- errorCode1 = e.getErrorCode();
- }
-
- try {
- SQLWarning wrs = conn.getWarnings();
- assertNotNull(wrs);
- assertEquals(errorCode1, wrs.getErrorCode());
- assertNull(wrs.getNextWarning());
- } catch (Exception e) {
- fail("Unexpected Exception: " + e.getMessage());
- }
- try {
- st.execute("select horse from zoooooo");
- } catch (SQLException e) {
- // expected
- errorCode2 = e.getErrorCode();
- }
-
- try {
- SQLWarning wrs = conn.getWarnings();
- assertEquals(errorCode1, wrs.getErrorCode());
- assertNotNull(wrs.getNextWarning());
- assertEquals(errorCode2, wrs.getErrorCode());
- } catch (Exception e) {
- fail("Unexpected Exception: " + e.getMessage());
- }
-
- try {
- st.close();
- } catch (SQLException ee) {
- }
-
- */
-
- conn.close();
- try {
- conn.getWarnings();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test java.sql.Connection#getAutoCommit()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException checking missed",
- method = "getAutoCommit",
- args = {}
- )
- public void testGetAutoCommit() {
- try {
- conn.setAutoCommit(true);
- assertTrue(conn.getAutoCommit());
- conn.setAutoCommit(false);
- assertFalse(conn.getAutoCommit());
- conn.setAutoCommit(true);
- assertTrue(conn.getAutoCommit());
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
- }
-
- /**
- * @test java.sql.Connection#setAutoCommit(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test throws exception",
- method = "setAutoCommit",
- args = {boolean.class}
- )
- @KnownFailure("conn.close() does not wrap up")
- public void testSetAutoCommit() throws SQLException {
-
- Statement st = null;
- ResultSet rs = null;
- ResultSet rs1 = null;
- try {
- conn.setAutoCommit(true);
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (3, 'Chichichi', 'monkey');");
- conn.commit();
- } catch (SQLException e) {
- //ok
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- // even though exception was thrown value is committed
- try {
- st = conn.createStatement();
- st.execute("select * from zoo");
- rs = st.getResultSet();
- assertEquals(3, getCount(rs));
- } catch (SQLException e) {
- fail("Unexpected Exception thrown");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
-
- try {
- conn.setAutoCommit(false);
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (4, 'Burenka', 'cow');");
- st.execute("select * from zoo");
- rs = st.getResultSet();
- assertEquals(4, getCount(rs));
- conn.commit();
- // Check cursors closed after commit
- rs1 = st.getResultSet();
- assertEquals(0, getCount(rs1));
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- rs1.close();
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- conn.close();
-
- try {
- conn.setAutoCommit(true);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#isReadOnly()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Instead of SQLException nullpointer exception is thrown.",
- method = "isReadOnly",
- args = {}
- )
- @KnownFailure("conn.close() does not wrap up")
- public void testIsReadOnly() throws SQLException {
- try {
- conn.setReadOnly(true);
- assertTrue(conn.isReadOnly());
- conn.setReadOnly(false);
- assertFalse(conn.isReadOnly());
- } catch (SQLException sqle) {
- fail("SQLException was thrown: " + sqle.getMessage());
- }
-
- conn.close();
- try {
- conn.isReadOnly();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#setReadOnly(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Not supported. test fails",
- method = "setReadOnly",
- args = {boolean.class}
- )
- @KnownFailure("not supported")
- public void testSetReadOnly() throws SQLException {
-
- // Pseudo test: not supported test
- Statement st = null;
- try {
- conn.setReadOnly(true);
- st = conn.createStatement();
- st.execute("insert into zoo (id, name, family) values (3, 'ChiChiChi', 'monkey');");
- // fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- fail("Set readonly is actually implemented: activate correct test");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- // test for correct implementation
- st = null;
- try {
- conn.setReadOnly(true);
- st = conn.createStatement();
- st.execute("insert into zoo (id, name, family) values (3, 'ChiChiChi', 'monkey');");
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- conn.setReadOnly(true);
- st = conn.createStatement();
- st.executeUpdate("insert into zoo (id, name, family) values (4, 'ChaChaCha', 'monkey');");
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- conn.setReadOnly(false);
- st = conn.createStatement();
- st.execute("insert into zoo (id, name, family) values (4, 'ChiChiChi', 'monkey');");
- } catch (SQLException sqle) {
- fail("SQLException was thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- conn.close();
- try {
- conn.setReadOnly(true);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#getHoldability()
- *
- * TODO ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "+option ResultSet.CLOSE_CURSORS_AT_COMMIT not supported. SQLException test fails.",
- method = "getHoldability",
- args = {}
- )
- @KnownFailure("not supported")
- public void testGetHoldability() throws SQLException {
- try {
- conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
- assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn
- .getHoldability());
- } catch (SQLException sqle) {
- fail("SQLException was thrown: " + sqle.getMessage());
- }
-
- try {
- conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
- assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn
- .getHoldability());
- } catch (SQLException e) {
- assertEquals("not supported", e.getMessage());
- }
-
- // Exception checking
-
- conn.close();
-
- try {
- conn.getHoldability();
- fail("Could execute statement on closed connection.");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test java.sql.Connection#setHoldability(int)
- *
- * TODO ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported",
- method = "setHoldability",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testSetHoldability() {
- Statement st = null;
- try {
- conn.setAutoCommit(false);
- conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
- assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn
- .getHoldability());
- st = conn.createStatement();
- st.execute("insert into zoo (id, name, family) values (4, 'ChiChiChi', 'monkey');");
- ResultSet rs = st.getResultSet();
- conn.commit();
- try {
- rs.next();
- } catch (SQLException sqle) {
- //ok
- }
- conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
- assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn
- .getHoldability());
- st = conn.createStatement();
- st.execute("insert into zoo (id, name, family) values (4, 'ChiChiChi', 'monkey');");
- rs = st.getResultSet();
- conn.commit();
- try {
- rs.next();
- } catch (SQLException sqle) {
- fail("SQLException was thrown: " + sqle.getMessage());
- }
- } catch (SQLException sqle) {
- fail("SQLException was thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- conn.setHoldability(-1);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#getTransactionIsolation()
- *
- * TODO only Connection.TRANSACTION_SERIALIZABLE is supported
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "SQLException testing throws exception. Connection.TRANSACTION_SERIALIZABLE.",
- method = "getTransactionIsolation",
- args = {}
- )
- @KnownFailure("not supported")
- public void testGetTransactionIsolation() throws SQLException {
- try {
- conn
- .setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
- assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn
- .getTransactionIsolation());
- conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
- assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn
- .getTransactionIsolation());
- conn
- .setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
- assertEquals(Connection.TRANSACTION_REPEATABLE_READ, conn
- .getTransactionIsolation());
- conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
- assertEquals(Connection.TRANSACTION_SERIALIZABLE, conn
- .getTransactionIsolation());
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
-
- // Exception checking
-
- conn.close();
-
- try {
- conn.getTransactionIsolation();
- fail("Could execute statement on closed connection.");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#getTransactionIsolation()
- *
- * TODO only Connection.TRANSACTION_SERIALIZABLE is supported
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "not supported options",
- method = "getTransactionIsolation",
- args = {}
- )
- public void testGetTransactionIsolationNotSupported() throws SQLException {
- /*
- try {
- conn
- .setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
- assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn
- .getTransactionIsolation());
- conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
- assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn
- .getTransactionIsolation());
- conn
- .setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
- assertEquals(Connection.TRANSACTION_REPEATABLE_READ, conn
- .getTransactionIsolation());
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
- */
- }
-
- /**
- * @test java.sql.Connection#setTransactionIsolation(int)
- *
- * TODO only Connection.TRANSACTION_SERIALIZABLE is supported
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not fully supported",
- method = "setTransactionIsolation",
- args = {int.class}
- )
- public void testSetTransactionIsolation() {
- try {
-// conn
-// .setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-// assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn
-// .getTransactionIsolation());
-// conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-// assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn
-// .getTransactionIsolation());
-// conn
-// .setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
-// assertEquals(Connection.TRANSACTION_REPEATABLE_READ, conn
-// .getTransactionIsolation());
- conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
- assertEquals(Connection.TRANSACTION_SERIALIZABLE, conn
- .getTransactionIsolation());
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
-
- try {
- conn.setTransactionIsolation(0);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- }
-
- /**
- * @test java.sql.Connection#setCatalog(String catalog)
- *
- * TODO setCatalog method does nothing: Hint default catalog sqlite_master.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setCatalog",
- args = {java.lang.String.class}
- )
- public void testSetCatalog() {
-
- String[] catalogs = { "test", "test1", "test" };
- Statement st = null;
- try {
- for (int i = 0; i < catalogs.length; i++) {
- conn.setCatalog(catalogs[i]);
- assertNull(catalogs[i], conn.getCatalog());
- st = conn.createStatement();
- st
- .equals("create table test_table (id integer not null, name varchar(20), primary key(id));");
- st.equals("drop table test_table;");
-
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown");
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- /*
- String[] catalogs = { "test"};
- Statement st = null;
- try {
- for (int i = 0; i < catalogs.length; i++) {
- conn.setCatalog(catalogs[i]);
- fail("illegal catalog name");
- assertEquals(catalogs[i], conn.getCatalog());
- st = conn.createStatement();
- st
- .equals("create table test_table (id integer not null, name varchar(20), primary key(id));");
- st.equals("drop table test_table;");
- }
- } catch (SQLException sqle) {
- System.out.println("TODO: Test for correct error message: name with ,\"sqlite_\" prefix expected");
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- String[] catalogs = { "sqlite_test", "sqlite_test1", "sqlite_test" };
- Statement st = null;
- try {
- for (int i = 0; i < catalogs.length; i++) {
- conn.setCatalog(catalogs[i]);
- assertEquals(catalogs[i], conn.getCatalog());
- st = conn.createStatement();
- st
- .equals("create table test_table (id integer not null, name varchar(20), primary key(id));");
- st.equals("drop table test_table;");
-
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown");
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- conn.setCatalog(null);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
-
- try {
- conn.setCatalog("not_exist");
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- */
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#getCatalog()
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported. test fails",
- method = "getCatalog",
- args = {}
- )
- @KnownFailure("not supported")
- public void testGetCatalog() throws SQLException {
-
-
- // test default catalog
- try {
- assertEquals("sqlite_master", conn.getCatalog());
- } catch (SQLException sqle) {
- fail("SQL Exception " + sqle.getMessage());
- } catch (Exception e) {
- fail("Unexpected Exception " + e.getMessage());
- }
-
-
- String[] catalogs = { "sqlite_test", "sqlite_test1", "sqlite_test" };
- Statement st = null;
- try {
- for (int i = 0; i < catalogs.length; i++) {
- conn.setCatalog(catalogs[i]);
- assertNull(conn.getCatalog());
- }
- } catch (SQLException sqle) {
- fail("SQL Exception " + sqle.getMessage());
- } catch (Exception e) {
- fail("Reeimplement tests now that the method is implemented");
- }
-
- // Exception checking
-
- conn.close();
-
- try {
- conn.getCatalog();
- fail("Could execute statement on closed connection.");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test java.sql.Connection#setTypeMap(Map<String,Class<?>> map)
- *
- * TODO setTypeMap is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setTypeMap",
- args = {java.util.Map.class}
- )
- public void testSetTypeMap() {
- /*
- try {
- java.util.Map map = conn.getTypeMap();
- map
- .put(
- "org.apache.harmony.sql.tests.java.sql.TestHelper_Connection1",
- Class.forName("TestHelper_Connection1"));
- conn.setTypeMap(map);
- assertEquals(map, conn.getTypeMap());
- } catch (SQLException sqle) {
- //ok
- } catch (Exception e) {
- fail("Unexpected Exception " + e.getMessage());
- }
-
- try {
- conn.setTypeMap(null);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- */
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#getTypeMap()
- *
- * TODO getTypeMap is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "getTypeMap",
- args = {}
- )
- public void testGetTypeMap() throws SQLException {
- /*
- try {
- java.util.Map map = conn.getTypeMap();
- map
- .put(
- "org.apache.harmony.sql.tests.java.sql.TestHelper_Connection1",
- Class.forName("TestHelper_Connection1"));
- conn.setTypeMap(map);
- assertEquals(map, conn.getTypeMap());
- } catch (SQLException sqle) {
- //ok
- } catch (Exception e) {
- fail("Unexpected Exception " + e.getMessage());
- }
-
-// Exception checking
-
- conn.close();
-
- try {
- conn.setTypeMap(null);
- fail("Could execute statement on closed connection.");
- } catch (SQLException e) {
- //ok
- }
- */
- }
-
- /**
- * @test java.sql.Connection#nativeSQL(String sql)
- *
- * TODO nativeSQL is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "nativeSQL",
- args = {java.lang.String.class}
- )
- public void testNativeSQL() throws SQLException{
- String[] queries = {
- "select * from zoo;",
- "insert into zoo (id, name, family) values (3, 'Chichichi', 'monkey');",
- "create table zoo_office(id integer not null, name varchar(20), primary key(id));",
- "drop table zoo_office;" };
- String[] native_queries = {
- "select * from zoo;",
- "insert into zoo (id, name, family) values (3, 'Chichichi', 'monkey');",
- "create table zoo_office(id integer not null, name varchar(20), primary key(id));",
- "drop table zoo_office;" };
- Statement st = null;
- String nativeQuery = "";
- try {
- for (int i = 0; i < queries.length; i++) {
- nativeQuery = conn.nativeSQL(queries[i]);
- assertEquals(native_queries[i], nativeQuery);
- st = conn.createStatement();
- st.execute(nativeQuery);
- }
- } catch (SQLException sqle) {
- //ok
- } catch (Exception e) {
- fail("Unexpected Exception " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- String[] inc_queries = { "", " ", "not query" };
- for (int i = 0; i < inc_queries.length; i++) {
- try {
- nativeQuery = conn.nativeSQL(inc_queries[i]);
- assertEquals(inc_queries[i], nativeQuery);
- } catch (SQLException e) {
- assertEquals("not supported",e.getMessage());
- }
- }
-
- // Exception checking
-
- conn.close();
-
- try {
- conn.nativeSQL(inc_queries[0]);
- fail("Could execute statement on closed connection.");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * @test java.sql.Connection#prepareCall(String sql)
- *
- * TODO prepareCall is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "prepareCall",
- args = {java.lang.String.class}
- )
- public void testPrepareCall() throws SQLException {
- CallableStatement cstmt = null;
- ResultSet rs = null;
- ResultSet rs1 = null;
- Statement st = null;
- Statement st1 = null;
- try {
- cstmt = conn.prepareCall("call welcomeAnimal(3, 'Petya', 'Cock')");
- st = conn.createStatement();
- st.execute("select * from zoo");
- rs = st.getResultSet();
- assertEquals(2, getCount(rs));
- cstmt.execute();
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(3, getCount(rs1));
-
- } catch (SQLException e) {
- //ok not supported
- } finally {
- try {
- st.close();
- st1.close();
- rs.close();
- rs1.close();
- cstmt.close();
- } catch (Exception ee) {
- }
- }
-
-
- try {
- conn.prepareCall("welcomeAnimal(4, 'Petya', 'Cock')");
- fail("SQL Exception is not thrown");
- } catch (SQLException e) {
- // expected
- }
-
- try {
- conn.prepareCall(null);
- fail("SQL Exception is not thrown");
- } catch (SQLException e) {
- // expected
- }
-
- // Exception checking
-
- conn.close();
-
- try {
- conn.prepareCall("");
- fail("Could execute statement on closed connection.");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * @test java.sql.Connection#prepareCall(String sql, int resultSetType, int
- * resultSetConcurrency)
- *
- * TODO prepareCall is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "prepareCall",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void testPrepareCall_String_int_int() {
- CallableStatement cstmt = null;
- ResultSet rs = null;
-
- try {
- String query = "call welcomeAnimal(3, 'Petya', 'Cock')";
- cstmt = conn.prepareCall(query, ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY);
- } catch (SQLException e) {
- //ok
- }
-
- /*
- try {
- String query = "call welcomeAnimal(3, 'Petya', 'Dino')";
- cstmt = conn.prepareCall(query, ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY);
- cstmt.execute("select id, name from zoo");
- rs = cstmt.getResultSet();
- try {
- rs.deleteRow();
- fail("Can delete row for READ_ONLY ResultSet");
- } catch (SQLException sqle) {
- // expected
- }
-
- try {
- rs.absolute(0);
- fail("Can move cursor to the last position for TYPE_FORWARD_ONLY ResultSet");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- cstmt.close();
- } catch (Exception ee) {
- }
- }
- Statement st = null;
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.execute("select name, family from zoo");
- rs = st.getResultSet();
- try {
- rs.insertRow();
- rs.updateObject("family", "bird");
- rs.next();
- rs.previous();
- assertEquals("parrot", (rs.getString(1)));
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.execute("select name, family from zoo");
- rs = st.getResultSet();
- try {
- rs.insertRow();
- rs.updateObject("family", "bird");
- rs.next();
- rs.previous();
- assertEquals("bird", (rs.getString(1)));
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, -1);
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- try {
- conn.createStatement(Integer.MIN_VALUE, ResultSet.CONCUR_READ_ONLY);
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- */
- }
-
- /**
- * @test java.sql.Connection#prepareCall(String sql, int resultSetType, int
- * resultSetConcurrency, int resultSetHoldability)
- *
- * TODO prepareCall is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "prepareCall",
- args = {java.lang.String.class, int.class, int.class, int.class}
- )
- public void testPrepareCall_String_int_int_int() {
- CallableStatement cstmt = null;
- ResultSet rs = null;
-
- try {
- String query = "call welcomeAnimal(?, ?, ?)";
- cstmt = conn.prepareCall(query, ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.HOLD_CURSORS_OVER_COMMIT);
- } catch (SQLException e) {
- //ok
- }
- /*
- try {
- String query = "call welcomeAnimal(?, ?, ?)";
- cstmt = conn.prepareCall(query, ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.HOLD_CURSORS_OVER_COMMIT);
- cstmt.setInt(1, 3);
- cstmt.setString(2, "Petya");
- cstmt.setString(3, "Cock");
- cstmt.execute("select id, name from zoo");
- rs = cstmt.getResultSet();
- try {
- rs.close();
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- fail("Unexpected exception was thrown during closing ResultSet");
- }
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- cstmt.close();
- } catch (Exception ee) {
- }
- }
-
- Statement st = null;
-
- try {
- st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.CLOSE_CURSORS_AT_COMMIT);
- st.execute("select id, name from zoo");
- rs = st.getResultSet();
- try {
- rs.close();
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- }
-
- try {
- conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY, -100);
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- */
-
- }
-
- /**
- * @test java.sql.Connection#prepareStatement(String sql)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "prepareStatement",
- args = {java.lang.String.class}
- )
- public void testPrepareStatement() {
- PreparedStatement prst = null;
- Statement st = null;
- ResultSet rs = null;
- ResultSet rs1 = null;
- try {
- String update = "update zoo set family = ? where name = ?;";
- prst = conn.prepareStatement(update);
- prst.setString(1, "cat");
- prst.setString(2, "Yasha");
- st = conn.createStatement();
- st.execute("select * from zoo where family = 'cat'");
- rs = st.getResultSet();
- assertEquals(0, getCount(rs));
- prst.executeUpdate();
- st.execute("select * from zoo where family = 'cat'");
- rs1 = st.getResultSet();
- assertEquals(1, getCount(rs1));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- rs1.close();
- prst.close();
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- prst = conn.prepareStatement("");
- prst.execute();
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- conn.prepareStatement(null);
- fail("SQLException is not thrown");
- } catch (Exception e) {
- //ok
- }
-
-
- }
-
-
- /**
- * @test { @link java.sql.Connection#prepareStatement(String sql, int
- * autoGeneratedKeys) }
- */
-// TODO Crashes VM. Fix later.
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Statment.Return_generated_keys/getGeneratedKeys is not supported",
- method = "prepareStatement",
- args = {java.lang.String.class, int.class}
- )
- @KnownFailure("not supported")
- public void testPrepareStatement_String_int() {
- PreparedStatement prst = null;
- PreparedStatement prst1 = null;
- Statement st = null;
- ResultSet rs = null;
- ResultSet rs1 = null;
- ResultSet rs4 = null;
- ResultSet rs5 = null;
-
-
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- prst = conn.prepareStatement(insert,
- Statement.RETURN_GENERATED_KEYS);
- fail("Fail: prepareStatement does not fail");
- } catch (SQLException e) {
- //ok not supported
- }
-
-
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
-
- prst = conn.prepareStatement(insert,
- Statement.NO_GENERATED_KEYS);
- prst.setInt(1, 8);
- prst.setString(2, "Tuzik");
- prst.setString(3, "dog");
- st = conn.createStatement();
- st.execute("select * from zoo");
- rs = st.getResultSet();
- assertEquals(2, getCount(rs));
- prst.execute();
- st.execute("select * from zoo where family = 'dog'");
- rs1 = st.getResultSet();
- assertEquals(1, getCount(rs1));
-// TODO getGeneratedKeys is not supported
- rs4 = prst.getGeneratedKeys();
- assertEquals(0, getCount(rs4));
-
-
-
- prst1 = conn.prepareStatement(insert, Statement.RETURN_GENERATED_KEYS);
- prst1.setInt(1, 5);
- prst1.setString(2, "Layka");
- prst1.setString(3, "dog");
-
- prst1.execute();
-
-
-
- rs5 = prst1.getGeneratedKeys();
- assertEquals(0, getCount(rs5));
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- rs1.close();
- prst.close();
- st.close();
- } catch (Exception ee) {
- }
- }
-
-
- }
-
- /**
- * @test java.sql.Connection#commit()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "commit",
- args = {}
- )
- public void testCommit() {
- Statement st = null;
- Statement st1 = null;
- Statement st2 = null;
- Statement st3 = null;
- Statement st4 = null;
- ResultSet rs1 = null;
- ResultSet rs2 = null;
- ResultSet rs3 = null;
- ResultSet rs4 = null;
- try {
- conn.setAutoCommit(false);
-
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
- st
- .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
-
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- try {
- conn.commit();
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st3 = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.HOLD_CURSORS_OVER_COMMIT);
- st3.execute("select * from zoo");
- rs3 = st3.getResultSet();
- conn.commit();
- assertEquals(4, getCount(rs3));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- if (rs3 != null) rs3.close();
- if (st3 != null) st3.close();
- } catch (SQLException ee) {
- }
- }
- } catch (SQLException sqle) {
- fail("SQLException was thrown: " + sqle.toString());
- } finally {
- try {
- rs1.close();
- st.close();
- st1.close();
- } catch (Exception ee) {
- }
- }
-
-
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Connection#rollback()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "rollback",
- args = {}
- )
- public void testRollback() throws SQLException {
- Statement st = null;
- Statement st1 = null;
- ResultSet rs1 = null;
- ResultSet rs2 = null;
- ResultSet rs3 = null;
-
- try {
- conn.setAutoCommit(false);
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
- st
- .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
- conn.rollback();
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals("Rollback was ineffective",2, getCount(rs1));
-
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- } finally {
- conn.setAutoCommit(true);
- try {
- st.close();
- st1.close();
- rs1.close();
- } catch (SQLException ee) {
- }
- }
- try {
- conn.setAutoCommit(false);
-
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
- st
- .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
-
- if (!conn.getAutoCommit()) {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- Statement st2 = null;
- Statement st3 = null;
- try {
- conn.commit();
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- // rollback after commit ineffective
- conn.rollback();
- st3 = conn.createStatement();
- st3.execute("select * from zoo");
- rs3 = st3.getResultSet();
- assertEquals(4, getCount(rs3));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- conn.setAutoCommit(true);
- try {
- rs2.close();
- rs3.close();
- st2.close();
- st3.close();
- } catch (SQLException ee) {
- }
- }
- } else {
- fail("Error in test setup: cannot turn autocommit off.");
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- } finally {
- try {
- st.close();
- st1.close();
- rs1.close();
- } catch (SQLException ee) {
- }
- }
-
- conn.close();
- try {
- conn.rollback();
- fail("SQLException expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * @test java.sql.Connection#setSavepoint()
- *
- * TODO setSavepoint is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setSavepoint",
- args = {}
- )
- public void testSetSavepoint() {
-
- try {
- conn.setAutoCommit(false);
-
- try {
- Savepoint sp = conn.setSavepoint();
- } catch (SQLException e) {
- // ok not supported
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
-
-
- //Complete test but: not supported exception is thrown
- /*
- try {
- conn.setAutoCommit(false);
-
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
- st
- .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
-
- if (!conn.getAutoCommit()) {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- Statement st2 = null;
- ResultSet rs2 = null;
- try {
- Savepoint sp = conn.setSavepoint();
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.rollback(sp);
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- Savepoint sp1 = conn.setSavepoint();
- assertNotNull(sp1);
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- Savepoint sp2 = conn.setSavepoint();
- assertNotNull(sp2);
- st
- .execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
- conn.rollback(sp1);
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- Savepoint sp1 = conn.setSavepoint();
- assertNotNull(sp1);
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- Savepoint sp2 = conn.setSavepoint();
- assertNotNull(sp2);
- st
- .execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
- conn.rollback();
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (SQLException ee) {
- }
- }
-
- } else {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- try {
- Savepoint sp = conn.setSavepoint();
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.rollback(sp);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- } finally {
- try {
- rs1.close();
- st.close();
- st1.close();
- } catch (SQLException ee) {
- }
- }
- */
- }
-
- /**
- * @test java.sql.Connection#setSavepoint(String name)
- *
- * TODO setSavepoint is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setSavepoint",
- args = {java.lang.String.class}
- )
- public void testSetSavepoint_String() {
-
- String testSavepoint = "testSavepoint";
-
- try {
- conn.setAutoCommit(false);
-
- try {
- Savepoint sp = conn.setSavepoint(testSavepoint);
- } catch (SQLException e) {
- // ok not supported
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
-
- /*
- Statement st = null;
- Statement st1 = null;
- ResultSet rs1 = null;
- try {
- conn.setAutoCommit(false);
-
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
- st
- .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
-
- if (!conn.getAutoCommit()) {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- Statement st2 = null;
- ResultSet rs2 = null;
- try {
- Savepoint sp = conn.setSavepoint("one");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.rollback(sp);
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- Savepoint sp1 = conn.setSavepoint("one");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- Savepoint sp2 = conn.setSavepoint("two");
- st
- .execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
- conn.rollback(sp1);
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- Savepoint sp1 = conn.setSavepoint("three");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- Savepoint sp2 = conn.setSavepoint("four");
- st
- .execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
- conn.rollback();
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (SQLException ee) {
- }
- }
-
- } else {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- try {
- Savepoint sp = conn.setSavepoint("five");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.rollback(sp);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- } finally {
- try {
- rs1.close();
- st.close();
- st1.close();
- } catch (SQLException ee) {
- }
- }
- */
- }
-
- /**
- * @test java.sql.Connection#rollback(Savepoint savepoint)
- *
- * TODO Savepoint is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "rollback",
- args = {java.sql.Savepoint.class}
- )
- public void testRollback_Savepoint() {
- Savepoint sp = new DummySavePoint();
- try {
- conn.setAutoCommit(false);
-
- try {
- conn.rollback(sp);
- } catch (SQLException e) {
- //ok
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
- /*
- Statement st = null;
- Statement st1 = null;
- ResultSet rs1 = null;
- try {
- conn.setAutoCommit(false);
-
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
- st
- .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
-
- if (!conn.getAutoCommit()) {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- Statement st2 = null;
- ResultSet rs2 = null;
- try {
- Savepoint sp = conn.setSavepoint("one");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.rollback(sp);
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- Savepoint sp1 = conn.setSavepoint("one");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- Savepoint sp2 = conn.setSavepoint("two");
- st
- .execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
- conn.rollback(sp1);
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- Savepoint sp1 = conn.setSavepoint("three");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- Savepoint sp2 = conn.setSavepoint("four");
- st
- .execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
- conn.rollback();
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (SQLException ee) {
- }
- }
-
- } else {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- try {
- Savepoint sp = conn.setSavepoint("five");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.rollback(sp);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- } finally {
- try {
- rs1.close();
- st.close();
- st1.close();
- } catch (SQLException ee) {
- }
- }
- */
- }
-
- /**
- * @test java.sql.Connection#releaseSavepoint(Savepoint savepoint)
- *
- * TODO Savepoint is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "releaseSavepoint",
- args = {java.sql.Savepoint.class}
- )
- public void testReleaseSavepoint_Savepoint() {
- Savepoint sp = new DummySavePoint();
- try {
- conn.setAutoCommit(false);
-
- try {
- conn.releaseSavepoint(sp);
- } catch (SQLException e) {
- //ok
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
- /*
-
- Statement st = null;
- Statement st1 = null;
- ResultSet rs1 = null;
- try {
- conn.setAutoCommit(false);
-
- st = conn.createStatement();
- st
- .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');");
- st
- .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');");
-
- if (!conn.getAutoCommit()) {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- Statement st2 = null;
- ResultSet rs2 = null;
- try {
- Savepoint sp = conn.setSavepoint("one");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.rollback(sp);
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.releaseSavepoint(sp);
- try {
- conn.rollback(sp);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- conn.rollback();
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- Savepoint sp1 = conn.setSavepoint("one");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- Savepoint sp2 = conn.setSavepoint("two");
- st
- .execute("insert into zoo (id, name, family) values (6, 'grach', 'rook');");
- conn.releaseSavepoint(sp1);
- try {
- conn.rollback(sp1);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- conn.commit();
- conn.rollback(sp2);
- st2 = conn.createStatement();
- st2.execute("select * from zoo");
- rs2 = st2.getResultSet();
- assertEquals(4, getCount(rs2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- rs2.close();
- st2.close();
- } catch (SQLException ee) {
- }
- }
-
- } else {
- st1 = conn.createStatement();
- st1.execute("select * from zoo");
- rs1 = st1.getResultSet();
- assertEquals(4, getCount(rs1));
- try {
- Savepoint sp = conn.setSavepoint("five");
- st
- .execute("insert into zoo (id, name, family) values (5, 'chayka', 'gull');");
- conn.releaseSavepoint(sp);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- }
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- } finally {
- try {
- rs1.close();
- st.close();
- st1.close();
- } catch (SQLException ee) {
- }
- }
- */
- }
-
- /**
- * @test java.sql.Connection#prepareStatement(String sql, int[]
- * columnIndexes)
- *
- * TODO prepareStatement(String sql, int[] columnIndexes) is not
- * supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "prepareStatement",
- args = {java.lang.String.class, int[].class}
- )
- public void testPrepareStatement_String_intArray() {
- PreparedStatement prst = null;
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- prst = conn.prepareStatement(insert, new int[] { 0, 1, 2 });
- } catch (SQLException e) {
- //ok not supported
- } finally {
- try {
- prst.close();
- } catch (Exception ee) {
- }
- }
- /*
-
- Statement st = null;
- PreparedStatement prst1 = null;
- PreparedStatement prst = null;
- ResultSet rs = null;
- ResultSet rs1 = null;
- ResultSet rs4 = null;
- ResultSet rs5 = null;
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- prst = conn.prepareStatement(insert, new int[] { 0, 1, 2 });
- prst.setInt(1, 8);
- prst.setString(2, "Tuzik");
- prst.setString(3, "dog");
-
- st = conn.createStatement();
- st.execute("select * from zoo");
- rs = st.getResultSet();
- assertEquals(2, getCount(rs));
- prst.execute();
- st.execute("select * from zoo where family = 'dog'");
- rs1 = st.getResultSet();
- assertEquals(1, getCount(rs1));
-
- rs4 = prst.getGeneratedKeys();
- assertEquals(0, getCount(rs4));
-
- prst1 = conn.prepareStatement(insert, new int[] { 0, 1, 2, 10 });
- prst1.setInt(1, 5);
- prst1.setString(2, "Layka");
- prst1.setString(3, "dog");
-
- prst1.execute();
-
- rs5 = prst1.getGeneratedKeys();
- assertEquals(0, getCount(rs5));
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- rs1.close();
- rs4.close();
- rs5.close();
- st.close();
- prst1.close();
- prst.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- conn.prepareStatement(insert, new int[] {});
- } catch (SQLException e) {
- fail("SQLException is thrown");
- }
-
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- conn.prepareStatement(insert, (int[]) null);
- } catch (SQLException e) {
- fail("SQLException is thrown");
- }
- */
- }
-
- /**
- * @test java.sql.Connection#prepareStatement(String sql, int resultSetType,
- * int resultSetConcurrency)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "not fully supported",
- method = "prepareStatement",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void testPrepareStatement_String_int_int() {
- String query = "insert into zoo (id, name, family) values (?, ?, ?);";
- PreparedStatement st = null;
- ResultSet rs = null;
- try {
-
- st = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY);
- st.execute("select id, name from zoo");
- rs = st.getResultSet();
- try {
- rs.deleteRow();
- fail("Can delete row for READ_ONLY ResultSet");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- if (rs != null) rs.close();
- if (st != null) st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.execute("select name, family from zoo");
- rs = st.getResultSet();
- try {
- rs.insertRow();
- rs.updateObject("family", "bird");
- rs.next();
- rs.previous();
- assertEquals("bird", (rs.getString(1)));
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- conn.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, -1);
- } catch (SQLException sqle) {
- // expected
- }
-
- try {
- conn.prepareStatement(query, Integer.MIN_VALUE,
- ResultSet.CONCUR_READ_ONLY);
- } catch (SQLException sqle) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "not supported options: ResultSet.TYPE_SCROLL_INSENSITIVE," +
- "ResultSet.CONCUR_UPDATABLE",
- method = "prepareStatement",
- args = {java.lang.String.class, int.class, int.class}
- )
- @KnownFailure("not supported")
- public void testPrepareStatementNotSupported() {
- String query = "insert into zoo (id, name, family) values (?, ?, ?);";
- PreparedStatement st = null;
- ResultSet rs = null;
- try {
- st = conn.prepareStatement(query,
- ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.execute("select name, family from zoo");
- rs = st.getResultSet();
- try {
- rs.insertRow();
- rs.updateObject("family", "bird");
- rs.next();
- rs.previous();
- assertEquals("parrot", (rs.getString(1)));
- } catch (SQLException sqle) {
- fail("Got Exception "+sqle.getMessage());
- }
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- if (rs != null) rs.close();
- if (st != null) st.close();
- } catch (SQLException ee) {
- }
- }
-
- }
-
-
-
- /**
- * @test java.sql.Connection#prepareStatement(String sql, int resultSetType,
- * int resultSetConcurrency, int resultSetHoldability)
- */
- // TODO Crashes VM. Fix later.
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Not fully implemented: ResultSet.CLOSE_CURSORS_AT_COMMIT not supported",
- method = "prepareStatement",
- args = {java.lang.String.class, int.class, int.class, int.class}
- )
- public void testPrepareStatement_String_int_int_int() {
- String query = "insert into zoo (id, name, family) values (?, ?, ?);";
- PreparedStatement st = null;
- ResultSet rs = null;
- try {
- st = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.HOLD_CURSORS_OVER_COMMIT);
- st.setInt(1, 3);
- st.setString(2, "Petya");
- st.setString(3, "Cock");
- st.execute("select id, name from zoo");
- rs = st.getResultSet();
- try {
- rs.close();
- } catch (SQLException sqle) {
- fail("Unexpected exception was thrown during closing ResultSet");
- }
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- if (rs != null) rs.close();
- if (st != null) st.close();
- } catch (SQLException ee) {
- }
- }
- /*
- //TODO ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported
- try {
- st = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.CLOSE_CURSORS_AT_COMMIT);
- st.execute("select id, name from zoo");
- rs = st.getResultSet();
- try {
- rs.close();
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- rs.close();
- } catch (SQLException ee) {
- }
- }
- */
-
- try {
- conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY, -100);
- fail("SQLException was not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- }
-
- /**
- * @test java.sql.Connection#prepareStatement(String sql, String[]
- * columnNames)
- *
- * TODO prepareStatement(String sql, String[] columnNames) method is
- * not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "prepareStatement",
- args = {java.lang.String.class, java.lang.String[].class}
- )
- public void testPrepareStatement_String_StringArray() {
- PreparedStatement prst = null;
- PreparedStatement prst1 = null;
- ResultSet rs = null;
- ResultSet rs1 = null;
- ResultSet rs4 = null;
- ResultSet rs5 = null;
-
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- conn.prepareStatement(insert, new String[] { "id", "name",
- "family" });
- } catch (SQLException e) {
- //ok not supported
- }
-
- /*
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- conn.prepareStatement(insert, new String[] {});
- } catch (SQLException e) {
- fail("SQLException is thrown");
- }
-
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- conn.prepareStatement(insert, (String[]) null);
- } catch (SQLException e) {
- fail("SQLException is thrown");
- }
-
- try {
- String insert = "insert into zoo (id, name, family) values (?, ?, ?);";
- prst = conn.prepareStatement(insert, new String[] { "id", "name",
- "family" });
- prst.setInt(1, 8);
- prst.setString(2, "Tuzik");
- prst.setString(3, "dog");
-
- Statement st = conn.createStatement();
- st.execute("select * from zoo");
- rs = st.getResultSet();
- assertEquals(2, getCount(rs));
- prst.execute();
- st.execute("select * from zoo where family = 'dog'");
- rs1 = st.getResultSet();
- assertEquals(1, getCount(rs1));
-
- rs4 = prst.getGeneratedKeys();
- assertEquals(0, getCount(rs4));
-
- prst1 = conn.prepareStatement(insert, new String[] { "id", "name", "" });
- prst1.setInt(1, 5);
- prst1.setString(2, "Layka");
- prst1.setString(3, "dog");
-
- prst1.execute();
-
- rs5 = prst1.getGeneratedKeys();
- assertEquals(0, getCount(rs5));
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- rs.close();
- rs1.close();
- rs4.close();
- rs5.close();
- prst.close();
- prst1.close();
- } catch (Exception ee) {
- }
- }
- */
-
-
- }
-
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported: it should release all resources but it doesn't",
- method = "close",
- args = {}
- )
- public void testClose() {
- try {
-
-
-
- if (! conn.isClosed()) {
- conn.close();
- }
- assertTrue(conn.isClosed());
-
- try {
- conn.prepareCall("select * from zoo");
- fail("Should not be able to prepare query closed connection");
- } catch (SQLException e) {
- //ok
- }
- } catch (SQLException e) {
- fail("Error in implementation");
- e.printStackTrace();
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "isClosed",
- args = {}
- )
- public void testIsClosed() throws Exception {
-
- assertFalse(conn.isClosed());
- conn.close();
- assertTrue(conn.isClosed());
-
- conn = DriverManager.getConnection("jdbc:sqlite:/" + dbFile.getPath());
- assertFalse(conn.isClosed());
- Statement st = conn.createStatement();
- st.execute("select * from zoo");
- }
-
-
- private static class DummySavePoint implements Savepoint{
-
- public int getSavepointId() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public String getSavepointName() {
- // TODO Auto-generated method stub
- return "NoName";
- }
-
- }
-}
diff --git a/luni/src/test/java/tests/sql/PreparedStatementTest.java b/luni/src/test/java/tests/sql/PreparedStatementTest.java
deleted file mode 100755
index cf1b6fc..0000000
--- a/luni/src/test/java/tests/sql/PreparedStatementTest.java
+++ /dev/null
@@ -1,3250 +0,0 @@
-/*
- * Copyright (C) 2007 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.sql;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.math.BigDecimal;
-import java.net.URL;
-import java.sql.Array;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.Date;
-import java.sql.ParameterMetaData;
-import java.sql.PreparedStatement;
-import java.sql.Ref;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-import java.util.Map;
-import java.util.TimeZone;
-
-@TestTargetClass(PreparedStatement.class)
-public class PreparedStatementTest extends SQLTest {
-
- String queryAllSelect = "select * from type";
-
- String[] queries = {
- "create table type (" +
-
- " BoolVal BOOLEAN," + " IntVal INT," + " LongVal LONG,"
- + " Bint BIGINT," + " Tint TINYINT," + " Sint SMALLINT,"
- + " Mint MEDIUMINT, " +
-
- " IntegerVal INTEGER, " + " RealVal REAL, "
- + " DoubleVal DOUBLE, " + " FloatVal FLOAT, "
- + " DecVal DECIMAL, " +
-
- " NumVal NUMERIC, " + " charStr CHAR(20), "
- + " dateVal DATE, " + " timeVal TIME, " + " TS TIMESTAMP, "
- +
-
- " DT DATETIME, " + " TBlob TINYBLOB, " + " BlobVal BLOB, "
- + " MBlob MEDIUMBLOB, " + " LBlob LONGBLOB, " +
-
- " TText TINYTEXT, " + " TextVal TEXT, "
- + " MText MEDIUMTEXT, " + " LText LONGTEXT " + ");",
-
- "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint,"
- + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal,"
- + "NumVal, charStr, dateVal, timeVal, TS,"
- + "DT, TBlob, BlobVal, MBlob, LBlob,"
- + "TText, TextVal, MText, LText"
- + ") "
- + "values (1, -1, 22, 2, 33,"
- + "3, 1, 2, 3.9, 23.2, 33.3, 44,"
- + "5, 'test string', '1799-05-26', '12:35:45', '2007-10-09 14:28:02.0',"
- + "'1221-09-22 10:11:55', 1, 2, 3, 4,"
- + "'Test text message tiny', 'Test text message', 'Test text message medium', 'Test text message long');" };
-
- public void setUp() throws Exception {
- super.setUp();
- Statement st = null;
- try {
- st = conn.createStatement();
- for (int i = 0; i < queries.length; i++) {
- st.execute(queries[i]);
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.toString());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
- }
-
- public void tearDown() {
- Statement st = null;
- try {
- st = conn.createStatement();
- st.execute("drop table if exists type");
- } catch (SQLException e) {
- fail("SQLException is thrown");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- super.tearDown();
- }
-
- /**
- * @test java.sql.PreparedStatement#addBatch()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "addBatch",
- args = {}
- )
- public void testAddBatch() throws SQLException {
- PreparedStatement ps = null;
- try {
- ps = conn
- .prepareStatement("INSERT INTO zoo VALUES (3,'Tuzik', ?);");
- ps.addBatch("INSERT INTO zoo VALUES (?,'Burenka', ?); ");
- ps.addBatch("INSERT INTO zoo VALUES (?,'Mashka','cat')");
- try {
- ps.executeBatch();
- } catch (SQLException sqle) {
- fail("SQLException is thrown for executeBatch()");
- }
- ps.setString(1, "dog");
- Statement st = null;
- try {
- ps.executeBatch();
- st = conn.createStatement();
- st.execute("select * from zoo");
- ResultSet rs = st.getResultSet();
- assertEquals(2, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown for executeBatch()");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- } catch (SQLException e) {
- fail("SQLException is thrown "+e.getMessage());
- } finally {
- try {
- ps.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps = conn
- .prepareStatement("INSERT INTO zoo VALUES (3,'Tuzik', ?);");
- ps.addBatch("");
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- ps.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps = conn
- .prepareStatement("INSERT INTO zoo VALUES (3,'Tuzik', ?);");
- ps.addBatch(null);
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- ps.close();
- } catch (SQLException ee) {
- }
- }
- }
-
-
- /**
- * @test java.sql.PreparedStatement#execute()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "execute",
- args = {}
- )
- @KnownFailure("preparedStatement.execute() does not return false on update.")
- public void testExecute() {
- Statement st = null;
- PreparedStatement ps = null;
- try {
- //update
- String query = "insert into zoo(id, family, name) values(?, ?, 'unknown animal')";
- ps = conn.prepareStatement(query);
- ps.setInt(1, 3);
- ps.setString(2, "No name");
- assertFalse(ps.execute());
- assertEquals(1,ps.getUpdateCount());
-
- // select
- ps = conn.prepareStatement("select * from zoo");
- assertTrue(ps.execute());
- assertEquals(3, getCount(ps.getResultSet()));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- String query = "update zoo set name='Masha', family=? where id=?;";
- ps = conn.prepareStatement(query);
- ps.setString(1, "cat");
- ps.setInt(2, 2);
- assertFalse(ps.execute());
- assertEquals(1, ps.getUpdateCount());
- st = conn.createStatement();
- st.execute("select family from zoo where id=2");
- ResultSet rs = st.getResultSet();
- rs.next();
- assertEquals("cat", rs.getString(1));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- ps.close();
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- conn.createStatement().execute("drop table if exists hutch");
- String query = "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));";
- ps = conn.prepareStatement(query);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- String query = "select name, family from zoo where id = ?";
- ps = conn.prepareStatement(query);
- ps.setInt(1, 1);
- assertTrue(ps.execute());
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- String query = "select name, family from zoo where id = ?";
- ps = conn.prepareStatement(query);
- ps.execute();
- } catch (SQLException e) {
- fail("SQLException is thrown");
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
- //Exception test
- try {
- String query = "update zoo set name='Masha', family=? where id=?;";
- ps = conn.prepareStatement(query);
- ps.setString(1, "cat");
- ps.setInt(2, 2);
- assertTrue(ps.execute("update zoo set name='Masha', family='cat' where id=2;"));
- } catch (SQLException e) {
- // ok Should not provide string argument for a prepared Statement
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
- }
-
-
- /**
- * @test java.sql.PreparedStatement#executeQuery()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "executeQuery",
- args = {}
- )
- public void testExecuteQuery() {
-
- String[] queries2 = {
- "update zoo set name='Masha', family='cat' where id=;",
- "insert into hutch (id, animal_id, address) values (1, ?,'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (?, 1, 'Horse-house, 5');",
- "create view address as select address from hutch where animal_id=?"};
-
- for (int i = 0; i < queries2.length; i++) {
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement(queries2[i]);
- ps.executeQuery();
- fail("SQLException is not thrown for query: " + queries2[i]);
- } catch (SQLException sqle) {
- // expected
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
- }
-
- String query = "select * from zoo where id = ?";
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement(query);
- ps.setInt(1, 1);
- ResultSet rs = ps.executeQuery();
- rs.next();
- assertEquals(1, rs.getInt(1));
- assertEquals("Kesha", rs.getString(2));
- assertEquals("parrot", rs.getString(3));
- } catch (SQLException e) {
- fail("SQLException is thrown for query");
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps = conn.prepareStatement(query);
- ps.setInt(1, 5);
- ResultSet rs = ps.executeQuery();
- assertNotNull(rs);
- assertFalse(rs.next());
- } catch (SQLException e) {
- fail("SQLException is thrown for query");
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
- }
-
- // TODO Crashes VM. Fix later.
- /**
- * @test {@link java.sql.PreparedStatement#executeUpdate()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "executeUpdate",
- args = {}
- )
- public void testExecuteUpdate() {
- String[] queries1 = { "insert into hutch (id, animal_id, address) values (1, ?, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (?, 1, 'Horse-house, 5');",
- "create view address as select address from hutch where animal_id=2" };
-
- for (int i = 0; i < queries1.length; i++) {
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement(queries1[i]);
- ps.executeUpdate();
- fail("SQLException is not thrown for query: " + queries1[i]);
- } catch(SQLException sqle) {
- // expected
- } finally {
- try {
- ps.close();
- } catch(Exception ee) {}
- }
- }
-
- String query = "update zoo set name='Masha', family='cat' where id=?;";
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement(query);
- ps.setInt(1, 2);
- int updateCount = ps.executeUpdate();
- assertEquals(1, updateCount);
- ps.setInt(1, 1);
- int updateCount1 = ps.executeUpdate();
- assertEquals(1, updateCount1);
- } catch (SQLException e) {
- fail("SQLException is thrown for query");
- } finally {
- try {
- ps.close();
- } catch(Exception ee) {}
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#getMetaData()
- *
- * Test Fails:
- * TODO Doesn't pass. according to Java docs:
- * it is possible to invoke the method getMetaData on a
- * PreparedStatement object before it is executed.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMetaData",
- args = {}
- )
- @KnownFailure("it is not possible to invoke the method getMetaData on a " +
- "PreparedStatement object before it is executed: got NullPointerException."+
- "Test passes on RI.")
- public void testGetMetaData() {
- PreparedStatement ps = null;
-
- // Specification testing
-
- try {
- String query = "update zoo set name='Masha', family='cat' where id=?;";
- ps = conn.prepareStatement(query);
- assertNotNull(ps);
- ResultSetMetaData meta = ps.getMetaData();
- assertNotNull(meta);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- sqle.printStackTrace();
- } catch (Exception e) {
- fail("Unspecified Exception: " + e.toString());
- e.printStackTrace();
- } finally {
- try {
- ps.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- String query = "select * from zoo where id = ?";
- ps = conn.prepareStatement(query);
- ResultSetMetaData rsmd = ps.getMetaData();
- assertNotNull(rsmd);
- assertEquals(3, rsmd.getColumnCount());
- assertEquals("id", rsmd.getColumnName(1));
- } catch (SQLException e) {
- fail("SQLException is thrown");
- } finally {
- try {
- ps.close();
- } catch (SQLException ee) {
- }
- }
-
- // ps closed
- try {
- ps.getMetaData();
- fail("SQLException expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- public void testGetParameterMetaData() throws SQLException {
- PreparedStatement ps = null;
- String query = "select * from zoo where id = ?";
- ps = conn.prepareStatement(query);
-
- try {
- ParameterMetaData rsmd = ps.getParameterMetaData();
- } catch (SQLException e) {
- assertEquals("not supported",e.getMessage());
- } finally {
- try {
- ps.close();
- } catch (SQLException ee) {
- }
- }
-
- ps.close();
-
- try {
- ps.getParameterMetaData();
- fail("SQLException expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
-
- /**
- * @test java.sql.PreparedStatement#clearParameters()
- * Test fails: clearparameters should be implemented with Stmt.reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test fails: clearparameters should be implemented with Stmt.reset()",
- method = "clearParameters",
- args = {}
- )
- @KnownFailure("First Exception test fails: parameters not cleared.")
- public void testClearParameters() {
- PreparedStatement ps = null;
- try {
- String query = "select * from zoo where id = ? and family=?";
- ps = conn.prepareStatement(query);
- ps.clearParameters();
- try {
- ps.execute();
- fail("SQLException is not thrown during execute method after calling clearParameters()");
- } catch (SQLException sql) {
-
- }
- ps.setInt(1, 2);
- ps.setString(2, "dog");
- ps.clearParameters();
- try {
- ps.execute();
- fail("SQLException is not thrown during execute method after calling clearParameters()");
- } catch (SQLException sqle) {
- // expected
- }
- ps.setInt(1, 2);
- ps.clearParameters();
- try {
- ps.execute();
- fail("SQLException is not thrown during execute method after calling clearParameters()");
- } catch (SQLException sqle) {
- // expected
- }
- ps.setInt(1, 2);
- ps.setString(2, "cat");
-
- try {
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown during execute method after calling clearParameters() twice");
- }
- } catch (SQLException e) {
- fail("SQLException is thrown");
- } finally {
- try {
- ps.close();
- } catch (SQLException ee) {
- }
- }
-
- }
-
- /**
- * @test java.sql.PreparedStatement#setInt(int parameterIndex, int x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setInt",
- args = {int.class, int.class}
- )
- @KnownFailure("exception test fails")
- public void testSetInt() throws SQLException {
-
- PreparedStatement ps = null;
- Statement st = null;
- try {
- String query = "insert into type (IntVal) values (?);";
- ps = conn.prepareStatement(query);
- try {
- ps.setInt(1, Integer.MAX_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where IntVal="
- + Integer.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- ps.close();
- st.close();
- } catch (Exception ee) {
- }
- }
- ps = conn.prepareStatement(query);
- try {
- ps.setInt(1, Integer.MIN_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where IntVal="
- + Integer.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- ps.close();
- st.close();
- } catch (SQLException ee) {
- }
- }
- ps = conn.prepareStatement(query);
- ps.close();
- try {
- ps.setInt(1, Integer.MIN_VALUE);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setLong(int parameterIndex, long x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLong",
- args = {int.class, long.class}
- )
- @KnownFailure("exception test fails")
- public void testSetLong() {
-
- PreparedStatement ps = null;
- try {
- String query = "insert into type (LongVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setLong(1, Long.MAX_VALUE);
- ps.execute();
- st = conn.createStatement();
- st
- .execute("select * from type where LongVal="
- + Long.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setLong(1, Long.MIN_VALUE);
- ps.execute();
- st = conn.createStatement();
- st
- .execute("select * from type where LongVal="
- + Long.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- ps.close();
- try {
- ps.setLong(1, Long.MIN_VALUE);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (SQLException ee) {
- }
- }
-
- }
-
- /**
- * @throws SQLException
- * @test java.sql.PreparedStatement#setFloat(int parameterIndex, float x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setFloat",
- args = {int.class, float.class}
- )
- @KnownFailure("exception test fails")
- public void testSetFloat() throws SQLException {
- float value1 = 12345678.12345689f;
- float value2 = -12345678.12345689f;
-
- PreparedStatement ps = null;
- String query = "insert into type (FloatVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
-
- Statement st = null;
- try {
- ps.setFloat(1, value1);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where FloatVal=" + value1);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setFloat(1, value2);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where FloatVal=" + value2);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
-
- }
- }
- ps.close();
- try {
- ps.setFloat(1, Float.MIN_VALUE);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @throws SQLException
- * @test java.sql.PreparedStatement#setDouble(int parameterIndex, double x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setDouble",
- args = {int.class, double.class}
- )
- @KnownFailure("exception test fails")
- public void testSetDouble() throws SQLException {
-
- PreparedStatement ps = null;
- String query = "insert into type (DoubleVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
-
- Statement st = null;
- try {
- ps.setDouble(1, Double.MAX_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where DoubleVal="
- + Double.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setDouble(1, Double.MIN_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where DoubleVal="
- + Double.MIN_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- ps.close();
- try {
- ps.setDouble(1, 2.0);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (SQLException ee) {
- }
- }
-
- }
-
- /**
- * @test java.sql.PreparedStatement#setString(int parameterIndex, String x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setString",
- args = {int.class, java.lang.String.class}
- )
- @KnownFailure("exception test fails")
- public void testSetString_charField() {
-
- PreparedStatement ps = null;
-
- try {
- String query = "insert into type (charStr) values (?);";
- ps = conn.prepareStatement(query);
-
- String str = "test^text$test%";
- Statement st = null;
- try {
- ps.setString(1, str);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where charStr='" + str + "'");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, "");
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where charStr=''");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps.setString(1, " ");
- ps.execute();
- st = conn.createStatement();
- st
- .execute("select * from type where charStr=' '");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps.setString(1, " test & text * test % text * test ^ text ");
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown");
- }
-
- try {
- ps.setString(1, null);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- ps.close();
-
- try {
- ps.setString(1, "test text");
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setString(int parameterIndex, String x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setString",
- args = {int.class, java.lang.String.class}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testSetString_tinyTextField() {
-
- PreparedStatement ps = null;
- try {
- String str = "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test";
- String query = "insert into type (TText) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setString(1, str);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where TText='" + str + "'");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, "");
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where TText=''");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps.setString(1, " ");
- ps.execute();
- st = conn.createStatement();
- st
- .execute("select * from type where TText=' '");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps.setString(
- 1,
- "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test*test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test-test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test+test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test?test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test#test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test ");
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown");
- }
-
- try {
- ps.setString(1, null);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- ps.close();
-
- try {
- ps.setString(1, "test text");
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setString(int parameterIndex, String x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setString",
- args = {int.class, java.lang.String.class}
- )
- public void testSetString_textField() {
-
- PreparedStatement ps = null;
- try {
- String str = "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test";
- String query = "insert into type (TextVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setString(1, str);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where TextVal='" + str + "'");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, "");
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where TextVal=''");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps.setString(1, " ");
- ps.execute();
- st = conn.createStatement();
- st
- .execute("select * from type where TextVal=' '");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
-
- try {
- String longString = " test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/";
- for (int i = 0; i < 10; i++) {
- longString += longString;
- }
- ps.setString(1, longString);
- ps.execute();
-
- } catch (SQLException sqle) {
- fail("SQLException is thrown");
- }
-
- try {
- ps.setString(1, null);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- ps.close();
-
- try {
- ps.setString(2, "test text");
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setString(int parameterIndex, String x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setString",
- args = {int.class, java.lang.String.class}
- )
- public void testSetString_mediumTextField() {
-
- PreparedStatement ps = null;
- try {
- String str = "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test";
- String query = "insert into type (MText) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setString(1, str);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where MText='" + str + "'");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, "");
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where MText=''");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, " ");
- ps.execute();
- st = conn.createStatement();
- st
- .execute("select * from type where MText=' '");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, null);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- ps.close();
-
- try {
- ps.setString(2, "test text");
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
-
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setString(int parameterIndex, String x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setString",
- args = {int.class, java.lang.String.class}
- )
- @KnownFailure("exception test fails")
- public void testSetString_longTextField() {
-
- PreparedStatement ps = null;
- try {
- String str = "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test";
- String query = "insert into type (LText) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setString(1, str);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where LText='" + str + "'");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, "");
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where LText=''");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, " ");
- ps.execute();
- st = conn.createStatement();
- st
- .execute("select * from type where LText=' '");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setString(1, null);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- ps.close();
-
- try {
- ps.setString(1, "test text");
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setShort(int parameterIndex, short x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setShort",
- args = {int.class, short.class}
- )
- @KnownFailure("exception test fails")
- public void testSetShort() {
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- PreparedStatement ps2 = null;
- try {
- String query = "insert into type (Sint) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setShort(1, Short.MAX_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where Sint=" + Short.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setShort(1, Short.MIN_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where Sint=" + Short.MIN_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- ps.close();
-
- try {
- ps.setShort(1, Short.MIN_VALUE);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- String query1 = "insert into type (Tint) values (?);";
- ps1 = conn.prepareStatement(query1);
- try {
- ps1.setShort(1, Short.MAX_VALUE);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: "+sqle.getMessage());
- }
-
- String query2 = "insert into type (IntVal) values (?);";
- ps2 = conn.prepareStatement(query2);
- try {
- ps2.setShort(1, Short.MAX_VALUE);
- ps2.execute();
- st = conn.createStatement();
- st
- .execute("select * from type where IntVal="
- + Short.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- ps1.close();
- ps2.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setBoolean(int parameterIndex, boolean
- * x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setBoolean",
- args = {int.class, boolean.class}
- )
- @KnownFailure("exception test fails")
- public void testSetBoolean() {
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (BoolVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setBoolean(1, false);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where BoolVal = 0");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setBoolean(1, true);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where BoolVal= 1");
- ResultSet rs = st.getResultSet();
- assertEquals(2, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- ps.close();
-
- try {
- ps.setBoolean(1, false);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- String query1 = "insert into type (Tint) values (?);";
- ps1 = conn.prepareStatement(query1);
- try {
- ps1.setBoolean(1, true);
- ps1.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- ps1.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setByte(int parameterIndex, byte x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setByte",
- args = {int.class, byte.class}
- )
- @KnownFailure("exception test fails")
- public void testSetByte() {
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (Tint) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setByte(1, Byte.MAX_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where Tint=" + Byte.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps.setByte(1, Byte.MIN_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where Tint=" + Byte.MIN_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- ps.setByte(2, Byte.MAX_VALUE);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
-
- ps.close();
-
- try {
- ps.setByte(1, Byte.MIN_VALUE);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- String query1 = "insert into type (IntVal) values (?);";
- ps1 = conn.prepareStatement(query1);
- try {
- ps1.setByte(1, Byte.MAX_VALUE);
- ps1.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- ps1.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setBytes(int parameterIndex, byte[] x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setBytes",
- args = {int.class, byte[].class}
- )
- @KnownFailure("preparedStatement.execute() does not return false on update.")
- public void testSetBytes() {
-
- byte[] bytesArray = {1, 0};
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (LBlob) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setBytes(1, bytesArray);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- try {
- ps.setBytes(2, bytesArray);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected RuntimeException or SQLException
- }
-
- ps.close();
-
- try {
- ps.setBytes(1, bytesArray);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- String query1 = "insert into type (TBlob) values (?);";
- ps1 = conn.prepareStatement(query1);
-
- try {
- ps.setBytes(1, bytesArray);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- if (ps != null) ps.close();
- if (ps1 != null) ps1.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setBigDecimal(int parameterIndex,
- * BigDecimal x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setBigDecimal",
- args = {int.class, java.math.BigDecimal.class}
- )
- @KnownFailure("preparedStatement.execute() does not return false on update.")
- public void testSetBigDecimal() {
-
- BigDecimal bd = new BigDecimal("50");
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (DecVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setBigDecimal(1, bd);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
-
- try {
- ps.setBigDecimal(2, bd);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- assertEquals("bad parameter index", sqle.getMessage());
- }
-
- try {
- ps.setBigDecimal(-2, bd);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- assertEquals("bad parameter index", sqle.getMessage());
- }
- String query1 = "insert into type (Tint) values (?);";
- ps1 = conn.prepareStatement(query1);
-
- try {
- ps1.setBigDecimal(1, bd);
- } catch (SQLException sqle) {
- fail("SQLException is thrown");
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- if (ps != null) ps.close();
- if (ps1 != null) ps1.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setDate(int parameterIndex, Date x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "First exception test fails: integer and date are incompatible"
- +" by spec.",
- method = "setDate",
- args = {int.class, java.sql.Date.class}
- )
- @KnownFailure("preparedStatement.execute() does not return false on update. "+
- "Setting a data for a declared INTEGER should throw Exception")
- public void testSetDate_int_Date() {
- Calendar cal = new GregorianCalendar(1799, 5, 26);
-
- Date[] dates = {
- new Date(cal.getTimeInMillis()), new Date(Integer.MAX_VALUE),
- new Date(123456789)};
-
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (dateVal) values (?);";
- ps = conn.prepareStatement(query);
-
- for (int i = 0; i < dates.length; i++) {
- try {
- ps.setDate(1, dates[i]);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
- }
-
- try {
- ps.setDate(2, dates[0]);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
-
- ps.close();
-
- try {
- ps.setDate(1, dates[0]);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
-
- String query1 = "insert into type (Tint) values (?);";
- ps1 = conn.prepareStatement(query1);
-
- try {
- ps1.setDate(1, dates[0]);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- assertEquals("SQLite.Exception: error in prepare", sqle
- .getMessage());
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- if (ps != null) ps.close();
- if (ps1 != null) ps1.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setDate(int parameterIndex, Date x,
- * Calendar cal)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setDate",
- args = {int.class, java.sql.Date.class, java.util.Calendar.class}
- )
- @KnownFailure("preparedStatement.execute() does not return false on update.")
- public void testSetDate_int_Date_Calendar() {
-
- Calendar[] cals = { Calendar.getInstance(),
- Calendar.getInstance(Locale.GERMANY),
- Calendar.getInstance(TimeZone.getDefault()) };
- Calendar cal = new GregorianCalendar(1799,5,26);
-
- Date[] dates = { new Date(cal.getTimeInMillis()), new Date(Integer.MAX_VALUE),
- new Date(123456789) };
-
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (dateVal) values (?);";
- ps = conn.prepareStatement(query);
-
- for (int i = 0; i < dates.length; i++) {
-
- try {
- ps.setDate(1, dates[i], cals[i]);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
- }
-
- try {
- ps.setDate(2, dates[0], cals[0]);
- ps.execute();
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
-
- ps.close();
-
- try {
- ps.setDate(1, dates[0], cals[1]);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
- String query1 = "insert into type (Tint) values (?);";
- ps1 = conn.prepareStatement(query1);
-
- try {
- ps1.setDate(1, dates[0], cals[2]);
- ps1.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown");
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- if (ps != null) ps.close();
- if (ps1 != null) ps1.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setNull(int parameterIndex, int sqlType)
- *
- * this test doesn't passed on RI
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setNull",
- args = {int.class, int.class}
- )
- public void testSetNull_int_int() {
-
- PreparedStatement ps = null;
- try {
- String query = "insert into type (BoolVal, IntVal) values ('true', ?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setNull(1, Types.INTEGER);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (BoolVal, LongVal) values ('true', ?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setNull(1, Types.BIGINT);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (BoolVal, DecVal) values ('true', ?)";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setNull(1, Types.DECIMAL);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (BoolVal, dateVal) values ('true', ?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setNull(1, Types.DATE);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (BoolVal, BlobVal) values ('true', ?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setNull(1, Types.BLOB);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (BoolVal, TextVal) values ('true', ?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setNull(1, Types.CHAR);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setNull(int, int, String)}
- *
- * UDTs and Ref types not supported in SQLite v 3
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setNull",
- args = {int.class, int.class, java.lang.String.class}
- )
- public void testSetNullIntintString() {
- // test UDT
- String typeCreationStmtUDT = "CREATE TYPE addressType AS "
- +"( street INTEGER, zip TEXT);";
- String personTableCreateUDT = "CREATE TABLE person (name TEXT, address addressType);";
- Statement st = null;
- PreparedStatement ps = null;
- try {
- st = conn.createStatement();
- st.execute(typeCreationStmtUDT);
- st.execute(personTableCreateUDT);
- fail("UDTs and Ref Types not supported");
- String query = "insert into person (name, address) values ('Hans', ?);";
- ps = conn.prepareStatement(query);
- try {
- ps.setNull(1, Types.DATALINK);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- sqle.printStackTrace();
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- } catch (SQLException e) {
- // UDTs or Ref types not supported
- // ok
- } finally {
- try {
- st.execute("drop table if exists person");
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- // test non UDT REF type Exception checking
- String personTableCreate = "create table person (name TEXT, Address TEXT)";
- try {
-
- st = conn.createStatement();
- st.execute(personTableCreate);
- String insert = "insert into person (name, address) values (?, '1600 Amphitheatre Mountain View');";
- ps = conn.prepareStatement(insert);
- try {
- ps.setNull(1,1, "");
- ps.execute();
- } catch (SQLException sqle) {
- assertEquals("SQLite.Exception: error in step",sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- e.printStackTrace();
- } finally {
- try {
- st.execute("drop table if exists person");
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- // test non UDT REF type OK
-
- personTableCreate = "create table person (name TEXT, Address TEXT)";
- try {
-
- st = conn.createStatement();
- st.execute("drop table if exists person");
- st.execute(personTableCreate);
- String insert = "insert into person (name, address) values (?, '1600 Amphitheatre Mountain View');";
- ps = conn.prepareStatement(insert);
- try {
- ps.setNull(1,1, "");
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- sqle.printStackTrace();
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- e.printStackTrace();
- } finally {
- try {
- st.execute("drop table if exists person");
- ps.close();
- } catch (Exception ee) {
- }
- }
-
-
- }
-
-
- /**
- * @test java.sql.PreparedStatement#setObject(int parameterIndex, Object x)
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setObject",
- args = {int.class, java.lang.Object.class}
- )
- @KnownFailure("exception test fails")
- public void testSetObject_int_Object() {
-
- PreparedStatement ps = null;
- try {
- String query = "insert into type (IntVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setObject(1, Integer.MAX_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where IntVal="
- + Integer.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (LongVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setObject(1, "test text");
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where LongVal='test text';");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- query = "insert into type (DecVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setObject(1, new Object());
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown");
- }
-
- query = "insert into type (dateVal) values (?);";
- ps = conn.prepareStatement(query);
- Date d = new Date(123456789);
-
- try {
- ps.setObject(1, d);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where dateVal='"
- + d.getTime() + "';");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- // this sub test doesn't pass on RI
- query = "insert into type (BlobVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setObject(1, null);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (Exception ee) {
- }
- }
- try {
- ps.setObject(1, "test text");
- fail("Exception not thrown");
- } catch (SQLException e) {
- // ok
- }
-
- }
-
- /**
- * @test java.sql.PreparedStatement#setObject(int parameterIndex, Object x,
- * int targetSqlType)
- *
- * this test doesn't pass on RI
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not all types supported",
- method = "setObject",
- args = {int.class, java.lang.Object.class, int.class}
- )
- @KnownFailure("Fails for Types.DATE")
- public void testSetObject_int_Object_int() {
-
- PreparedStatement ps = null;
- try {
- String query = "insert into type (IntVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setObject(1, Integer.MAX_VALUE, Types.INTEGER);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where IntVal="
- + Integer.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (LongVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setObject(1, "test text", Types.CHAR);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where LongVal='test text';");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (DecVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setObject(1, new Object(), Types.DECIMAL);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
-
- query = "insert into type (dateVal) values (?);";
- ps = conn.prepareStatement(query);
- Date d = new Date(123456789);
-
-
- try {
- ps.setObject(1, d, Types.DATE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where dateVal='"
- + d.getTime() + "';");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- // this sub test doesn't pass on RI
- query = "insert into type (BlobVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setObject(1, "", Types.BLOB);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setObject(1, Integer.MAX_VALUE, Types.INTEGER);
- fail("Exception not thrown");
- } catch (SQLException e) {
- // ok
- }
-
- }
-
- /**
- * @test java.sql.PreparedStatement#setObject(int parameterIndex, Object x,
- * int targetSqlType, int scale)
- *
- * this test doesn't pass on RI
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setObject",
- args = {int.class, java.lang.Object.class, int.class, int.class}
- )
- @KnownFailure("Fails for Types.DATE")
- public void testSetObject_int_Object_int_int() {
-
- PreparedStatement ps = null;
- try {
- String query = "insert into type (IntVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- try {
- ps.setObject(1, Integer.MAX_VALUE, Types.INTEGER,
- Integer.MAX_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where IntVal="
- + Integer.MAX_VALUE);
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (LongVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setObject(1, "test text", Types.CHAR, Integer.MIN_VALUE);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where LongVal='test text';");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- query = "insert into type (DecVal) values (?);";
- ps = conn.prepareStatement(query);
- BigDecimal bd2 = new BigDecimal("12.21");
-
- try {
- ps.setObject(1, bd2, Types.DECIMAL, 2);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
-
- query = "insert into type (dateVal) values (?);";
- ps = conn.prepareStatement(query);
- Date d = new Date(123456789);
- try {
- ps.setObject(1, d , Types.DATE, -1);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where dateVal='"
- + d.getTime() + "';");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- // this sub test doesn't pass on RI
- query = "insert into type(BlobVal) values (?);";
- ps = conn.prepareStatement(query);
-
- try {
- ps.setObject(1, "", Types.BLOB, 0);
- ps.execute();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- ps.setObject(1, "test text", Types.CHAR, Integer.MIN_VALUE);
- fail("Exception not thrown");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setTime(int parameterIndex, Time x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setTime",
- args = {int.class, java.sql.Time.class}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testSetTimeint_Time() {
-
- Time[] times = { new Time(24, 25, 26), new Time(Integer.MAX_VALUE),
- new Time(123456789) };
-
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (timeVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- for (int i = 0; i < times.length; i++) {
- try {
- ps.setTime(1, times[i]);
- ps.execute();
- st = conn.createStatement();
- st.execute("select * from type where timeVal='"
- + times[i].getTime() + "'");
- ResultSet rs = st.getResultSet();
- assertEquals(1, getCount(rs));
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
- }
-
- try {
- ps.setTime(2, times[0]);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected index out of bounds
- }
-
- ps.close();
-
- try {
- ps.setTime(1, times[0]);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- String query1 = "insert into type (Tint) values (?)";
- ps1 = conn.prepareStatement(query1);
-
- try {
- ps1.setTime(1, times[0]);
- ps1.execute();
-
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- ps1.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setTime(int parameterIndex, Time x,
- * Calendar cal)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setTime",
- args = {int.class, java.sql.Time.class, java.util.Calendar.class}
- )
- @KnownFailure("preparedStatement.execute() does not return False on update.")
- public void testSetTime_int_Time_Calendar() {
-
- Calendar[] cals = { Calendar.getInstance(),
- Calendar.getInstance(Locale.GERMANY),
- Calendar.getInstance(TimeZone.getDefault()) };
-
- Time[] times = { new Time(24, 25, 26), new Time(Integer.MAX_VALUE),
- new Time(123456789) };
-
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (timeVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- for (int i = 0; i < times.length; i++) {
- try {
- ps.setTime(1, times[i], cals[i]);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
- }
-
- try {
- ps.setTime(2, times[0], cals[0]);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
-
- ps.close();
-
- try {
- ps.setTime(-2, times[0], cals[1]);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
- String query1 = "insert into type (Tint) values (?);";
- ps1 = conn.prepareStatement(query1);
-
- try {
- ps1.setTime(1, times[0], cals[2]);
- ps1.execute();
-
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- ps1.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.PreparedStatement#setTimestamp(int parameterIndex,
- * Timestamp x)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setTimestamp",
- args = {int.class, java.sql.Timestamp.class}
- )
- @KnownFailure("preparedStatement.execute() does not return false on update.")
- public void testSetTimestamp_int_Timestamp() {
-
- Timestamp[] timestamps = { new Timestamp(2007, 10, 17, 19, 06, 50, 23),
- new Timestamp(123) };
-
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (TS) values (?);";
- ps = conn.prepareStatement(query);
-
- for (int i = 0; i < timestamps.length; i++) {
- try {
- ps.setTimestamp(1, timestamps[i]);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
- }
-
- try {
- ps.setTimestamp(2, timestamps[0]);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
-
- try {
- ps.setTimestamp(-2, timestamps[0]);
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
- String query1 = "insert into type (Tint) values (?);";
- ps1 = conn.prepareStatement(query1);
-
- try {
- ps1.setTimestamp(1, timestamps[0]);
- ps1.execute();
-
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- ps1.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setBlob(int, java.sql.Blob)}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setBlob",
- args = {int.class, java.sql.Blob.class}
- )
- public void testSetBlob() {
- ResultSet res = null;
- PreparedStatement ps = null;
- Blob mock = new MockBlob();
- try {
- String neverExecutedQuery = "select TBlob from type;";
- ps = conn.prepareStatement(neverExecutedQuery);
- ps.setBlob(1,mock);
- fail("Exception expected not supported");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setClob(int, java.sql.Clob)}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setClob",
- args = {int.class, java.sql.Clob.class}
- )
- public void testSetClob() {
- ResultSet res = null;
- PreparedStatement ps = null;
- Clob mock = new MockClob();
- try {
- String neverExecutedQuery = "select TBlob from type;";
- ps = conn.prepareStatement(neverExecutedQuery);
- ps.setClob(1,mock);
- fail("Exception expected not supported");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setTimestamp(int, Timestamp, Calendar)}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setTimestamp",
- args = {int.class, java.sql.Timestamp.class, java.util.Calendar.class}
- )
- @KnownFailure("preparedStatement.execute() does not return false on update.")
- public void testSetTimestampIntTimestampCalendar() {
- Calendar[] cals = { Calendar.getInstance(),
- Calendar.getInstance(Locale.GERMANY),
- Calendar.getInstance(TimeZone.getDefault()) };
-
- Timestamp[] timestamps = { new Timestamp(2007, 10, 17, 19, 06, 50, 23),
- new Timestamp(123) };
-
-
- PreparedStatement ps = null;
- PreparedStatement ps1 = null;
- try {
- String query = "insert into type (timeVal) values (?);";
- ps = conn.prepareStatement(query);
- Statement st = null;
- for (int i = 0; i < timestamps.length; i++) {
- try {
- ps.setTimestamp(1, timestamps[i], cals[i]);
- assertFalse(ps.execute());
- assertTrue(ps.getUpdateCount() > 0);
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
- }
-
- try {
- ps.setTimestamp(2, timestamps[0], cals[0]);
- ps.execute();
- fail("SQLException is not thrown");
- } catch (Exception sqle) {
- // expected
- }
- ps.close();
- try {
- ps.setTimestamp(1, timestamps[0], cals[1]);
- ps.execute();
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- String query1 = "insert into type (Tint) values (?);";
- ps1 = conn.prepareStatement(query1);
-
- try {
- ps1.setTimestamp(1, timestamps[0], cals[2]);
- ps1.execute();
-
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.toString());
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
-
- ps.close();
- ps1.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setURL(int, java.net.URL)}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setURL",
- args = {int.class, java.net.URL.class}
- )
- public void testSetURL() {
- ResultSet res = null;
- PreparedStatement ps = null;
- try {
- String query = "insert into type (TText) values (?);";
- ps = conn.prepareStatement(query);
- ps.setURL(1, new URL("http://www.android.com"));
- fail("Exception expected not supported");
- } catch (SQLException e) {
- //ok
- } catch (Exception e) {
- fail("Error in test setup "+e.getMessage());
- e.printStackTrace();
- }
-
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setArray(int, java.sql.Array)}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setArray",
- args = {int.class, java.sql.Array.class}
- )
- public void testSetArray() {
- ResultSet res = null;
- PreparedStatement ps = null;
- Array a = new MockArray();
- try {
- String query = "insert into type (TText) values (?);";
- ps = conn.prepareStatement(query);
- ps.setArray(1, new MockArray());
- fail("Exception expected not supported");
- } catch (SQLException e) {
- //ok
- } catch (Exception e) {
- fail("Error in test setup "+e.getMessage());
- e.printStackTrace();
- }
-
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setRef(int, java.sql.Ref)}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setRef",
- args = {int.class, java.sql.Ref.class}
- )
- public void testSetRef() {
- ResultSet res = null;
- PreparedStatement ps = null;
- Ref mock = new MockRef();
- try {
- String neverExecutedQuery = "select TBlob from type;";
- ps = conn.prepareStatement(neverExecutedQuery);
- ps.setRef(1,mock);
- fail("Exception expected not supported");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setUnicodeStream(int, java.io.InputStream, int)}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setUnicodeStream",
- args = {int.class, java.io.InputStream.class, int.class}
- )
- public void testSetUnicodestream() {
- ResultSet res = null;
- PreparedStatement ps = null;
- try {
- String query = "insert into type (TText) values (?);";
- ps = conn.prepareStatement(query);
- InputStream file = Class.forName(this.getClass().getName())
- .getResourceAsStream("/blob.c");
- ps.setUnicodeStream(0, file, 100);
- fail("Exception expected not supported");
- } catch (SQLException e) {
- //ok
- } catch (Exception e) {
- fail("Error in test setup "+e.getMessage());
- e.printStackTrace();
- }
- }
-
- public void testSetCharacterSteam() {
- ResultSet res = null;
- PreparedStatement ps = null;
- try {
- String query = "insert into type (TText) values (?);";
- ps = conn.prepareStatement(query);
- InputStream file = Class.forName(this.getClass().getName())
- .getResourceAsStream("/blob.c");
- assertNotNull("Error in test setup: file not found",file);
- Reader reader = new InputStreamReader(file);
- ps.setCharacterStream(1, reader, 100);
- } catch (Exception e) {
- fail("Error in test setup "+e.getMessage());
- e.printStackTrace();
- }
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setAsciiStream(int, InputStream, int)}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setAsciiStream",
- args = {int.class, java.io.InputStream.class, int.class}
- )
- public void testSetAxciiStream() {
- ResultSet res = null;
- PreparedStatement ps = null;
- try {
- String query = "insert into type (TText) values (?);";
- ps = conn.prepareStatement(query);
- InputStream file = Class.forName(this.getClass().getName())
- .getResourceAsStream("/blob.c");
- ps.setAsciiStream(0, file, 100);
- fail("Exception expected not supported");
- } catch (SQLException e) {
- // ok
- } catch (Exception e) {
- fail("Error in test setup "+e.getMessage());
- e.printStackTrace();
- }
- }
-
- /**
- * @test {@link java.sql.PreparedStatement#setBinaryStream(int, InputStream, int)}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setBinaryStream",
- args = {int.class, java.io.InputStream.class, int.class}
- )
- public void testSetBinaryStream() {
-
- ResultSet res = null;
- PreparedStatement ps = null;
- try {
- String query = "insert into type (TText) values (?);";
- ps = conn.prepareStatement(query);
- InputStream file = Class.forName(this.getClass().getName())
- .getResourceAsStream("/blob.c");
- ps.setBinaryStream(0, file, 100);
- fail("Exception expected not supported");
- } catch (SQLException e) {
- // ok
- } catch (Exception e) {
- fail("Error in test setup "+e.getMessage());
- e.printStackTrace();
- }
- }
-
- private class MockRef implements Ref {
-
- public String getBaseTypeName() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object getObject() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object getObject(Map<String, Class<?>> map) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void setObject(Object value) throws SQLException {
- // TODO Auto-generated method stub
-
- }
-
- }
-
- private class MockArray implements Array {
-
- public Object getArray() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object getArray(long index, int count) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object getArray(long index, int count, Map<String, Class<?>> map)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object getArray(Map<String, Class<?>> map) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public int getBaseType() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public String getBaseTypeName() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public ResultSet getResultSet() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public ResultSet getResultSet(long index, int count)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public ResultSet getResultSet(long index, int count,
- Map<String, Class<?>> map) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public ResultSet getResultSet(Map<String, Class<?>> map)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void free() throws SQLException {}
- }
-
- private class MockBlob implements Blob {
-
- public InputStream getBinaryStream() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public byte[] getBytes(long pos, int length) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public long length() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public long position(Blob pattern, long start) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public long position(byte[] pattern, long start) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public OutputStream setBinaryStream(long pos) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public int setBytes(long pos, byte[] theBytes) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public int setBytes(long pos, byte[] theBytes, int offset, int len)
- throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public void truncate(long len) throws SQLException {
- // TODO Auto-generated method stub
-
- }
-
- public void free() throws SQLException {}
-
- public InputStream getBinaryStream(long pos, long length) throws SQLException {
- return null;
- }
- }
-
- private class MockClob implements Clob {
-
- public InputStream getAsciiStream() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Reader getCharacterStream() throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getSubString(long pos, int length) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public long length() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public long position(Clob searchstr, long start) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public long position(String searchstr, long start) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public OutputStream setAsciiStream(long pos) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Writer setCharacterStream(long pos) throws SQLException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public int setString(long pos, String str) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public int setString(long pos, String str, int offset, int len)
- throws SQLException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public void truncate(long len) throws SQLException {
- // TODO Auto-generated method stub
-
- }
-
- public void free() throws SQLException {}
-
- public Reader getCharacterStream(long pos, long length) throws SQLException {
- return null;
- }
- }
-}
diff --git a/luni/src/test/java/tests/sql/ResultSetGetterTests.java b/luni/src/test/java/tests/sql/ResultSetGetterTests.java
deleted file mode 100644
index 5cb50d5..0000000
--- a/luni/src/test/java/tests/sql/ResultSetGetterTests.java
+++ /dev/null
@@ -1,2183 +0,0 @@
-/*
- * Copyright (C) 2007 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.sql;
-
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.sql.DatabaseMetaData;
-import java.sql.Date;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * Tests based on
- * <a href="http://java.sun.com/products/jdbc/download.html">JDBC 1.0 API spec
- * </a> Table 1.0
- */
-@TestTargetClass(ResultSet.class)
-public class ResultSetGetterTests extends SQLTest {
-
- String queryAllSelect = "select * from type";
-
- ResultSet res = null;
-
- Statement st = null;
-
- // Judgement concerning support is based on the result of ResultSet.getOject
- // and Table 1 of JDBC 1.0 spec.
- static boolean booleanSupported = false;
- static boolean blobSupported = false;
- static boolean bigIntSupported = false;
- static boolean smallIntSupported = false;
- static boolean mediumIntSupported = false;
- static boolean realSupported = false;
- static boolean floatSupported = false;
- static boolean dateSupported = false;
- static boolean timeSupported = false;
- static boolean timeStampSupported = false;
- static boolean dateTimeSupported = false;
- static boolean urlSupported= false;
- static boolean tinyIntSupported = false;
- static boolean decimalSupported = false;
- static boolean numericSupported = false;
-
- static List<String> colNames = Arrays.asList("BoolVal", "IntVal", "LongVal",
- "Bint", "Tint", "Sint", "Mint", "IntegerVal", "RealVal",
- "DoubleVal", "FloatVal", "DecVal", "NumVal", "charStr",
- "dateVal", "timeVal", "TS", "DT", "TBlob", "BlobVal", "MBlob",
- "LBlob", "TText", "TextVal", "MText", "LText", "MaxLongVal",
- "MinLongVal", "validURL", "invalidURL");
-
- static List<String> values = Arrays.asList("1", "-1", "22", "2", "33",
- "3","1","2","3.9","23.2","33.3","44",
- "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0",
- "1221-09-22 10:11:55","1","2","3","4","Test text message tiny",
- "Test text", "Test text message medium",
- "Test text message long");
-
- static boolean[] supported = new boolean[]{
- booleanSupported,
- true,
- true,
- bigIntSupported,
- tinyIntSupported,
- smallIntSupported,
- mediumIntSupported,
- true,
- realSupported,
- true,
- floatSupported,
- decimalSupported,
- numericSupported,
- true,
- dateSupported,
- timeSupported,
- timeStampSupported,
- dateTimeSupported,
- blobSupported,
- blobSupported,
- blobSupported,
- blobSupported,
- true,
- true,
- true,
- true,
- bigIntSupported,
- bigIntSupported,
- urlSupported,
- urlSupported
- };
-
- // Not supported: BIT,VARBINARY, LONGVARBINARY, BINARY, VARCHAR, LONGVARCHAR
- static Class[] typeMap = new Class[]{
- java.lang.String.class, //
- java.lang.Integer.class,//Types.INTEGER,
- java.lang.Integer.class, //Types.LONG, not a JDBC 1.0 type
- java.lang.Long.class, // Types.BIGINT,
- java.lang.Byte.class, // Types.TINYINT,
- java.lang.Short.class, // Types.SMALLINT,
- java.lang.Integer.class, //Types.MEDIUMINT, , not a JDBC 1.0 type
- java.lang.Integer.class, // Types.Integer
- java.lang.Float.class, // Types.REAL,
- java.lang.Double.class, // Types.FLOAT,
- java.lang.Double.class, // Types.DOUBLE,
- java.math.BigDecimal.class, // Types.DECIMAL,
- java.math.BigDecimal.class, // Types.NUMERIC,
- java.lang.String.class, // Types.CHAR
- java.sql.Date.class, // Types.DATE,
- java.sql.Time.class, // Types.TIME,
- java.sql.Timestamp.class, // Types.TIMESTAMP,
- java.sql.Date.class, // types datetime, not a JDBC 1.0 type
- java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type
- java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type
- java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type
- java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type
- java.lang.String.class, // not a JDBC 1.0 type
- java.lang.String.class, // not a JDBC 1.0 type
- java.lang.String.class, // not a JDBC 1.0 type
- java.lang.String.class, // not a JDBC 1.0 type
- java.lang.Long.class, // Types.BIGINT,
- java.lang.Long.class, // Types.BIGINT,
- java.net.URL.class, // not a JDBC 1.0 type
- java.net.URL.class // not a JDBC 1.0 type
-
-
- };
-
- // first inserted row : actual values
- // second inserted row: null values
- String[] queries = {
- "create table type (" +
-
- " BoolVal BOOLEAN," + " IntVal INT," + " LongVal LONG,"
- + " Bint BIGINT," + " Tint TINYINT," + " Sint SMALLINT,"
- + " Mint MEDIUMINT, " +
-
- " IntegerVal INTEGER, " + " RealVal REAL, "
- + " DoubleVal DOUBLE, " + " FloatVal FLOAT, "
- + " DecVal DECIMAL, " +
-
- " NumVal NUMERIC, " + " charStr CHAR(20), "
- + " dateVal DATE, " + " timeVal TIME, " + " TS TIMESTAMP, "
- +
-
- " DT DATETIME, " + " TBlob TINYBLOB, " + " BlobVal BLOB, "
- + " MBlob MEDIUMBLOB, " + " LBlob LONGBLOB, " +
-
- " TText TINYTEXT, " + " TextVal TEXT, "
- + " MText MEDIUMTEXT, " + " LText LONGTEXT, " +
-
- " MaxLongVal BIGINT, MinLongVal BIGINT, "+
-
- " validURL URL, invalidURL URL "+
-
- ");"
- ,
-
- "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint,"
- + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal,"
- + "NumVal, charStr, dateVal, timeVal, TS,"
- + "DT, TBlob, BlobVal, MBlob, LBlob,"
- + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal,"
- + " validURL, invalidURL"
- + ") "
- + "values (1, -1, 22, 2, 33,"
- + "3, 1, 2, 3.9, 23.2, 33.3, 44,"
- + "5, 'test string', '1799-05-26', '12:35:45', '2007-10-09 14:28:02.0',"
- + "'1221-09-22 10:11:55', 1, 2, 3, 4,"
- + "'Test text message tiny', 'Test text',"
- + " 'Test text message medium', 'Test text message long', "
- + Long.MAX_VALUE+", "+Long.MIN_VALUE+", "
- + "'http://www.android.com', 'helloWorld' "+
- ");"
- ,
-
- "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint,"
- + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal,"
- + "NumVal, charStr, dateVal, timeVal, TS,"
- + "DT, TBlob, BlobVal, MBlob, LBlob,"
- + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal,"
- +" validURL, invalidURL"
- + ") "
- + "values (null, null, null, null, null,"
- + "null, null, null, null, null, null, null,"
- + "null, null, null, null, null,"
- + "null, null, null, null, null,"
- + "null, null, null, null,null, null, null, null);"
- };
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- try {
- conn.setAutoCommit(false);
- st = conn.createStatement();
- for (int i = 0; i < queries.length; i++) {
- st.execute(queries[i]);
- }
- res = st.executeQuery(queryAllSelect);
- assertTrue(res.next());
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
- }
-
- public void tearDown() {
- try {
- st.execute("drop table if exists type");
- st.close();
- res.close();
- } catch (SQLException e) {
- fail("SQLException is thrown "+e.getMessage());
- } finally {
- try {
- st.close();
- res.close();
- } catch (SQLException ee) {
- }
- }
- super.tearDown();
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getBytes(int)}.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Exception testing",
- method = "getBytes",
- args = {int.class}
- )
- public void testGetBytesInt() {
- int i = 1;
-
-
- // null value
- try {
- i = 1;
- res.next();
- for (String t : values) {
- assertNull(res.getBytes(i));
- i++;
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.close();
- res.getBytes(24);
- fail("Should get Exception");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getBytes(int)}.
- * @throws SQLException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "VARBINARY value",
- method = "getBytes",
- args = {int.class}
- )
- public void testGetBytesIntVarbinary() throws SQLException {
-
- Statement st = null;
- Statement stQuery = null;
- PreparedStatement stPrep = null;
- ResultSet res = null;
-
- // setup
- try {
- String testString = "HelloWorld";
- st = conn.createStatement();
- st.executeUpdate("create table testBinary (VARBINARY value);");
- stPrep = conn
- .prepareStatement("insert into testBinary values (?);");
- stPrep.setBytes(1, testString.getBytes());
- stPrep.execute();
-
- stQuery = conn.createStatement();
- res = stQuery.executeQuery("select * from testBinary");
- try {
- assertTrue(res.next());
- byte[] output = res.getBytes(1);
- String helloTest = new String(output);
- assertNotNull(helloTest);
- assertEquals(testString, helloTest);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- } finally {
- if (res != null) res.close();
- if (stPrep != null) stPrep.close();
- if (st != null) st.close();
- if (stQuery != null) stQuery.close();
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getBytes(int)}.
- * @throws SQLException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "BINARY value",
- method = "getBytes",
- args = {int.class}
- )
- public void testGetBytesIntBinary() throws SQLException {
-
- Statement st = null;
- Statement stQuery = null;
- PreparedStatement stPrep = null;
- ResultSet res = null;
-
-
- // setup
-
- String testString = "HelloWorld";
- st = conn.createStatement();
- st.executeUpdate("create table testBinary (BINARY value);");
- stPrep = conn.prepareStatement("insert into testBinary values (?);");
- stPrep.setBytes(1, testString.getBytes());
- stPrep.execute();
- try {
- stQuery = conn.createStatement();
- res = stQuery.executeQuery("select * from testBinary");
- try {
- assertTrue(res.next());
- byte[] output = res.getBytes(1);
- String helloTest = new String(output);
- assertNotNull(helloTest);
- assertEquals(testString, helloTest);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- } finally {
- if (res != null) res.close();
- if (stPrep != null) stPrep.close();
- if (st != null) st.close();
- if (stQuery != null) stQuery.close();
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getBytes(String)}.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Exception testing",
- method = "getBytes",
- args = {String.class}
- )
- public void testGetBytesString() {
- int i = 1;
-
- // null value
- try {
-
- res.next();
- for (String t : colNames) {
- assertNull(res.getBytes(t));
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.close();
- res.getBytes(colNames.get(24));
- fail("Should get Exception");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getBytes(int)}.
- * @throws SQLException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "VARBINARY value",
- method = "getBytes",
- args = {String.class}
- )
- @KnownFailure("last assertion fails: invalid conversion. Test passes on RI")
- public void testGetBytesStringVarbinary() throws SQLException {
-
- Statement st = null;
- Statement stQuery = null;
- PreparedStatement stPrep = null;
- ResultSet res = null;
-
- // setup
- try {
- String testString = "HelloWorld";
- st = conn.createStatement();
- st.executeUpdate("create table testBinary (VARBINARY value);");
- stPrep = conn
- .prepareStatement("insert into testBinary values (?);");
- stPrep.setBytes(1, testString.getBytes());
- stPrep.execute();
-
- stQuery = conn.createStatement();
- res = stQuery.executeQuery("select value from testBinary");
- try {
- assertTrue(res.next());
- byte[] output = res.getBytes("value");
- String helloTest = new String(output);
- assertNotNull(helloTest);
- assertEquals(testString, helloTest);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- } finally {
- if (res != null) res.close();
- if (stPrep != null) stPrep.close();
- if (st != null) st.close();
- if (stQuery != null) stQuery.close();
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getBytes(int)}.
- * @throws SQLException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "BINARY value",
- method = "getBytes",
- args = {String.class}
- )
- @KnownFailure("last assertion fails: invalid conversion. Test passes on RI")
- public void testGetBytesStringBinary() throws SQLException {
-
- Statement st = null;
- Statement stQuery = null;
- PreparedStatement stPrep = null;
- ResultSet res = null;
-
-
- // setup
-
- String testString = "HelloWorld";
- st = conn.createStatement();
- st.executeUpdate("create table testBinary (BINARY value);");
- stPrep = conn.prepareStatement("insert into testBinary values (?);");
- stPrep.setBytes(1, testString.getBytes());
- stPrep.execute();
- try {
- stQuery = conn.createStatement();
- res = stQuery.executeQuery("select value from testBinary");
- try {
- assertTrue(res.next());
- byte[] output = res.getBytes("value");
- String helloTest = new String(output);
- assertNotNull(helloTest);
- assertEquals(testString, helloTest);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- } finally {
- if (res != null) res.close();
- if (stPrep != null) stPrep.close();
- if (st != null) st.close();
- if (stQuery != null) stQuery.close();
- }
- }
-
- public void testGetConcurrency() {
- try {
- assertEquals(ResultSet.CONCUR_UPDATABLE, res.getConcurrency());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getDate(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDate",
- args = {int.class}
- )
- public void testGetDateInt() {
- try {
-
- GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0);
- Date input = new Date(testCal.getTimeInMillis());
- Date d = res.getDate(15);
- assertEquals(input.toString(),"1799-05-26");
- assertEquals(input,d);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- try {
- Date d = res.getDate(500);
- fail("Should get exception");
- } catch (SQLException e) {
- //ok
- } catch (Exception e) {
- fail("Got unspecified Exception "+ e.getMessage());
- }
-
- // null value
- try {
- assertTrue(res.next());
- Date d = res.getDate(15);
- assertNull(d);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getDate(int, java.util.Calendar)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Not fully supported",
- method = "getDate",
- args = {int.class, java.util.Calendar.class}
- )
- public void testGetDateIntCalendar() {
- GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0);
- try {
-
- Date input = new Date(testCal.getTimeInMillis());
- Date d = res.getDate(15, testCal);
-
- assertEquals(input.toString(),"1799-05-26");
- assertEquals(input,d);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- try {
- Date d = res.getDate(500, testCal);
- fail("Should get exception");
- } catch (SQLException e) {
- //ok
- } catch (Exception e) {
- fail("Got unspecified Exception "+ e.getMessage());
- }
-
-
- // null value
- try {
- assertTrue(res.next());
- Date d = res.getDate(15,testCal);
- assertNull(d);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getDate(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Not fully supported",
- method = "getDate",
- args = {java.lang.String.class}
- )
- public void testGetDateString() {
- try {
- GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0);
- Date input = new Date(testCal.getTimeInMillis());
- Date d = res.getDate("dateVal");
- assertEquals(input.toString(),"1799-05-26");
- assertEquals(input,d);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- try {
- Date d = res.getDate("bla");
- fail("Should get exception");
- } catch (SQLException e) {
- //ok
- }
-
- // null value
- try {
- assertTrue(res.next());
- Date d = res.getDate("dateVal");
- assertNull(d);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getDate(java.lang.String, java.util.Calendar)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDate",
- args = {java.lang.String.class, java.util.Calendar.class}
- )
- public void testGetDateStringCalendar() {
- GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0);
- try {
- Date input = new Date(testCal.getTimeInMillis());
- Date d = res.getDate("dateVal", testCal);
-
- assertEquals(input.toString(),"1799-05-26");
- assertEquals(input,d);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- try {
- Date d = res.getDate("bla", testCal);
- fail("Should get exception");
- } catch (SQLException e) {
- //ok
- }
-
- // null value
- try {
- assertTrue(res.next());
- Date d = res.getDate("dateVal",testCal);
- assertNull(d);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getDouble(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDouble",
- args = {int.class}
- )
- public void testGetDoubleInt() {
-
- double output = 0.0;
- try {
- double[] input = {2.0, 3.9 , 23.2};
-
- output = res.getDouble(8);
- assertEquals(input[0],output);
-
- output = res.getDouble(9);
- assertEquals(input[1],output);
-
- output = res.getDouble(10);
- assertEquals(input[2],output);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getDouble(500);
- } catch (SQLException e) {
- //ok
- }
-
- // null value
- try {
- res.next();
- output = res.getDouble(8);
- assertEquals(0.0,output);
-
- output = res.getDouble(9);
- assertEquals(0.0,output);
-
- output = res.getDouble(10);
- assertEquals(0.0,output);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getDouble(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Not fully supported: eg. getDouble from TinyInt ",
- method = "getDouble",
- args = {java.lang.String.class}
- )
- public void testGetDoubleString() {
- double input = 23.2;
- double output = 0.0;
-
- try{
- output = res.getDouble("DoubleVal");
- assertEquals (input,output);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try{
- output = res.getDouble("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
-
- // null value
- try{
- assertTrue(res.next());
- output = res.getDouble("DoubleVal");
- assertEquals (0.0 , output);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getFloat(int)}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Not fully supported: eg.: getFloat from TinyInt according to JDBC 1.0 spec",
- method = "getFloat",
- args = {int.class}
- )
- public void testGetFloatInt() {
- float defaultF = 0.0f;
- try {
- float[] input = {3.9f, 23.2f, 33.3f};
-
-
- float output = res.getFloat(9);
- assertEquals(input[0], output);
-
- output = res.getFloat(10);
- assertEquals(input[1], output);
-
- output = res.getFloat(11);
- assertEquals(input[2], output);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getFloat(500);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- res.next();
- float output = res.getFloat(8);
- assertEquals(defaultF, output);
-
- output = res.getFloat(9);
- assertEquals(defaultF, output);
-
- output = res.getFloat(10);
- assertEquals(defaultF, output);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getFloat(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Not fully supported",
- method = "getFloat",
- args = {java.lang.String.class}
- )
- public void testGetFloatString() {
- float defaultF = 0.0f;
- try {
- String[] input = {"RealVal", "DoubleVal", "FloatVal"};
- float[] inputF = {3.9f, 23.2f, 33.3f};
-
-
- float output = res.getFloat(input[0]);
- assertEquals(inputF[0], output);
-
- output = res.getFloat(input[1]);
- assertEquals(inputF[1], output);
-
- output = res.getFloat(input[2]);
- assertEquals(inputF[2], output);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getFloat(500);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- res.next();
- float output = res.getFloat(8);
- assertEquals(defaultF, output);
-
- output = res.getFloat(9);
- assertEquals(defaultF, output);
-
- output = res.getFloat(10);
- assertEquals(defaultF, output);
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getInt(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInt",
- args = {int.class}
- )
- public void testGetIntInt() {
-
- // real input val -1, 22, 2, 33,3, 1, 2
- List<Integer> input = Arrays.asList(1, -1, 22, 2, 33,3, 1, 2);
- ListIterator<Integer> it = input.listIterator();
- Double test2 = new Double(23.2);
- try {
- for (int i = 1;i<9;i++ ) {
- assertEquals(it.next().intValue(),res.getInt(i));
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getInt(500);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- res.next();
- for (int i = 2;i<11;i++ ) {
- assertEquals(0,res.getInt(i));
- }
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getInt(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInt",
- args = {java.lang.String.class}
- )
- public void testGetIntString() {
- List<String> inputS = Arrays.asList("BoolVal", "IntVal", "LongVal",
- "Bint", "Tint", "Sint", "Mint", "IntegerVal");
- ListIterator<String> itS = inputS.listIterator();
- List<Integer> input = Arrays.asList(1, -1, 22, 2, 33, 3, 1, 2);
- ListIterator<Integer> it = input.listIterator();
- try {
- while (it.hasNext()) {
- assertEquals(it.next().intValue(), res.getInt(itS.next()));
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getInt("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- res.next();
- for (String s : inputS) {
- assertEquals(0, res.getInt(s));
- }
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getLong(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLong",
- args = {int.class}
- )
- public void testGetLongInt() {
- long maxVal = Long.MAX_VALUE;
- long minVal = Long.MIN_VALUE;
-
- try {
- assertEquals(maxVal, res.getLong(27));
- assertEquals(minVal, res.getLong(28));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getInt(500);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- res.next();
-
- assertEquals(0,res.getLong(27));
- assertEquals(0,res.getLong(28));
-
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getLong(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLong",
- args = {java.lang.String.class}
- )
- public void testGetLongString() {
- long maxVal = Long.MAX_VALUE;
- long minVal = Long.MIN_VALUE;
-
- try {
- assertEquals(maxVal, res.getLong("MaxLongVal"));
- assertEquals(minVal, res.getLong("MinLongVal"));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getInt("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- res.next();
-
- assertEquals(0,res.getLong("MaxLongVal"));
- assertEquals(0,res.getLong("MinLongVal"));
-
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getMetaData()}.
- * type mappings according to
- * http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame8.html
- * Not supported datatypes are not checked.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "checks supported data types ,not supported types are not checked.",
- method = "getMetaData",
- args = {}
- )
- })
- @KnownFailure("Wrong value returned for Long: java.lang.String (VARCHAR)")
- public void testGetMetaData() {
- /*
- * List<String> types = Arrays.asList("BOOLEAN", "INT", "LONG",
- * "BIGINT", "TINYINT", "SMALLINT", "MEDIUMINT", "INTEGER", "REAL",
- * "DOUBLE", "FLOAT", "DECIMAL", "NUMERIC", "CHAR(20)", "DATE", "TIME",
- * "TIMESTAMP", "DATETIME", "TINYBLOB", "BLOB", "MEDIUMBLOB",
- * "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "BIGINT",
- * "BIGINT","URL","URL");
- */
- List<String> types = Arrays.asList("VARCHAR", "INTEGER", "INTEGER",
- "BIGINT", "SMALLINT", "SHORT", "INTEGER", "INTEGER", "FLOAT",
- "DOUBLE", "DOUBLE", "DECIMAL", "NUMERIC", "VARCHAR", "DATE",
- "TIME", "TIMESTAMP", "DATETIME", "BLOB", "BLOB", "BLOB",
- "BLOB", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR", "BIGINT",
- "BIGINT", "URL", "URL");
-
-
-
- ListIterator<String> it = types.listIterator();
- ListIterator<String> colNameIt = colNames.listIterator();
- try {
- ResultSetMetaData meta = res.getMetaData();
- assertNotNull(meta);
- assertEquals("Error in test setup. Columns do not match", types
- .size(), meta.getColumnCount());
- for (int i = 1; i < 31; i++) {
- String colName = colNameIt.next();
- String type = it.next();
- if (supported[i - 1]) {
- assertTrue("Wrong column name at " + i, colName
- .equalsIgnoreCase(meta.getColumnName(i)));
- assertTrue("Wrong type at " + i+" required" +type+ " but is "+meta.getColumnTypeName(i), type.equalsIgnoreCase(meta
- .getColumnTypeName(i)));
- }
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getObject(int)}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not supported types BIT,VARBINARY, LONGVARBINARY, BINARY, VARCHAR, LONGVARCHAR",
- method = "getObject",
- args = {int.class}
- )
- @KnownFailure("Wrong value returned for Long: java.lang.String")
- public void testGetObjectInt() {
-
- try {
- for (int i = 1; i <= typeMap.length; i++) {
- if (supported[i-1]) {
- Object value = res.getObject(i);
- assertTrue("value " + value.getClass().getName()
- + " does not correspond " + typeMap[i-1] + "at "+i, value
- .getClass().equals(typeMap[i-1]));
- }
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getObject(500);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- res.next();
- for (int i = 1; i <= typeMap.length; i++) {
- Object value = res.getObject(i);
- assertNull(value);
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- }
-
-
- /**
- * Test method for {@link java.sql.ResultSet#getObject(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not fully supported",
- method = "getObject",
- args = {java.lang.String.class}
- )
- @KnownFailure("Wrong value returned for Long: java.lang.String")
- public void testGetObjectString() {
- ListIterator<String> colNameIt = colNames.listIterator();
- try {
- for (int i = 1; i <= typeMap.length; i++) {
- String name = colNameIt.next();
- if (supported[i-1]) {
- Object value = res.getObject(name);
- assertTrue("value " + value.getClass().getName()
- + " for "+name+" does not correspond " + typeMap[i-1] + "at "+i, value
- .getClass().equals(typeMap[i-1]));
- }
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getObject("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
-
- try {
- colNameIt = colNames.listIterator();
- res.next();
- for (int i = 1; i <= typeMap.length; i++) {
- Object value = res.getObject(colNameIt.next());
- assertNull(value);
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- }
-
-
- /**
- * Test method for {@link java.sql.ResultSet#getRow()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Exception testing missed, test fails. According to spec afterlast row is 0 but returns 3",
- method = "getRow",
- args = {}
- )
- @KnownFailure("If there is no current row 0 must be returned. res.close() does not wrap up")
- public void testGetRow() {
- try {
- assertEquals(1, res.getRow());
- assertTrue(res.isFirst());
- res.next();
- assertEquals(2, res.getRow());
- assertTrue(res.isLast());
- res.next();
- assertTrue(res.isAfterLast());
- assertEquals(0, res.getRow());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.close();
- res.getRow();
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getShort(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getShort",
- args = {int.class}
- )
- public void testGetShortInt() {
- try {
- short shorty = res.getShort(6);
- assertEquals(3,shorty);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.next();
- short shorty = res.getShort(6);
- assertEquals(0,shorty);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- res.getShort(500);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getShort(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getShort",
- args = {java.lang.String.class}
- )
- public void testGetShortString() {
- try {
- short shorty = res.getShort("Sint");
- assertEquals(3,shorty);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.next();
- short shorty = res.getShort("Sint");
- assertEquals(0,shorty);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- res.getShort("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getStatement()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "test fails. According to spec info.getStatement should return"+
- " null but an exception is thrown: stale result set.",
- method = "getStatement",
- args = {}
- )
- @KnownFailure("According to spec info.getStatement should return null"+
- " but an exception is thrown: stale result set.")
- public void testGetStatement() {
- try {
- DatabaseMetaData meta = conn.getMetaData();
- ResultSet info = meta.getTypeInfo();
- Statement statement2 = info.getStatement();
- assertNull(statement2);
- } catch(SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- Statement statement2 = res.getStatement();
- assertEquals(st, statement2);
- } catch(SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- // exception testing
- try {
- res.close();
- res.getStatement();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getString(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getString",
- args = {int.class}
- )
- public void testGetStringInt() {
- List<String> texts = Arrays.asList("Test text message tiny",
- "Test text", "Test text message medium",
- "Test text message long");
- int i = 23;
-
- //text and exception testing
- try {
- for (String t : texts) {
- assertEquals(t, res.getString(i));
- i++;
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- // the rest: everything should work with getString
-
- texts = Arrays.asList("1", "-1", "22", "2", "33",
- "3","1","2","3.9","23.2","33.3","44",
- "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0",
- "1221-09-22 10:11:55","1","2","3","4");
- i= 1;
-
- try {
- for (String t : texts) {
- assertEquals(t, res.getString(i));
- i++;
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- //null testing
-
- try {
- i = 1;
- res.next();
- for (String t : values) {
- assertNull(res.getString(i));
- i++;
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- // exception testing
- try {
- res.getString(500);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getString(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "exception test missed",
- method = "getString",
- args = {java.lang.String.class}
- )
- public void testGetStringString() {
-
- ListIterator<String> colNameIt = colNames.listIterator();
- try {
- for (String t : values) {
- assertEquals(t, res.getString(colNameIt.next()));
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.next();
-
- for (String name: colNames) {
- assertNull(res.getString(name));
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getString("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getTime(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTime",
- args = {int.class}
- )
- @KnownFailure("getTime should return Time value for a TIMESTAMP type but returns null")
- public void testGetTimeInt() {
- // values "12:35:45", "2007-10-09 14:28:02.0", "1221-09-22 10:11:55"
-
- Calendar cal = new GregorianCalendar();
- cal.clear();
- cal.set(Calendar.HOUR_OF_DAY, 12);
- cal.set(Calendar.MINUTE, 35);
- cal.set(Calendar.SECOND, 45);
- cal.set(Calendar.MILLISECOND, 0);
- // set with calendar value (correct init time: since epoch)
- long millis = cal.getTime().getTime();
- Time t1 = new java.sql.Time(millis);
- assertNotNull("t1", t1);
-
-
- Calendar cal2 = new GregorianCalendar();
- cal2.set(Calendar.YEAR, 2007);
- cal2.set(Calendar.MONTH, Calendar.OCTOBER);
- cal2.set(Calendar.DATE, 9);
- cal2.set(Calendar.HOUR_OF_DAY, 14);
- cal2.set(Calendar.MINUTE, 28);
- cal2.set(Calendar.SECOND, 02);
- cal2.set(Calendar.MILLISECOND, 0);
-
- long millis2 = cal2.getTime().getTime();
- Time t2 = new java.sql.Time(millis2);
-
- int i = 16;
-
- try {
- Time resTime = res.getTime(i);
- assertNotNull("Pos " + i + " null", resTime);
- assertEquals(t1.toString(), resTime.toString());
- assertEquals(t1.getTime(), resTime.getTime());
- assertEquals(t1, resTime);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- // Compatibility Test: TIMESTAMP value
- i = 17;
-
- try {
- Time resTime = res.getTime(i);
- assertNotNull("Pos " + i + " null", resTime);
- assertEquals(t2.toString(), resTime.toString());
- assertEquals(t2.getTime(), resTime.getTime());
- assertEquals(t2, resTime);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- i = 16;
- res.next();
- assertNull(res.getTime(i));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getTime(500);
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getTime(int, java.util.Calendar)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTime",
- args = {int.class, java.util.Calendar.class}
- )
- @KnownFailure("getTime on TIMESTAMP value fails: returns null")
- public void testGetTimeIntCalendar() {
- List<Time> times = new LinkedList<Time>();
- List<Calendar> cals = new LinkedList<Calendar>();
- // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0",
- // "1221-09-22 10:11:55");
-
- Calendar cal1 = new GregorianCalendar();
- cal1.clear();
- cal1.set(Calendar.HOUR_OF_DAY, 12);
- cal1.set(Calendar.MINUTE, 35);
- cal1.set(Calendar.SECOND, 45);
- cal1.set(Calendar.MILLISECOND, 0);
-
- long millis = cal1.getTime().getTime();
- Time t1 = new java.sql.Time(millis);
-
- Calendar cal2 = new GregorianCalendar();
- cal2.set(Calendar.YEAR, 2007);
- cal2.set(Calendar.MONTH, Calendar.OCTOBER);
- cal2.set(Calendar.DATE, 9);
- cal2.set(Calendar.HOUR_OF_DAY, 14);
- cal2.set(Calendar.MINUTE, 28);
- cal2.set(Calendar.SECOND, 02);
- cal2.set(Calendar.MILLISECOND, 0);
-
- long millis2 = cal2.getTime().getTime();
- Time t2 = new java.sql.Time(millis2);
-
- // TIME value
-
- int i = 16;
-
- try {
- Time timeRes = res.getTime(i,new GregorianCalendar());
- assertNotNull(timeRes);
- assertEquals(t1.toString(), timeRes.toString());
- assertEquals(t1.getTime(), timeRes.getTime());
- assertEquals(t1, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- // TIMESTAMP value
- i = 17;
-
- try {
- Time timeRes = res.getTime(i,new GregorianCalendar());
- assertNotNull(timeRes);
- assertEquals(t2.toString(), timeRes.toString());
- assertEquals(t2.getTime(), timeRes.getTime());
- assertEquals(t2, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.next();
-
- for (Calendar c : cals) {
- assertNull(res.getTime(16,c));
- i++;
- }
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getTime(500,Calendar.getInstance());
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getTime(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "getTime",
- args = {java.lang.String.class}
- )
- @KnownFailure("getTime should return a Time value for a TIMESTAMP type but returns null")
- public void testGetTimeString() {
- List<Time> times = new LinkedList<Time>();
-
- List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT");
- Iterator<String> it = stringTimes.iterator();
-
- // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0",
- // "1221-09-22 10:11:55");
-
- Calendar cal = new GregorianCalendar();
- cal.clear();
- cal.set(Calendar.HOUR_OF_DAY, 12);
- cal.set(Calendar.MINUTE, 35);
- cal.set(Calendar.SECOND, 45);
- cal.set(Calendar.MILLISECOND, 0);
-
- long millis = cal.getTime().getTime();
- Time t1 = new java.sql.Time(millis);
-
- String col = it.next();
-
- try {
- Time timeRes = res.getTime(col);
- assertNotNull(timeRes);
- assertEquals(t1.toString(), timeRes.toString());
- assertEquals(t1.getTime(), timeRes.getTime());
- assertEquals(t1, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- Calendar cal2 = new GregorianCalendar();
- cal2.set(Calendar.YEAR, 2007);
- cal2.set(Calendar.MONTH, Calendar.OCTOBER);
- cal2.set(Calendar.DATE, 9);
- cal2.set(Calendar.HOUR_OF_DAY, 14);
- cal2.set(Calendar.MINUTE, 28);
- cal2.set(Calendar.SECOND, 02);
- cal2.set(Calendar.MILLISECOND, 0);
-
- long millis2 = cal.getTime().getTime();
- Time t2 = new java.sql.Time(millis2);
-
- col = it.next();
-
- try {
- Time timeRes = res.getTime(col);
- assertNotNull(timeRes);
- assertEquals(t2.toString(), timeRes.toString());
- assertEquals(t2.getTime(), timeRes.getTime());
- assertEquals(t2, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- res.next();
-
- assertNull(res.getTime(col));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getTime("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getTime(java.lang.String, java.util.Calendar)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Testing getTime with TIME, TIMESTAMP value",
- method = "getTime",
- args = {java.lang.String.class, java.util.Calendar.class}
- )
- @KnownFailure("getTime on TIMESTAMP value fails: returns null")
- public void testGetTimeStringCalendar() {
- List<Time> times = new LinkedList<Time>();
-
- List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT");
- Iterator<String> it = stringTimes.iterator();
- List<Calendar> cals = new LinkedList<Calendar>();
-
- // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0",
- // "1221-09-22 10:11:55");
-
- Calendar cal1 = new GregorianCalendar();
- cal1.clear();
- cal1.set(Calendar.HOUR_OF_DAY, 12);
- cal1.set(Calendar.MINUTE, 35);
- cal1.set(Calendar.SECOND, 45);
- cal1.set(Calendar.MILLISECOND, 0);
-
- long millis = cal1.getTime().getTime();
- Time t1 = new java.sql.Time(millis);
-
- Calendar cal2 = new GregorianCalendar();
- cal2.set(Calendar.YEAR, 2007);
- cal2.set(Calendar.MONTH, Calendar.OCTOBER);
- cal2.set(Calendar.DATE, 9);
- cal2.set(Calendar.HOUR_OF_DAY, 14);
- cal2.set(Calendar.MINUTE, 28);
- cal2.set(Calendar.SECOND, 02);
- cal2.set(Calendar.MILLISECOND, 0);
-
- long millis2 = cal2.getTime().getTime();
- Time t2 = new java.sql.Time(millis2);
-
- // TIME value
- String col = it.next();
-
- try {
- Time timeRes = res.getTime(col, new GregorianCalendar());
- assertNotNull(timeRes);
- assertEquals(t1.toString(), timeRes.toString());
- assertEquals(t1.getTime(), timeRes.getTime());
- assertEquals(t1, res.getTime(col));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- //TIMESTAMP value
- col = it.next();
-
- try {
- Time timeRes = res.getTime(col, new GregorianCalendar());
- assertNotNull(timeRes);
- assertEquals(t2.toString(), timeRes.toString());
- assertEquals(t2.getTime(), timeRes.getTime());
- assertEquals(t2, res.getTime(col));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
-
- try {
- res.next();
- assertNull(res.getTime(stringTimes.get(0), new GregorianCalendar()));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getTime("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getTimestamp(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTimestamp",
- args = {int.class}
- )
- public void testGetTimestampInt() {
- List<Timestamp> times = new LinkedList<Timestamp>();
-
- List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT");
- Iterator<String> it = stringTimes.iterator();
- List<Calendar> cals = new LinkedList<Calendar>();
-
- Calendar cal2 = new GregorianCalendar();
- cal2.set(Calendar.YEAR, 2007);
- cal2.set(Calendar.MONTH, Calendar.OCTOBER);
- cal2.set(Calendar.DATE, 9);
- cal2.set(Calendar.HOUR_OF_DAY, 14);
- cal2.set(Calendar.MINUTE, 28);
- cal2.set(Calendar.SECOND, 02);
- cal2.set(Calendar.MILLISECOND, 0);
-
- long millis = cal2.getTime().getTime();
- Timestamp t2 = new Timestamp(millis);
- times.add(t2);
-
- Calendar cal3 = new GregorianCalendar();
- cal3.set(Calendar.YEAR, 1221);
- cal3.set(Calendar.MONTH, Calendar.SEPTEMBER);
- cal3.set(Calendar.DATE, 22);
- cal3.set(Calendar.HOUR_OF_DAY, 10);
- cal3.set(Calendar.MINUTE, 11);
- cal3.set(Calendar.SECOND, 55);
- cal3.set(Calendar.MILLISECOND, 0);
-
- millis = cal3.getTime().getTime();
- Timestamp t3 = new Timestamp(millis);
- times.add(t3);
- // TIMESTAMP value
- int i = 17;
-
- try {
- Timestamp timeRes = res.getTimestamp(i);
- assertEquals(t2.toString(), timeRes.toString());
- assertEquals(t2.getTime(), timeRes.getTime());
- assertEquals(t2, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- // DATE value
- i = 18;
- try {
- Timestamp timeRes = res.getTimestamp(i);
- assertEquals(t3.toString(), timeRes.toString());
- assertEquals(t3.getTime(), timeRes.getTime());
- assertEquals(t3, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.next();
- assertNull(res.getTime(i));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getTime(500);
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getTimestamp(int, java.util.Calendar)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTimestamp",
- args = {int.class, java.util.Calendar.class}
- )
- public void testGetTimestampIntCalendar() {
- List<Timestamp> times = new LinkedList<Timestamp>();
-
- List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT");
- Iterator<String> it = stringTimes.iterator();
-// List<Calendar> cals = new LinkedList<Calendar>();
-
- Calendar cal2 = new GregorianCalendar();
- cal2.set(Calendar.YEAR, 2007);
- cal2.set(Calendar.MONTH, Calendar.OCTOBER);
- cal2.set(Calendar.DATE, 9);
- cal2.set(Calendar.HOUR_OF_DAY, 14);
- cal2.set(Calendar.MINUTE, 28);
- cal2.set(Calendar.SECOND, 02);
- cal2.set(Calendar.MILLISECOND, 0);
-
- long millis = cal2.getTime().getTime();
- Timestamp t2 = new Timestamp(millis);
- times.add(t2);
- //
- Calendar cal3 = new GregorianCalendar();
- cal3.set(Calendar.YEAR, 1221);
- cal3.set(Calendar.MONTH, Calendar.SEPTEMBER);
- cal3.set(Calendar.DATE, 22);
- cal3.set(Calendar.HOUR_OF_DAY, 10);
- cal3.set(Calendar.MINUTE, 11);
- cal3.set(Calendar.SECOND, 55);
- cal3.set(Calendar.MILLISECOND, 0);
-
- millis = cal3.getTime().getTime();
- Timestamp t3 = new Timestamp(millis);
- times.add(t3);
-
-// cals.add(cal1);
-// cals.add(cal2);
-// cals.add(cal3);
-//
-// ListIterator<Calendar> calIt = cals.listIterator();
-
- int i = 17;
-
- try {
- Timestamp timeRes = res.getTimestamp(i,new GregorianCalendar());
- assertEquals(t2.toString(), timeRes.toString());
- assertEquals(t2, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- i = 18;
-
- try {
- Timestamp timeRes = res.getTimestamp(i,new GregorianCalendar());
- assertEquals(t3.toString(), timeRes.toString());
- assertEquals(t3, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.next();
- assertNull(res.getTime(17,cal2));
- assertNull(res.getTime(18,cal3));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getTime(500);
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getTimestamp(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTimestamp",
- args = {java.lang.String.class}
- )
- public void testGetTimestampString() {
- List<Timestamp> times = new LinkedList<Timestamp>();
-
- List<String> stringTimes = Arrays.asList( "TS", "DT");
- Iterator<String> it = stringTimes.iterator();
-// List<Calendar> cals = new LinkedList<Calendar>();
-
- Calendar cal2 = new GregorianCalendar();
- cal2.set(Calendar.YEAR, 2007);
- cal2.set(Calendar.MONTH, Calendar.OCTOBER);
- cal2.set(Calendar.DATE, 9);
- cal2.set(Calendar.HOUR_OF_DAY, 14);
- cal2.set(Calendar.MINUTE, 28);
- cal2.set(Calendar.SECOND, 02);
- cal2.set(Calendar.MILLISECOND, 0);
-
- long millis = cal2.getTime().getTime();
- Timestamp t2 = new Timestamp(millis);
- times.add(t2);
- //
- Calendar cal3 = new GregorianCalendar();
- cal3.set(Calendar.YEAR, 1221);
- cal3.set(Calendar.MONTH, Calendar.SEPTEMBER);
- cal3.set(Calendar.DATE, 22);
- cal3.set(Calendar.HOUR_OF_DAY, 10);
- cal3.set(Calendar.MINUTE, 11);
- cal3.set(Calendar.SECOND, 55);
- cal3.set(Calendar.MILLISECOND, 0);
-
- millis = cal3.getTime().getTime();
- Timestamp t3 = new Timestamp(millis);
- times.add(t3);
-
- String col = it.next();
-
- try {
- Timestamp timeRes = res.getTimestamp(col);
- assertEquals(t2.toString(), timeRes.toString());
- assertEquals(t2.toString(), timeRes.toString());
- assertEquals(t2.getTime(), timeRes.getTime());
- assertEquals(t2, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- // DATE value
- col = it.next();
-
- try {
- Timestamp timeRes = res.getTimestamp(col);
- assertEquals(t3.toString(), timeRes.toString());
- assertEquals(t3.toString(), timeRes.toString());
- assertEquals(t3.getTime(), timeRes.getTime());
- assertEquals(t3, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.next();
- assertNull(res.getTime(stringTimes.get(0)));
- assertNull(res.getTime(stringTimes.get(1)));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getTime(500);
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getTimestamp(java.lang.String, java.util.Calendar)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTimestamp",
- args = {java.lang.String.class, java.util.Calendar.class}
- )
- public void testGetTimestampStringCalendar() {
- List<Timestamp> times = new LinkedList<Timestamp>();
-
- List<String> stringTimes = Arrays.asList( "TS", "DT");
- Iterator<String> it = stringTimes.iterator();
-
- Calendar cal2 = new GregorianCalendar();
- cal2.set(Calendar.YEAR, 2007);
- cal2.set(Calendar.MONTH, Calendar.OCTOBER);
- cal2.set(Calendar.DATE, 9);
- cal2.set(Calendar.HOUR_OF_DAY, 14);
- cal2.set(Calendar.MINUTE, 28);
- cal2.set(Calendar.SECOND, 02);
- cal2.set(Calendar.MILLISECOND, 0);
-
- long millis = cal2.getTime().getTime();
- Timestamp t2 = new Timestamp(millis);
- times.add(t2);
- //
- Calendar cal3 = new GregorianCalendar();
- cal3.set(Calendar.YEAR, 1221);
- cal3.set(Calendar.MONTH, Calendar.SEPTEMBER);
- cal3.set(Calendar.DATE, 22);
- cal3.set(Calendar.HOUR_OF_DAY, 10);
- cal3.set(Calendar.MINUTE, 11);
- cal3.set(Calendar.SECOND, 55);
- cal3.set(Calendar.MILLISECOND, 0);
-
- millis = cal3.getTime().getTime();
- Timestamp t3 = new Timestamp(millis);
- times.add(t3);
-
- try {
- Timestamp timeRes = res.getTimestamp(stringTimes.get(0),cal2);
- assertEquals(t2.toString(), timeRes.toString());
- assertEquals(t2.getTime(), timeRes.getTime());
- assertEquals(t2, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- // DATE value
- try {
- Timestamp timeRes = res.getTimestamp(stringTimes.get(1),cal3);
- assertEquals(t3.toString(), timeRes.toString());
- assertEquals(t3.getTime(), timeRes.getTime());
- assertEquals(t3, timeRes);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- // calIt = cals.listIterator();
-
- try {
- res.next();
- assertNull(res.getTime(stringTimes.get(0),cal2));
- assertNull(res.getTime(stringTimes.get(1),cal3));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- res.getTime(500);
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getType()}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "SQLException checking missed. Only one ResultSet type supported: default values, Test fails.Not fully supported. Always returns ResultSet.TYPE_SCROLL_INSENSITIVE. Wrong default value.",
- method = "getType",
- args = {}
- )
- @KnownFailure("res.close() does not wrap up")
- public void testGetType() {
- try {
- assertEquals(ResultSet.TYPE_FORWARD_ONLY, res.getType());
- } catch (SQLException e) {
- fail("Unexpected exception " + e.getMessage());
- }
-
- try {
- st.close();
- res.getType();
- fail("Exception not thrown.");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
-
- /**
- * Test method for {@link java.sql.ResultSet#getURL(int)}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not fully supported type",
- method = "getURL",
- args = {int.class}
- )
- public void testGetURLInt() {
- try {
- URL input = new URL("http://www.android.com");
- URL validURL = res.getURL(29);
- assertEquals(input, validURL);
- } catch (SQLException e) {
- fail("Unexpected exception " + e.getMessage());
- } catch (MalformedURLException e) {
- fail("Unexpected exception " + e.getMessage());
- }
-
- try {
- URL invalidURL = res.getURL(30);
- assertNull(invalidURL);
- } catch (SQLException e) {
- // ok
- }
-
- try {
- res.next();
- assertNull(res.getURL(29));
- assertNull(res.getURL(30));
- } catch (SQLException e) {
- fail("Unexpected exception " + e.getMessage());
- }
-
- try {
- res.getURL(500);
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#getURL(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not fully supported type",
- method = "getURL",
- args = {java.lang.String.class}
- )
- public void testGetURLString() {
- try {
- URL input = new URL("http://www.android.com");
- URL validURL = res.getURL("validURL");
- assertEquals(input, validURL);
- } catch (SQLException e) {
- fail("Unexpected exception " + e.getMessage());
- } catch (MalformedURLException e) {
- fail("Unexpected exception " + e.getMessage());
- }
-
- try {
- URL invalidURL = res.getURL("invalidURL");
- assertNull(invalidURL);
- } catch (SQLException e) {
- // ok
- }
-
- try {
- res.next();
- assertNull(res.getURL("validURL"));
- assertNull(res.getURL("invalidURL"));
- } catch (SQLException e) {
- fail("Unexpected exception " + e.getMessage());
- }
-
- try {
- res.getURL("bla");
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
- }
-}
diff --git a/luni/src/test/java/tests/sql/ResultSetMetaDataTest.java b/luni/src/test/java/tests/sql/ResultSetMetaDataTest.java
deleted file mode 100755
index a891b93..0000000
--- a/luni/src/test/java/tests/sql/ResultSetMetaDataTest.java
+++ /dev/null
@@ -1,888 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.sql;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.IOException;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
-
-@TestTargetClass(ResultSetMetaData.class)
-public class ResultSetMetaDataTest extends SQLTest {
-
- ResultSetMetaData rsmd = null;
- Statement st = null;
- ResultSet rs = null;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- try {
- conn.setAutoCommit(false);
- assertFalse(conn.getAutoCommit());
- String query = "select * from zoo";
- st = conn.createStatement();
- st.execute(query);
- rs = st.getResultSet();
- rsmd = rs.getMetaData();
- } catch (SQLException e) {
- fail("Couldn't get ResultSetMetaData object");
- }
- }
-
- @Override
- public void tearDown() {
- try {
- rs.close();
- st.close();
- } catch (SQLException e) {
- fail("Couldn't close Statement object");
- }
- super.tearDown();
- }
-
- /**
- * @test java.sql.ResultSetMetaData#getCatalogName(int column)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Catalog not supported.",
- method = "getCatalogName",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testGetCatalogName() throws SQLException {
- try {
- assertNotNull(rsmd.getCatalogName(1));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- conn.close();
- rsmd.getCatalogName(0);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test java.sql.ResultSetMetaData#getColumnClassName(int column)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getColumnClassName",
- args = {int.class}
- )
- public void testGetColumnClassName() {
- try {
- assertNotNull(rsmd);
- assertEquals(Short.class.getName(), rsmd.getColumnClassName(1));
- assertEquals(String.class.getName(), rsmd.getColumnClassName(2));
- assertEquals(String.class.getName(), rsmd.getColumnClassName(3));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- String name = rsmd.getColumnClassName(0);
- assertNull(name);
- } catch (SQLException e) {
- fail("SQLException is thrown");
- }
-
- try {
- String name = rsmd.getColumnClassName(4);
- assertNull(name);
- } catch (SQLException e) {
- fail("SQLException is thrown");
- }
- }
-
- /**
- * @test java.sql.ResultSetMetaData#getColumnCount()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException checking test fails",
- method = "getColumnCount",
- args = {}
- )
- @KnownFailure("SQLException checking test fails")
- public void testGetColumnCount() {
- try {
- assertEquals(3, rsmd.getColumnCount());
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- rs.close();
- rsmd.getColumnCount();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * @test java.sql.ResultSetMetaData#getColumnLabel(int column)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getColumnLabel",
- args = {int.class}
- )
- @KnownFailure("Column label has format TABLE.COLUMN expected: COLUMN")
- public void testGetColumnLabel() {
- String[] labels = { "id", "name", "family" };
- try {
- for (int i = 0; i < rsmd.getColumnCount(); i++) {
- String label = rsmd.getColumnLabel(i + 1);
- assertTrue("expected "+labels[i] + "got "+label,labels[i].contains(label));
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- String label = rsmd.getColumnLabel(0);
- fail("SQLException expected");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- String label = rsmd.getColumnLabel(5);
- fail("SQLException expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test java.sql.ResultSetMetaData#getColumnName(int column)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getColumnName",
- args = {int.class}
- )
- @KnownFailure("Column label has format TABLE.COLUMN expected: COLUMN")
- public void testGetColumnName() {
- String[] labels = { "id", "name", "family" };
- try {
- for (int i = 0; i < rsmd.getColumnCount(); i++) {
- String name = rsmd.getColumnName(i + 1);
- assertEquals(labels[i], name);
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- String label = rsmd.getColumnName(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- //ok
- }
-
- try {
- String label = rsmd.getColumnName(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test java.sql.ResultSetMetaData#getColumnType(int column)
- *
- * for extensive tests see: ResultSetGetterTest.testGetMetaData
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Not all types supported. More type checking done in ResultSetGetterTest.testGetMetaData",
- method = "getColumnType",
- args = {int.class}
- )
- public void testGetColumnType() {
- int[] types = { Types.SMALLINT, Types.VARCHAR, Types.VARCHAR};
- try {
- for (int i = 0; i < rsmd.getColumnCount(); i++) {
- int type = rsmd.getColumnType(i + 1);
- assertEquals(types[i], type);
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- rsmd.getColumnType(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.getColumnType(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- }
-
- /**
- * @test java.sql.ResultSetMetaData#getColumnTypeName(int column)
- *
- * for extensive tests see: ResultSetGetterTest.testGetMetaData
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not all types supported: see ResultSetGetterTests.",
- method = "getColumnTypeName",
- args = {int.class}
- )
- public void testGetColumnTypeName() {
- try {
- assertTrue("smallint".equalsIgnoreCase(rsmd.getColumnTypeName(1)));
- assertTrue("varchar".equalsIgnoreCase(rsmd.getColumnTypeName(2)));
- assertTrue("varchar".equalsIgnoreCase(rsmd.getColumnTypeName(3)));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- rsmd.getColumnTypeName(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.getColumnTypeName(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- }
-
- /**
- * @throws SQLException
- * @test java.sql.ResultSetMetaData#getTableName(int column)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTableName",
- args = {int.class}
- )
- @KnownFailure("For int = 0, exception expected")
- public void testGetTableName() throws SQLException {
- try {
- assertEquals("zoo", rsmd.getTableName(1));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
- Statement st1 = null;
- ResultSet rs1 = null;
- try {
-
- String create = "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));";
- String insert1 = "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');";
- String insert2 = "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');";
- String query = "select name, animal_id from hutch, zoo where zoo.id = 1" ;
- st1 = conn.createStatement();
- st1.executeUpdate(create);
- st1.executeUpdate(insert1);
- st1.executeUpdate(insert2);
-
- rs1 = st1.executeQuery(query);
- assertNotNull(rs1);
- ResultSetMetaData rsmd1 = rs1.getMetaData();
- assertEquals("zoo", rsmd1.getTableName(1));
- assertEquals("hutch", rsmd1.getTableName(2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- if (rs1 != null) rs1.close();
- if (st1 != null) {
- st1.executeUpdate("drop table if exists hutch");
- st1.close();
- }
- } catch (SQLException sqle) {
- }
- }
- //Exception Text
- try {
- String name = rsmd.getTableName(0);
- fail("SQLException Expected");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#getPrecision(int column)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fails: always returns 0, exception tests fail ,failing statements commented out",
- method = "getPrecision",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testGetPrecision() throws SQLException {
- Statement st2 = null;
- Statement st3 = null;
- ResultSetMetaData rsmd2 = null;
- try {
- int precisionNum = 10;
- int scale = 3;
- int precicisionReal = 10;
- String createTable = "create table DecimalNumbers ( valueDouble DOUBLE,"+
- "valueFloat FLOAT , scaleTest NUMERIC("+precisionNum+","+scale+"),"+
- " valueReal REAL("+precicisionReal+") );";
- String insert = "insert into DecimalNumbers values (1.5, 20.55, 30.666, 100000);";
- String select = "select * from DecimalNumbers;";
- st2 = conn.createStatement();
- st2.executeUpdate(createTable);
- st2.executeUpdate(insert);
-
- st2.close();
-
- st3 = conn.createStatement();
- rs = st3.executeQuery(select);
- assertTrue(rs.next());
- rsmd2 = rs.getMetaData();
-
- assertNotNull(rsmd2);
- assertEquals(precicisionReal, rsmd2.getPrecision(4));
- assertEquals(precisionNum,rsmd2.getPrecision(3));
- assertTrue(rsmd2.getPrecision(2) > 0);
- assertTrue(rsmd2.getPrecision(1) > 0);
-
- // non numeric field
- try {
- rsmd.getPrecision(3);
- } catch (SQLException e1) {
- System.out.println("ResultSetMetaDataTest.testGetPrecision()"+e1.getMessage());
- e1.printStackTrace();
- }
-
-
- try {
- rsmd.getPrecision(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.getPrecision(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
-
- try {
- rs.close();
- rsmd.getPrecision(1);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- } finally {
- if (st2 != null) st2.close();
- if (st3 != null) st3.close();
- }
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#getScale(int column)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fail: always returns 0, exception tests fail"+
- " no positive test case for black-box test possible: no default"+
- " value indicated",
- method = "getScale",
- args = {int.class}
- )
- @KnownFailure("Not supported")
- public void testGetScale() throws SQLException {
- try {
- int scale = 3;
- String createTable = "create table DecimalNumbers ( valueDouble DOUBLE,"+
- "valueFloat FLOAT , scaleTest NUMERIC(10,"+scale+") );";
- String insert = "insert into DecimalNumbers values (1.5, 20.55, 30.666);";
- String select = "select * from DecimalNumbers;";
-
- Statement st = conn.createStatement();
- st.executeUpdate(createTable);
- st.executeUpdate(insert);
-
- rs = st.executeQuery(select);
- ResultSetMetaData rsmd2 = rs.getMetaData();
-
- assertNotNull(rsmd2);
- assertEquals(scale,rsmd2.getScale(3));
- assertTrue(rsmd2.getScale(1) > 0);
- assertTrue(rsmd2.getScale(2) > 0);
-
- try {
- rsmd.getScale(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.getScale(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
-
-
- try {
- conn.close();
- rsmd.getScale(1);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- } finally {
- st.cancel();
- }
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#getSchemaName(int column)}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Tests fail: always returns null. Feature only partially implemented. Missing: positive test.",
- method = "getSchemaName",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testGetSchema() {
-
- try {
- assertNull("Functionality is now supported. Change test",rsmd.getSchemaName(2));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.testGetScale()"+e1.getMessage());
- e1.printStackTrace();
- }
-
-
-
- try {
- rsmd.getSchemaName(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.getSchemaName(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
-
-
- try {
- conn.close();
- rsmd.getSchemaName(2);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#isAutoIncrement(int column)}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Tests fail: always returns false, failing statements commented out. Feature only partially implemented.Missing: Test positive case",
- method = "isAutoIncrement",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testisAutoIncrement() {
-
- try {
- assertFalse(rsmd.isAutoIncrement(1));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.testGetScale()"+e1.getMessage());
- e1.printStackTrace();
- }
-
- /*
- // Exception testing
-
- try {
- rsmd.isAutoIncrement(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.isAutoIncrement(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- */
-
- try {
- conn.close();
- rsmd.getSchemaName(2);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#isCaseSensitive(int column)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fail: always returns false. Exception tests fail, failing statements commented out. Feature only partially implemented.",
- method = "isCaseSensitive",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testIsCaseSensitive() {
-
- try {
- assertFalse(rsmd.isCaseSensitive(1));
- assertFalse(rsmd.isCaseSensitive(2));
- assertFalse(rsmd.isCaseSensitive(3));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.testGetScale()"+e1.getMessage());
- e1.printStackTrace();
- }
-
- /*
- // Exception testing
-
- try {
- rsmd.isCaseSensitive(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.isCaseSensitive(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- */
-
- try {
- conn.close();
- rsmd.isCaseSensitive(1);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#isCurrency(int column)}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Tests fail: always returns false. Exceptions and tests non Numeric fields fail, failing statements commented out. Feature only partially implemented. May be an optional feature.",
- method = "isCurrency",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testIsCurrency() {
-
- try {
- assertFalse(rsmd.isCurrency(1));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.testGetScale()"+e1.getMessage());
- e1.printStackTrace();
- }
-
-
- // Exception testing
-
- try {
- rsmd.isCurrency(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.isCurrency(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
-
-
- try {
- rs.close();
- rsmd.isCurrency(1);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#isDefinitelyWritable(int column)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fail: always returns true. Exceptions fail, Feature only partially implemented.",
- method = "isDefinitelyWritable",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testIsDefinitlyWritable() {
-
- try {
- assertTrue(rsmd.isDefinitelyWritable(1));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.testisDefinitelyWritable()"
- + e1.getMessage());
- e1.printStackTrace();
- }
-
- // Exception testing
-
- try {
- rsmd.isDefinitelyWritable(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.isDefinitelyWritable(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#isNullable(int column)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fail: always returns ResultSetMetaData.columnNullableUnknown. Exceptions fail, failing statements commented out. Feature only partially implemented. May be an optional feature.",
- method = "isNullable",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testIsNullable() {
-
- try {
- assertEquals(ResultSetMetaData.columnNullable, rsmd
- .isNullable(1));
- assertEquals(ResultSetMetaData.columnNullable, rsmd
- .isNullable(2));
- assertEquals(ResultSetMetaData.columnNullable, rsmd
- .isNullable(3));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.isNullable()" + e1.getMessage());
- e1.printStackTrace();
- }
-
- /*
- // Exception testing
-
- try {
- rsmd.isNullable(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.isNullable(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- */
-
- }
-
- // Cannot know from blackbox test if readonly or writable. Exceptions fail, Feature only partially implemented.
- @KnownFailure("not supported")
- public void testIsReadOnly() {
-
- try {
- assertFalse(rsmd.isReadOnly(1));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.isReadOnly" + e1.getMessage());
- e1.printStackTrace();
- }
-
- // Exception testing
-
- try {
- rsmd.isReadOnly(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#isSearchable(int column)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fail: always returns false. Exceptions fail, Feature only partially implemented. Missing: test for searchable field.",
- method = "isSearchable",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testIsSearchable() {
-
- try {
- assertTrue(rsmd.isSearchable(1));
- assertTrue(rsmd.isSearchable(2));
- assertTrue(rsmd.isSearchable(3));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.isReadOnly" + e1.getMessage());
- e1.printStackTrace();
- }
-
- // Exception testing
-
- try {
- rsmd.isSearchable(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- }
-
- /**
- * @test {@link java.sql.ResultSetMetaData#isSigned(int column)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fail: always returns false. Exceptions and tests on non numeric fields fail, Feature only partially implemented. Missing: test positive result.",
- method = "isSigned",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testIsSigned() {
-
- try {
- assertFalse(rsmd.isSigned(1));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.isSigned" + e1.getMessage());
- e1.printStackTrace();
- }
-
- // Exception testing
-
- try {
- rsmd.isSigned(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- }
-
- // Analogous to is Readonly. Exceptions and tests on non numeric fields fail, failing statements commented out. Feature only partially implemented.
- @KnownFailure("not supported")
- public void testIsWritable() {
-
- try {
- assertTrue(rsmd.isWritable(1));
- assertTrue(rsmd.isWritable(2));
- assertTrue(rsmd.isWritable(3));
- } catch (SQLException e1) {
- fail("ResultSetMetaDataTest.isWritable" + e1.getMessage());
- e1.printStackTrace();
- }
-
- // Exception testing
-
- try {
- rsmd.isWritable(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- }
-
-
- /**
- * @test {@link java.sql.ResultSetMetaData#getColumnDisplaySize(int Column)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fail. always returns 0. Missing case where display"+
- " size greater than 0",
- method = "getColumnDisplaySize",
- args = {int.class}
- )
- @KnownFailure("not supported")
- public void testGetColumnDisplaySize() {
- try {
- for (int i = 0; i < rsmd.getColumnCount(); i++) {
- int size = rsmd.getColumnDisplaySize(i + 1);
- assertTrue(size > 0);
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- // Exception testing
-
- try {
- rsmd.getColumnDisplaySize(0);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- try {
- rsmd.getColumnDisplaySize(5);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- }
- }
-
-}
diff --git a/luni/src/test/java/tests/sql/ResultSetTest.java b/luni/src/test/java/tests/sql/ResultSetTest.java
deleted file mode 100644
index 9c91468..0000000
--- a/luni/src/test/java/tests/sql/ResultSetTest.java
+++ /dev/null
@@ -1,827 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.sql;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import tests.support.DatabaseCreator;
-
-import java.io.IOException;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-/**
- * @author andrea@google.com (Your Name Here)
- *
- */
-@TestTargetClass(ResultSet.class)
-public class ResultSetTest extends SQLTest {
-
- ResultSet target = null;
- ResultSet emptyTarget = null;
- ResultSet scrollableTarget = null;
- ResultSet writableTarget = null;
- Statement stForward = null;
- Statement stScrollable = null;
- Statement stWritable = null;
- final String selectAllAnimals = "select id, name from zoo";
- final String selectEmptyTable = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- public void setUp() throws Exception {
- super.setUp();
- try {
- conn.setAutoCommit(false);
- stForward = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY);
- stForward.execute(selectAllAnimals);
- target = stForward.getResultSet();
- assertNotNull(target);
-
- // empty table
- stForward = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY);
- stForward.execute(DatabaseCreator.CREATE_TABLE_SIMPLE1);
- stForward.execute(selectEmptyTable);
- emptyTarget = stForward.getResultSet();
-
- } catch (SQLException e) {
- fail("SQLException was thrown: " + e.getMessage());
- }
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- public void tearDown() {
- super.tearDown();
- try {
- target.close();
- stForward.close();
- } catch (SQLException e) {
- fail("Error in test setup");
- e.printStackTrace();
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#absolute(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "absolute",
- args = {int.class}
- )
- public void testAbsolute() {
- try {
- assertTrue(target.isBeforeFirst());
- assertFalse(target.absolute(0));
- assertTrue(target.absolute(1));
- assertTrue(target.isFirst());
- assertTrue(target.absolute(-1));
- assertTrue(target.isLast());
- target.next();
- assertTrue(target.isAfterLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#afterLast()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "afterLast",
- args = {}
- )
- @KnownFailure("res.close() does not wrap up")
- public void testAfterLast() {
- try {
- target.afterLast();
- assertTrue(target.isAfterLast());
- assertFalse(target.next());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- emptyTarget.afterLast();
- assertFalse(emptyTarget.isAfterLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- target.close();
- target.beforeFirst();
- fail("Should get SQLException");
- } catch (SQLException e) {
-
- }
-
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#beforeFirst()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "beforeFirst",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testBeforeFirst() {
-
- try {
- target.beforeFirst();
- assertTrue(target.isBeforeFirst());
- assertTrue(target.next());
- assertFalse(target.isBeforeFirst());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- emptyTarget.beforeFirst();
- assertFalse(emptyTarget.isBeforeFirst());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- target.close();
- target.beforeFirst();
- fail("Should get SQLException");
- } catch (SQLException e) {
-
- }
-
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#close()}.
- *
- * According to the JDBC spec close has to "Releases this ResultSet
- * object's database and JDBC resources immediately", and this implies
- * the fields should be released as well (so that garbage collection
- * can take place)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "test immediate release of resources, test fails",
- method = "close",
- args = {}
- )
- @KnownFailure("Resultset.close() does not wrap up")
- public void testClose1() {
- try {
- target.close();
- target.next();
- fail("Should get SQLException");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#close()}.
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "test that exception in one prepared statement does not affect second statement. (Atomicity Rule)",
- method = "close",
- args = {}
- )
- public void testClose() {
- PreparedStatement ps1 = null;
- PreparedStatement ps2 = null;
- try {
-
- Statement s = conn.createStatement();
- s.addBatch("create table t1 (a text);");
-
- s.addBatch("insert into t1 values('abc');");
- s.addBatch("insert into t1 values('def');");
- s.addBatch("insert into t1 values('ghi');");
- s.executeBatch();
- s.close();
-
- conn.commit();
- ps1 = conn.prepareStatement("select * from t1");
- ps2 = conn
- .prepareStatement("select * from t1 whe a like '?000'");
-
- ResultSet rs1 = ps1.executeQuery();
-
- try {
- ResultSet rs2 = ps2.executeQuery();
- while (rs2.next()){
- // do nothing
- }
- fail("Should get SQLException");
- } catch (SQLException sqle) {
- // ok : Division by zero
- }
-
- // Although exception happened on ps2 rs1 should still work
- // Isolation property if ACID rules
-
- while (rs1.next()) {
- // do nothing: switching of rows should be possible
- }
-
- conn.commit();
-
- rs1.close();
- ps1.close();
- ps2.close();
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- } finally {
- try {
- if (ps1 != null) ps1.close();
- if (ps2 != null) ps2.close();
- conn.rollback();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
-
-
- /**
- * Test method for {@link java.sql.ResultSet#findColumn(java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "findColumn",
- args = {java.lang.String.class}
- )
- public void testFindColumn() {
- try {
- assertEquals(1, target.findColumn("id"));
- assertEquals(2, target.findColumn("name"));
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- target.findColumn("bla");
- fail("Should get SQLException");
- } catch (SQLException e) {
- // ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#first()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "first",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testtestFirst() {
- try {
- assertFalse(emptyTarget.first());
- assertTrue(target.first());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- target.close();
- // releases all resources such that it can be finalized!
- target.first();
- fail("Should get SQLException");
- } catch (SQLException e) {
-
- }
-
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#isAfterLast()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "isAfterLast",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testtestIsAfterLast() {
- try {
- assertFalse(target.isAfterLast());
- target.absolute(-1); // last
- target.next();
- assertTrue(target.isAfterLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- assertFalse(emptyTarget.isAfterLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- target.close();
- // releases all resources such that it can be finalized!
- target.isAfterLast();
- fail("Should get SQLException");
- } catch (SQLException e) {
-
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#isBeforeFirst()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "isBeforeFirst",
- args = {}
- )
- @KnownFailure("In Second code block assertion fails. statment. "+
- "close() does not wrap up")
- public void testtestIsBeforeFirst() {
- try {
- assertTrue(target.isBeforeFirst());
- assertTrue(target.next());
- assertFalse(target.isBeforeFirst());
- assertTrue(target.isFirst());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- assertTrue(emptyTarget.isBeforeFirst());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- target.close();
- // releases all resources such that it can be finalized!
- target.isBeforeFirst();
- fail("Should get SQLException");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#isFirst()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "isFirst",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testtestIsFirst() {
- try {
- assertFalse(target.isFirst());
- target.first();
- assertTrue(target.isFirst());
- target.next();
- assertFalse(target.isFirst());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- assertFalse(emptyTarget.isFirst());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- target.close();
- // releases all resources such that it can be finalized!
- target.isFirst();
- fail("Should get SQLException");
- } catch (SQLException e) {
-
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#isLast()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails. Test for empty result set fails",
- method = "isLast",
- args = {}
- )
- @KnownFailure("Second block first assertion fails. Is Last should evaluate "+
- "true if the row on which the cursor is actually provides a result."+
- "statment.close() does not wrap up")
- public void testtestIsLast() {
-
- try {
- assertFalse(target.isLast());
- target.absolute(-1);
- assertTrue(target.isLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- //check default value no valid row
- try {
- assertFalse(emptyTarget.isLast());
- assertFalse(emptyTarget.next());
- assertFalse(emptyTarget.isLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
-
- try {
- target.close();
- target.isLast();
- fail("Should get SQLException");
- } catch (SQLException e) {
- // ok
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#last()}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "last",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testtestLast() {
- try {
- assertFalse(target.isLast());
- target.last();
- assertTrue(target.isLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- target.close();
- target.last();
- fail("Should get SQLException");
- } catch (SQLException e) {
- // ok
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#next()}.
- * @throws SQLException
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "SQLException checking test fails. Clearing of warnings"+
- " and closed streams not supported.",
- method = "next",
- args = {}
- )
- @KnownFailure("Resultset.close() does not wrap up")
- public void testNext() throws SQLException {
- try {
- //before first - first
- assertTrue(target.next());
- //first - second
- assertTrue(target.next());
- //after last
- assertFalse(target.next());
- assertTrue(target.isAfterLast());
- // one more
- assertFalse(target.next());
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- assertFalse(emptyTarget.next());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- target.close();
- try {
- target.next();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
- }
-
- public void testPrevious() throws SQLException {
- try {
- target.first();
- target.previous();
- assertTrue(target.isBeforeFirst());
-
- target.last();
- target.next();
- target.previous();
- assertFalse(target.isAfterLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- target.close();
- try {
- target.previous();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#relative(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "test fails: no exception is thrown when moving cursor backwards",
- method = "relative",
- args = {int.class}
- )
- @KnownFailure("no exception is thrown when moving cursor backwards"
- +" on forward only statement")
- public void testRelative() {
-
- // forward only
- try {
- int initialRow = target.getRow();
- assertFalse(target.relative(0));
- assertEquals(initialRow, target.getRow());
-
- assertTrue(target.relative(1));
- assertTrue(target.isFirst());
- assertEquals(1, target.getRow());
-
- assertTrue(target.relative(1));
- assertFalse(target.isFirst());
- assertEquals(2, target.getRow());
-
-
- assertFalse(target.relative(2));
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
-
- try {
- // should not be able to scroll backwards in forward only RS
- target.relative(-2);
- assertEquals(2,target.getRow());
- fail("Should get SQLException");
- } catch (SQLException e) {
- // ok
- } catch (Exception e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- assertFalse(emptyTarget.relative(Integer.MAX_VALUE));
- assertTrue(emptyTarget.isAfterLast());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- } catch (Exception e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#relative(int)}.
- * @throws SQLException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "test fails: does not move before first row on min_value",
- method = "relative",
- args = {int.class}
- )
- @KnownFailure("Scrollable resultSet. Not supported")
- public void testRelativeScrollableResultSet() throws SQLException {
- // scrollable resultSet
- try {
-
- int initialRow = scrollableTarget.getRow();
- assertFalse(scrollableTarget.relative(0));
- assertEquals(initialRow, scrollableTarget.getRow());
-
- assertTrue(scrollableTarget.relative(1));
- assertTrue(scrollableTarget.isFirst());
- assertEquals(1, scrollableTarget.getRow());
-
- assertTrue(scrollableTarget.relative(1));
- assertFalse(scrollableTarget.isFirst());
-
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- assertEquals(2, scrollableTarget.getRow());
- assertFalse(scrollableTarget.relative(2));
- scrollableTarget.relative(-2);
- assertEquals(2,scrollableTarget.getRow());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- assertFalse(scrollableTarget.relative(Integer.MIN_VALUE));
- assertTrue(scrollableTarget.isBeforeFirst());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- } catch (Exception e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- stScrollable.close();
- try {
- scrollableTarget.relative(1);
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
-
-
- /**
- * Test method for {@link java.sql.ResultSet#updateObject(java.lang.String, java.lang.Object)}.
- */
- @KnownFailure("not supported")
- public void testUpdateObjectStringObject() {
- try {
- writableTarget.next();
- writableTarget.updateObject("family","bird");
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- try {
- target.next();
- target.updateObject("family","bird");
- fail("SQLException was not thrown");
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
-
- /**
- * Test method for {@link java.sql.ResultSet#updateString(java.lang.String, java.lang.String)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported. Only exception testing. Missing testing for wrong type",
- method = "updateString",
- args = {java.lang.String.class, java.lang.String.class}
- )
- @KnownFailure("Feature not supported")
- public void testUpdateStringStringString() throws Exception {
- try {
- writableTarget.next();
- writableTarget.updateString("family","bird");
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- // non writable target.
- try {
- target.next();
- target.updateString("family","bird");
- fail("SQLException was not thrown");
- } catch (SQLException e) {
- //ok
- }
-
-
- // writable but wrong type
- try {
- target.updateString(1,"test");
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- }
-
- target.close();
-
- // Exception test
- try {
- target.updateString("family","test");
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * Test method for {@link java.sql.ResultSet#wasNull()}.
- * Spec sais: if something was read... -> if nothing was read it should be false
- * @throws SQLException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "failing tests.",
- method = "wasNull",
- args = {}
- )
- @KnownFailure("the default tests, and exception tests fail.")
- public void testWasNull() throws SQLException {
-
- // Check default: select statement executed but no get on target called yet
- // Either false or throw an exception.
- try {
- assertFalse(target.wasNull());
- } catch (SQLException e) {
- //ok
- }
-
-
- try {
- stForward.execute("insert into zoo values(8,null,null);");
- stForward.execute(selectAllAnimals);
- target = stForward.getResultSet();
- assertNotNull(target);
- assertTrue(target.last());
- assertNull(target.getObject(2));
- assertTrue(target.wasNull());
- assertNotNull(target.getObject(1));
- assertFalse(target.wasNull());
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- e.printStackTrace();
- }
-
- target.close();
- try {
- target.wasNull();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-}
diff --git a/luni/src/test/java/tests/sql/SQLTest.java b/luni/src/test/java/tests/sql/SQLTest.java
deleted file mode 100755
index 1b7d241..0000000
--- a/luni/src/test/java/tests/sql/SQLTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.sql;
-
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.io.File;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-@TestTargetClass(Statement.class)
-public class SQLTest extends TestCase {
- static Connection conn;
-
- @Override
- public void setUp() throws Exception {
- getSQLiteConnection();
- createZoo();
- }
-
- protected File dbFile;
-
- protected void getSQLiteConnection() throws Exception {
- String tmp = System.getProperty("java.io.tmpdir");
- assertEquals(tmp, System.getProperty("java.io.tmpdir"));
- File tmpDir = new File(tmp);
- if (tmpDir.isDirectory()) {
- dbFile = File.createTempFile("sqliteTest", ".db", tmpDir);
- dbFile.deleteOnExit();
- } else {
- System.err.println("java.io.tmpdir does not exist");
- }
-
- Class.forName("SQLite.JDBCDriver").newInstance();
- conn = DriverManager.getConnection("jdbc:sqlite:/" + dbFile.getPath());
- assertNotNull("Connection created ", conn);
- }
-
- @Override
- public void tearDown() {
- Statement st = null;
- try {
- if (! conn.isClosed()) {
- st = conn.createStatement();
- st.execute("drop table if exists zoo");
- }
- } catch (SQLException e) {
- fail("Couldn't drop table: " + e.getMessage());
- } finally {
- try {
- if (st != null) {
- st.close();
- conn.close();
- }
- } catch(SQLException ee) {
- //ignore
- }
- }
- }
-
- public void createZoo() {
-
- String[] queries = {
- "create table zoo(id smallint, name varchar(10), family varchar(10))",
- "insert into zoo values (1, 'Kesha', 'parrot')",
- "insert into zoo values (2, 'Yasha', 'sparrow')" };
-
- Statement st = null;
- try {
- st = conn.createStatement();
- for (int i = 0; i < queries.length; i++) {
- st.execute(queries[i]);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- fail("Unexpected exception: " + e.getMessage());
- } finally {
- try {
- if (st != null) {
- st.close();
- }
- } catch (SQLException ee) {}
- }
- }
-
- public void createProcedure() {
- String proc = "CREATE PROCEDURE welcomeAnimal (IN parameter1 integer, IN parameter2 char(20), IN parameter3 char(20)) "
- + " BEGIN "
- + " INSERT INTO zoo(id, name, family) VALUES (parameter1, parameter2, parameter3); "
- + "SELECT * FROM zoo;" + " END;";
- Statement st = null;
- try {
- st = conn.createStatement();
- st.execute("DROP PROCEDURE IF EXISTS welcomeAnimal");
- st.execute(proc);
- } catch (SQLException e) {
- fail("Unexpected exception: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {}
- }
- }
-
- public int getCount(ResultSet rs) {
- int count = 0;
- try {
- while (rs.next()) {
- count++;
- }
- } catch (SQLException e) {
- fail("SQLException is thrown");
- }
- return count;
- }
-}
diff --git a/luni/src/test/java/tests/sql/StatementTest.java b/luni/src/test/java/tests/sql/StatementTest.java
deleted file mode 100755
index 11ce82c..0000000
--- a/luni/src/test/java/tests/sql/StatementTest.java
+++ /dev/null
@@ -1,1836 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.sql;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.sql.BatchUpdateException;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.sql.SQLWarning;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Vector;
-import java.util.logging.Logger;
-
-@TestTargetClass(Statement.class)
-public class StatementTest extends SQLTest {
-
- /**
- * @test java.sql.Statement#addBatch(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "addBatch",
- args = {java.lang.String.class}
- )
- public void testAddBatch() throws SQLException {
-
- Statement st = null;
- try {
- st = conn.createStatement();
- st.addBatch("INSERT INTO zoo VALUES (3,'Tuzik','dog')");
- st.addBatch("INSERT INTO zoo VALUES (4,'Mashka','cat')");
-
- int[] updateCounts = st.executeBatch();
- assertEquals(2, updateCounts.length);
- assertEquals(1, updateCounts[0]);
- assertEquals(1, updateCounts[1]);
-
- } catch (SQLException e) {
- fail("SQLException is thrown");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- st.addBatch("");
- st.executeBatch();
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- st.addBatch(null);
- st.executeBatch();
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#clearWarnings()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "clearWarnings",
- args = {}
- )
- public void testClearWarnings() {
- Statement st = null;
- try {
- st = conn.createStatement();
- st.execute("select animals from zoo");
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- try {
- st = conn.createStatement();
- st.clearWarnings();
- SQLWarning w = st.getWarnings();
- assertNull(w);
- } catch (Exception e) {
- fail("Unexpected Exception: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#getWarnings()
- *
- * TODO getWarnings is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported. always returns null. ",
- method = "getWarnings",
- args = {}
- )
- public void testGetWarnings() {
-
- Statement st = null;
- int errorCode1 = -1;
- int errorCode2 = -1;
-
- try {
- st = conn.createStatement();
- st.execute("select animals from zoooo");
- fail("SQLException was not thrown");
- } catch (SQLException e) {
- // expected
- errorCode1 = e.getErrorCode();
- }
-
- try {
- SQLWarning wrs = st.getWarnings();
- assertNull(wrs);
- } catch (Exception e) {
- fail("Change test implementation: get warnings is supported now");
- }
- /*
- Statement st = null;
- int errorCode1 = -1;
- int errorCode2 = -1;
-
- try {
- st = conn.createStatement();
- st.execute("select animals from zoooo");
- } catch (SQLException e) {
- // expected
- errorCode1 = e.getErrorCode();
- }
- try {
- SQLWarning wrs = st.getWarnings();
- assertNull(wrs);
- } catch (Exception e) {
- fail("Unexpected Exception: " + e.getMessage());
- }
- try {
- st.execute("select horse from zoooooo");
- } catch (SQLException e) {
- // expected
- errorCode2 = e.getErrorCode();
- }
-
- try {
- SQLWarning wrs = st.getWarnings();
- assertEquals(errorCode1, wrs.getErrorCode());
- assertNotNull(wrs.getNextWarning());
- assertEquals(errorCode2, wrs.getErrorCode());
- } catch (Exception e) {
- fail("Unexpected Exception: " + e.getMessage());
- }
-
- try {
- st.close();
- } catch (SQLException ee) {
- }
- */
-
- }
-
- /**
- * @test {@link java.sql.Statement#clearBatch()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "clearBatch",
- args = {}
- )
- public void testClearBatch() throws SQLException {
-
- Statement st = null;
-
- try {
- st = conn.createStatement();
- st.addBatch("INSERT INTO zoo VALUES (3,'Tuzik','dog'); ");
- st.addBatch("INSERT INTO zoo VALUES (4,'Mashka','cat')");
-
- st.clearBatch();
-
- int[] updateCounts = st.executeBatch();
-
- for (int i = 0; i < updateCounts.length; i++) {
- assertEquals(0, updateCounts[i]);
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- st.addBatch("");
- st.executeBatch();
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- st.addBatch(null);
- st.executeBatch();
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#execute(String sql)
- *
- * TODO not pass on SQLite and RI.
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "execute",
- args = {java.lang.String.class}
- )
- @KnownFailure("Return value wrong for queries below.")
- public void testExecute() throws SQLException {
-
- String[] queries = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "drop table if exists hutch",
- "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));",
- "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');",
- "select animal_id, address from hutch where animal_id=1;",
- "create view address as select address from hutch where animal_id=2",
- "drop view address;", "drop table hutch;" };
- boolean[] results = {false, false, false, false, false, true, false,
- false, false};
-
- for (int i = 0; i < queries.length; i++) {
- Statement st = null;
- try {
- st = conn.createStatement();
- boolean res = st.execute(queries[i]);
- assertEquals("different result for statement no. "+i, results[i], res);
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
- }
-
- String[] inc_queries = {
- "update zoo_zoo set name='Masha', family='cat' where id=5;",
- "drop table hutchNO",
- "insert into hutch (id, animal_id, address) values (1, 2, 10);",
- "select animal_id, from hutch where animal_id=1;",
- "drop view address;", "drop table hutch;", "", null };
-
- for (int i = 0; i < inc_queries.length; i++) {
- Statement st = null;
- try {
- st = conn.createStatement();
- st.execute(inc_queries[i]);
- fail("SQLException is not thrown for query: " + inc_queries[i]);
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
- }
-
- /**
- * @test java.sql.Statement#execute(String sql, int autoGeneratedKeys)
- * TODO not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Missing implementation for Statement.RETURN_GENERATED_KEYS: keys not yet supported",
- method = "execute",
- args = {java.lang.String.class, int.class}
- )
- public void testExecute_String_int() {
- String[] queries = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "drop table if exists hutch",
- "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));",
- "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');",
- "select animal_id, address from hutch where animal_id=1;",
- "create view address as select address from hutch where animal_id=2",
- "drop view address;", "drop table hutch;" };
-
- for (int i = 0; i < queries.length; i++) {
- Statement st = null;
- try {
- st = conn.createStatement();
- st.execute(queries[i], Statement.NO_GENERATED_KEYS);
-
- ResultSet rs = st.getGeneratedKeys();
- assertFalse(rs.next());
-
- } catch (SQLException e) {
- // ok
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- for (int i = 0; i < queries.length; i++) {
- Statement st = null;
- try {
- st = conn.createStatement();
- st.execute(queries[i], Statement.RETURN_GENERATED_KEYS);
- fail("Exception expected: Not supported");
- /*
- ResultSet rs = st.getGeneratedKeys();
- fail("Revise test implemenation for feature impl. has changed");
- assertFalse(rs.next());
- */
- } catch (SQLException e) {
- //ok
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
- }
-
- /**
- * @test java.sql.Statement#getConnection()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "getConnection",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testGetConnection() {
- Statement st = null;
- try {
- st = conn.createStatement();
- assertSame(conn, st.getConnection());
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st.close();
- st.getConnection();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
-
-
- }
-
- /**
- * @test java.sql.Statement#getFetchDirection()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "SQLException test fails. Not all Fetch directions supported.",
- method = "getFetchDirection",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testGetFetchDirection() {
- Statement st = null;
- try {
- st = conn.createStatement();
- assertEquals(ResultSet.FETCH_UNKNOWN, st.getFetchDirection());
- } catch (SQLException e) {
- fail("SQLException is thrown " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- st.setFetchDirection(ResultSet.FETCH_FORWARD);
- assertEquals(ResultSet.FETCH_FORWARD, st.getFetchDirection());
- fail("Exception expected: not supported");
- } catch (SQLException e) {
- // ok
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st.getFetchDirection();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test java.sql.Statement#setFetchDirection(int)
- * TODO not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported. ",
- method = "setFetchDirection",
- args = {int.class}
- )
- public void testSetFetchDirection() {
- Statement st = null;
- try {
- st = conn.createStatement();
- st.setFetchDirection(ResultSet.FETCH_FORWARD);
- st.executeQuery("select * from zoo;");
- fail("Revise test implemenation for feature impl. has changed");
-// assertEquals(ResultSet.FETCH_FORWARD, st.getFetchDirection());
- } catch (SQLException e) {
-// fail("SQLException is thrown: " + e.getMessage());
- //ok
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- /*
- try {
- st = conn.createStatement();
- st.setFetchDirection(-1);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- st.setFetchDirection(100);
- fail("SQLException is not thrown");
- } catch (SQLException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- */
- }
-
- /**
- * @test java.sql.Statement#getFetchSize()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "getFetchSize",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testGetFetchSize() {
- Statement st = null;
- try {
- st = conn.createStatement();
- st.execute("select * from zoo;");
- assertEquals(1, st.getFetchSize());
- } catch (SQLException e) {
- fail("SQLException is thrown");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st.close();
- st.getFetchSize();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.Statement#setFetchSize(int)}
- * TODO not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported.",
- method = "setFetchSize",
- args = {int.class}
- )
- public void testSetFetchSize() {
- Statement st = null;
- try {
- st = conn.createStatement();
- int rows = 100;
- for (int i = 0; i < rows; i++) {
- try {
- st.setFetchSize(i);
- assertEquals(i, st.getFetchSize());
- } catch (SQLException sqle) {
- // getFetchSize() hardcoded to 1.
- assertEquals("fetch size not 1", sqle.getMessage());
- }
- }
- /*
- try {
- st.setFetchSize(-1);
- fail("SQLException is not thrown");
- } catch (SQLException sqle) {
- // expected
- }
- */
-
- } catch (SQLException e) {
- fail("SQLException is thrown");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#setMaxFieldSize(int max)
- * TODO not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "setMaxFieldSize",
- args = {int.class}
- )
- public void testSetMaxFieldSize() {
- Statement st = null;
- try {
- st = conn.createStatement();
- for (int i = 0; i < 300; i += 50) {
- try {
- st.setMaxFieldSize(i);
- assertEquals(i, st.getMaxFieldSize());
- fail("Revise test implemenation for feature impl. has changed");
- } catch (SQLException sqle) {
- assertEquals("not supported", sqle.getMessage());
-// fail("SQLException is thrown: " + sqle.getMessage());
- }
- }
- /*
- try {
- st.setMaxFieldSize(-1);
- fail("SQLException isn't thrown");
- } catch (SQLException sqle) {
- // expecteds
- }
- */
- } catch (SQLException e) {
- fail("Can't create statement, SQLException is thrown: "
- + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#getMaxFieldSize()
- * TODO not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "getMaxFieldSize",
- args = {}
- )
- public void testGetMaxFieldSize() {
- Statement st = null;
- try {
- st = conn.createStatement();
- for (int i = 200; i < 500; i += 50) {
- try {
- st.setMaxFieldSize(i);
- fail("Revise test implemenation for feature impl. has changed");
- } catch (SQLException sqle) {
- assertEquals("not supported", sqle.getMessage());
- // fail("SQLException is thrown: " + sqle.getMessage());
- }
- }
- } catch (SQLException e) {
- fail("Can't create statement, SQLException is thrown: "
- + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- public void testMaxRows() {
- Statement st = null;
- try {
- st = conn.createStatement();
- for (int i = 0; i < 300; i += 50) {
- try {
- st.setMaxRows(i);
- assertEquals(i, st.getMaxRows());
- ResultSet r = st.executeQuery("select * from zoo;");
- int rowCount = 0;
- while (r.next()) {
- ++rowCount;
- }
- if (i == 0) {
- // 0 means unlimited.
- assertTrue("rowCount=" + rowCount + " i=" + i, rowCount > i);
- } else {
- assertTrue("rowCount=" + rowCount + " i=" + i, rowCount <= i);
- }
- r.close();
- } catch (SQLException sqle) {
- fail("SQLException is thrown: " + sqle.getMessage());
- }
- }
- try {
- st.setMaxRows(-1);
- fail("SQLException isn't thrown");
- } catch (SQLException sqle) {
- // expecteds
- }
- } catch (SQLException e) {
- fail("Can't create statement, SQLException is thrown: "
- + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#close()
- * not passed according to Java Docs: should release all resources
- * IMMEDIATELY
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testClose() {
- Statement st = null;
- ResultSet res = null;
- try {
- String[] queries = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');",
- "insert into zoo (id, name, family) values (4, 'Slon', 'elephant');",
- "select * from zoo"};
- st = conn.createStatement();
- for (int i = 0; i < queries.length; i++) {
- st.execute(queries[i]);
- }
- res = st.getResultSet();
- assertNotNull(res);
- assertTrue(res.next());
- st.close();
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- // test release of resources:
- // this code should throw an exception as the db is not available
- // anymore in fact every resource which is used afterwards should throw
- // an SQLException.
- try {
- res.next();
- fail("Exception expected");
- } catch (SQLException e) {
- // ok
- }
-
- }
-
- /**
- * @test java.sql.Statement#execute(String sql, int[] columnIndexes)
- * TODO not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "execute",
- args = {java.lang.String.class, int[].class}
- )
- public void testExecute_String_intArray() {
- Statement st = null;
- try {
- String[] queries = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "insert zoo(id, name, family) values (3, 'Vorobey', 'sparrow');",
- "insert zoo(id, name, family) values (4, 'Slon', 'elephant');",
- "select * from zoo" };
- Vector<int[]> array = new Vector<int[]>();
- array.addElement(null);
- array.addElement(new int[] { 1, 2, 3 });
- array.addElement(new int[] { 1, 2, 10, 100 });
- array.addElement(new int[] {});
-
- st = conn.createStatement();
- for (int i = 0; i < queries.length; i++) {
- st.execute(queries[i], (int[]) array.elementAt(i));
- fail("SQLException expected: not supported");
- }
- /*
- fail("Revise test implemenation for feature impl. has changed");
- assertNotNull(st.getResultSet());
- st.close();
- assertNull(st.getResultSet());
- */
- } catch (SQLException e) {
- // ok: not supported
-// fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#execute(String sql, String[] columnNames)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "execute",
- args = {java.lang.String.class, java.lang.String[].class}
- )
- public void testExecute_String_StringArray() {
- Statement st = null;
- try {
- String[] queries = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "insert zoo(id, name, family) values (3, 'Vorobey', 'sparrow');",
- "insert zoo(id, name, family) values (4, 'Slon', 'elephant');",
- "select * from zoo" };
- Vector<String[]> array = new Vector<String[]>();
- array.addElement(null);
- array.addElement(new String[] { "", "", "", "", "", "", "", "" });
- array.addElement(new String[] { "field 1", "", "field2" });
- array.addElement(new String[] { "id", "family", "name" });
-
- st = conn.createStatement();
- for (int i = 0; i < queries.length; i++) {
- st.execute(queries[i], (String[]) array.elementAt(i));
- fail("Exception expected: not supported");
- }
- fail("Revise test implemenation for feature impl. has changed");
- assertNotNull(st.getResultSet());
- st.close();
- assertNull(st.getResultSet());
- } catch (SQLException e) {
- // ok: not supported
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#executeBatch()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test fails: dropping table hutch affects at least 2 rows.executeBatch() always returns same result: 1.",
- method = "executeBatch",
- args = {}
- )
- @KnownFailure("always returns 1 for no. of updates")
- public void testExecuteBatch() {
-
- String[] queries = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "drop table if exists hutch",
- "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));",
- "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');",
- "create view address as select address from hutch where animal_id=2",
- "drop view address;", "drop table hutch;" };
-
- String[] wrongQueries = {
- "update zoo set name='Masha', family='cat' where;",
- "drop table if exists hutch;",
- "create view address as select address from hutch where animal_id=2;",
- "drop view address;", "drop table hutch;" };
-
- int[] result = { 1, 1, 1, 1, 1, 1, 1, 1 };
- Statement st = null;
-
- //Exception test
- try {
- st = conn.createStatement();
- assertEquals(0, st.executeBatch().length);
- for (int i = 0; i < wrongQueries.length; i++) {
- st.addBatch(wrongQueries[i]);
- }
- st.executeBatch();
- fail("BatchupdateException expected");
- } catch (BatchUpdateException e) {
- //ok
- } catch (SQLException e) {
- fail("BatchupdateException expected");
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- assertEquals(0, st.executeBatch().length);
- for (int i = 0; i < queries.length; i++) {
- st.addBatch(queries[i]);
- }
- int[] resArray = st.executeBatch();
- assertTrue(java.util.Arrays.equals(result, resArray));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- st.addBatch("select * from zoo");
- st.executeBatch();
- fail("Exception expected");
- } catch (BatchUpdateException bue) {
- // ok select returns a resultSet
- } catch (SQLException sqle) {
- fail("Unknown SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- //Exception test
- try {
- st.close();
- st.executeBatch();
- fail("SQLException not thrown");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test java.sql.Statement#executeQuery(String sql)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Not according to spec.",
- method = "executeQuery",
- args = {java.lang.String.class}
- )
- @KnownFailure("Does throw an exception on non select statment.")
- public void testExecuteQuery_String() {
-
- String[] queries1 = { "select * from zoo",
- "select name, family from zoo where id = 1" };
-
- String[] queries2 = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "drop table if exists hutch",
- "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));",
- "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');",
- "create view address as select address from hutch where animal_id=2",
- "drop view address;", "drop table hutch;", "select from zoo" };
-
- Statement st = null;
-
- try {
- st = conn.createStatement();
- for (int i = 0; i < queries1.length; i++) {
- try {
- ResultSet rs = st.executeQuery(queries1[i]);
- assertNotNull(rs);
- } catch (SQLException sqle) {
- fail("SQLException is thrown for query: " + queries1[i]);
- }
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- // queries which do not produce a ResultSet -> exception testing
-
- try {
- st = conn.createStatement();
- for (int i = 0; i < queries2.length; i++) {
- try {
- ResultSet rs = st.executeQuery(queries2[i]);
- assertNotNull(rs);
- fail("SQLException is not thrown for query: " + queries2[i]);
- } catch (SQLException sqle) {
- // expected
- }
- }
- } catch (SQLException sqle) {
- fail("Unknown SQLException is thrown: " + sqle.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- }
-
- /**
- * @throws SQLException
- * @test java.sql.Statement#executeUpdate(String sql)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "impl not according to spec.",
- method = "executeUpdate",
- args = {java.lang.String.class}
- )
- @KnownFailure("Spec is not precise enough: should be: number of rows affected."+
- " eg. to be consistent for deletes: 'delete from s1;' should be different from "+
- "'delete from s1 where c1 = 1;' ")
- public void testExecuteUpdate_String() throws SQLException {
-
- String[] queries1 = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "drop table if exists hutch",
- "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));",
- "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');",
- "create view address as select address from hutch where animal_id=2;",
- "drop view address;", "drop table hutch;"};
-
- String queries2 = "select * from zoo;";
-
- Statement st = null;
- try {
- st = conn.createStatement();
- for (int i = 0; i < queries1.length; i++) {
- try {
- int count = st.executeUpdate(queries1[i]);
- assertTrue(count > 0);
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
- }
-
- try {
- assertEquals(0, st.executeUpdate(queries2));
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (Exception ee) {
- }
- }
-
- // test return value for specific numbers
-
- Statement stat = conn.createStatement();
-
- // there are 0 rows created therefore 0 should be returned.
- assertEquals(0 ,stat.executeUpdate("create table s1 (c1);"));
-
- assertEquals(1, stat.executeUpdate("insert into s1 values (0);"));
- assertEquals(1, stat.executeUpdate("insert into s1 values (1);"));
- assertEquals(1, stat.executeUpdate("insert into s1 values (2);"));
- assertEquals(1,stat.executeUpdate("delete from s1 where c1 = 1;"));
- assertEquals(2, stat.executeUpdate("update s1 set c1 = 5;"));
-
- // analogous to statemente before, delete all should return 2
- assertEquals(2,stat.executeUpdate("delete from s1;"));
-
- // there are no rows in table: 0 should be returned
- assertEquals(0, stat.executeUpdate("drop table s1;"));
-
- stat.executeUpdate("create table s1 (c1);");
- stat.executeUpdate("insert into s1 values (0);");
- stat.executeUpdate("insert into s1 values (1);");
- stat.executeUpdate("insert into s1 values (2);");
-
- // there are 3 rows in table: 3 should be returned
- assertEquals(3, stat.executeUpdate("drop table s1;"));
-
- stat.close();
- }
-
- /**
- * @test java.sql.Statement#executeUpdate(String sql, int[] columnIndexes)
- *
- * TODO executeUpdate(String sql, int[] columnIndexes) is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "executeUpdate",
- args = {java.lang.String.class, int[].class}
- )
- public void testExecuteUpdate_String_intArray() throws SQLException {
- Statement st = null;
- try {
- String[] queries1 = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "drop table if exists hutch",
- "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));",
- "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');",
- "create view address as select address from hutch where animal_id=2",
- "drop view address;", "drop table hutch;" };
-
- Vector<int[]> array = new Vector<int[]>();
- array.addElement(null);
- array.addElement(new int[] { 1, 2, 3 });
- array.addElement(new int[] { 1, 2, 10, 100 });
- array.addElement(new int[] {});
- array.addElement(new int[] { 100, 200 });
- array.addElement(new int[] { -1, 0 });
- array.addElement(new int[] { 0, 0, 0, 1, 2, 3 });
- array.addElement(new int[] { -100, -200 });
-
- st = conn.createStatement();
- for (int i = 0; i < queries1.length; i++) {
- st.executeUpdate(queries1[i], (int[]) array.elementAt(i));
- fail("Exception expected");
- }
- } catch (SQLFeatureNotSupportedException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#executeUpdate(String sql, int autoGeneratedKeys)
- *
- * TODO executeUpdate(String sql, int autoGeneratedKeys) is not supported
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not supported",
- method = "executeUpdate",
- args = {java.lang.String.class, int.class}
- )
- public void testExecuteUpdate_String_int() {
- String[] queries = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "drop table if exists hutch",
- "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));",
- "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');",
- "select animal_id, address from hutch where animal_id=1;",
- "create view address as select address from hutch where animal_id=2",
- "drop view address;", "drop table hutch;" };
-
- Statement st = null;
- ResultSet rs = null;
- try {
- st = conn.createStatement();
- st.executeUpdate(queries[1], Statement.NO_GENERATED_KEYS);
- rs = st.getGeneratedKeys();
- assertFalse(rs.next());
- fail("Exception expected: not supported");
- } catch (SQLException e) {
- //ok
- } finally {
- try {
- rs.close();
- st.close();
- } catch (Exception ee) {
- }
- }
-
- try {
- st = conn.createStatement();
- st.executeUpdate(queries[1], Statement.RETURN_GENERATED_KEYS);
- rs = st.getGeneratedKeys();
- assertTrue(rs.next());
- fail("Exception expected: not supported");
- } catch (SQLException e) {
- //ok
- } finally {
- try {
- rs.close();
- st.close();
- } catch (Exception ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#executeUpdate(String sql, String[] columnNames)
- *
- * TODO executeUpdate(String sql, String[] columnNames) is not supported
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not supported",
- method = "executeUpdate",
- args = {java.lang.String.class, java.lang.String[].class}
- )
- public void testExecuteUpdate_String_StringArray() throws SQLException {
- Statement st = null;
- try {
- String[] queries = {
- "update zoo set name='Masha', family='cat' where id=2;",
- "drop table if exists hutch",
- "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));",
- "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');",
- "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');",
- "create view address as select address from hutch where animal_id=2",
- "drop view address;", "drop table hutch;" };
-
- Vector<String[]> array = new Vector<String[]>();
- array.addElement(null);
- array.addElement(new String[] { "", "", "", "", "", "", "", "" });
- array.addElement(new String[] { "field 1", "", "field2" });
- array.addElement(new String[] { "id", "family", "name" });
- array
- .addElement(new String[] { "id", null, "family", null,
- "name" });
- array.addElement(new String[] { "id", " ", "name" });
- array.addElement(new String[] { null, null, null, null });
- array.addElement(new String[] { " ", "123 21", "~!@#$%^&*()_+ ",
- null });
-
- st = conn.createStatement();
- for (int i = 0; i < queries.length; i++) {
- st.executeUpdate(queries[i], (String[]) array.elementAt(i));
- fail("Revise test implemenation for feature impl. has changed");
- }
- } catch (SQLFeatureNotSupportedException e) {
- // expected
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- }
-
- /**
- * @test java.sql.Statement#getUpdateCount()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException test fails",
- method = "getUpdateCount",
- args = {}
- )
- @KnownFailure("statment.close() does not wrap up")
- public void testGetUpdateCount() {
- Statement st = null;
- try {
- String query = "update zoo set name='Masha', family='cat' where id=2;";
- st = conn.createStatement();
- st.executeUpdate(query);
- assertEquals(1, st.getUpdateCount());
- query = "update zoo set name='Masha', family='cat' where id=5;";
- st.executeUpdate(query);
- assertEquals(0, st.getUpdateCount());
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
- // statment closed : Exception test
- try {
- st.getUpdateCount();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.Statement#getGeneratedKeys()}
- *
- * TODO getGeneratedKeys() is not supported
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not supported",
- method = "getGeneratedKeys",
- args = {}
- )
- public void testGeneratedKeys() throws SQLException {
- Statement st = null;
- try {
- String insert = "insert into zoo (id, name, family) values (8, 'Tuzik', 'dog');";
- st = conn.createStatement();
- assertNull(st.getGeneratedKeys());
- fail("Fail: statement does not fail");
- } catch (SQLFeatureNotSupportedException e) {
- // expected
- }
- }
-
- /**
- * @test {@link java.sql.Statement#setCursorName(String)}
- *
- * TODO setCursorName() is not supported
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not supported",
- method = "setCursorName",
- args = {java.lang.String.class}
- )
- public void testSetCursorName() throws SQLException {
- Statement st = null;
- try {
- String select = "select * from zoo";
- st = conn.createStatement();
- st.setCursorName("test");
- fail("Fail: statement does not fail");
- } catch (SQLFeatureNotSupportedException e) {
- // expected
- }
- }
-
- /**
- * @test {@link java.sql.Statement#setEscapeProcessing}
- *
- * TODO setExcapeProcessing() is not supported
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not supported",
- method = "setEscapeProcessing",
- args = {boolean.class}
- )
- public void testSetEscapeProcessing() {
- Statement st = null;
- try {
- String select = "select * from zoo";
- st = conn.createStatement();
- st.setEscapeProcessing(true);
- fail("Fail: statement does not fail");
- } catch (SQLException e) {
- assertEquals("not supported", e.getMessage());
- }
-
- }
-
- /**
- * @test {@link java.sql.Statement#setQueryTimeout}
- *
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Error in impl. default query timeout for sqlite dbs is 0.",
- method = "setQueryTimeout",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Error in impl. default query timeout for sqlite dbs is 0.",
- method = "getQueryTimeout",
- args = {}
- )
- })
- public void testSetQueryTimeout() {
- try {
- Statement st = conn.createStatement();
- st.setQueryTimeout(2);
- assertEquals(2, st.getQueryTimeout());
-
- try {
- st = conn.createStatement();
- st.setQueryTimeout(-1);
- fail("SQLException not thrown");
- } catch (SQLException expected) {
- // expected
- }
-
- try {
- st = conn.createStatement();
- st.close();
- st.setQueryTimeout(3);
- fail("SQLException not thrown");
- } catch (SQLException expected) {
- // expected
- }
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * @test {@link java.sql.Statement#getResultSetType()}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Tests fail. not fully supported: returns only ResultSet.TYPE_SCROLL_INSENSITIVE. Either should throw an unsupported exception or behave according to spec.",
- method = "getResultSetType",
- args = {}
- )
- @KnownFailure("not fully supported")
- public void testGetResultSetType() {
- Statement st = null;
- // test default value
- try {
- st = conn.createStatement();
- st.getResultSetType();
- assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, st
- .getResultSetType());
- } catch (SQLException e) {
- assertEquals("not supported", e.getMessage());
- }
-
- // failing tests
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.getResultSetType();
- assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, st.getResultSetType());
- } catch (SQLException e) {
- assertEquals("not supported", e.getMessage());
- }
-
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.getResultSetType();
- assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, st.getResultSetType());
- } catch (SQLException e) {
- assertEquals("not supported", e.getMessage());
- }
-
- try {
- st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_UPDATABLE);
- st.getResultSetType();
- assertEquals(ResultSet.TYPE_FORWARD_ONLY, st.getResultSetType());
- } catch (SQLException e) {
- assertEquals("not supported", e.getMessage());
- }
- }
-
- /**
- * @test {@link java.sql.Statement#getResultSetHoldability()}
- *
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not supported",
- method = "getResultSetHoldability",
- args = {}
- )
- @KnownFailure("Test for default value fails")
- public void testGetResultSetHoldability() {
-
- // test default value
- Statement st = null;
- try {
- st = conn.createStatement();
- assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, st
- .getResultSetHoldability());
- } catch (SQLException e) {
- assertEquals("not supported", e.getMessage());
- }
-
- // failing tests
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.HOLD_CURSORS_OVER_COMMIT);
- fail("Exception expected: not supported");
- /*
- st.getResultSetHoldability();
- assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, st
- .getResultSetHoldability());
- */
- } catch (SQLException e) {
- // ok: not supported
- }
-
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.CLOSE_CURSORS_AT_COMMIT);
- fail("Exception expected: not supported");
- /*
- st.getResultSetHoldability();
- assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, st
- .getResultSetHoldability());
- */
- } catch (SQLException e) {
- // ok: not supported
- }
- }
-
- /**
- * @test {@link java.sql.Statement#getResultSetConcurrency()}
- *
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests fail. returns only ResultSet.TYPE_SCROLL_INSENSITIVE. Either should throw an unsupported exception or behave according to spec.",
- method = "getResultSetConcurrency",
- args = {}
- )
- @KnownFailure("Not supported")
- public void testGetResultSetConcurrency() {
- Statement st = null;
-
- // test default value
- try {
- st = conn.createStatement();
- st.getResultSetConcurrency();
- assertEquals(ResultSet.CONCUR_READ_ONLY, st
- .getResultSetConcurrency());
- } catch (SQLException e) {
- assertEquals("not supported", e.getMessage());
- }
-
- // failing tests
-
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- st.getResultSetConcurrency();
- assertEquals(ResultSet.CONCUR_UPDATABLE, st.getResultSetConcurrency());
- fail("Exception expected: not supported");
- } catch (SQLException e) {
- //ok
-
- }
-
- try {
- st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- st.getResultSetConcurrency();
- assertEquals(ResultSet.CONCUR_READ_ONLY, st.getResultSetConcurrency());
- fail("Exception expected: not supported");
- } catch (SQLException e) {
- //ok;
- }
- }
-
- /**
- * @test {@link java.sql.Statement#getResultSet()}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Error in implementation. Is not according to spec:if updateCount > 0 resultset must be null.",
- method = "getResultSet",
- args = {}
- )
- @KnownFailure("Does not return null on update count > 0 (not a select statement) ")
- public void testGetResultSet() {
- Statement st = null;
- ResultSet res = null;
-
- try {
- st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.CLOSE_CURSORS_AT_COMMIT);
- st.execute("create table test (c1);");
- res = st.getResultSet();
- assertNull(res);
- } catch (SQLException e) {
- fail("Unexpected Exception "+e);
- }
-
- try {
- st = conn.createStatement();
- String select = "select * from zoo where id == 4;";
- String insert = "insert into zoo (id, name, family) values (4, 'Vorobuy', 'bear');";
- st.execute(insert);
- st.execute(select);
- assertEquals(-1, st.getUpdateCount());
- res = st.getResultSet();
- assertNotNull(res);
- res.next();
- assertEquals(4,res.getInt(1));
- assertEquals("Vorobuy",res.getString(2));
- assertEquals("bear",res.getString(3));
-// assertEquals(0, st.getUpdateCount()); not supported
- assertFalse(res.next());
- } catch (SQLException e) {
- fail("SQLException is thrown:"+e.getMessage());
- }
-
- try {
- st = conn.createStatement();
- String insert = "insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');";
- st
- .execute(insert);
- res = st.getResultSet();
- // statement is an update and should return null according to spec.
- if (st.getUpdateCount() > 0) {
- assertNull(res);
- }
-
- } catch (SQLException e) {
- fail("SQLException is thrown:"+e.getMessage());
- }
-
- try {
- st.close();
- st.getResultSet();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.Statement#setQueryTimeout}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Errors in impl.An other value is returned than was set (X * 1000)Default query timeout for sqlite dbs is 0.",
- method = "getQueryTimeout",
- args = {}
- )
- @KnownFailure("An other value is returned than was set (X * 1000)")
- public void testGetQueryTimeout() {
- Statement st = null;
- try {
- st = conn.createStatement();
- st.setQueryTimeout(2000);
- assertEquals(2000, st.getQueryTimeout());
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- st = conn.createStatement();
- assertEquals(0,st.getQueryTimeout());
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- st.close();
- st.getQueryTimeout();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.Statement#getMoreResults()}
- *
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "not fully supported",
- method = "getMoreResults",
- args = {}
- )
- @KnownFailure("not supported")
- public void testGetMoreResults() {
- Statement st = null;
- ResultSet res1 = null;
- ResultSet res2 = null;
- String[] queries = {
- "insert into zoo values (3,'John','bird');",
- "update zoo set name='Masha', family='cat' where id=3;",
- "update zoo set name='Masha', family='bear' where id=3;"};
-
- try {
- st = conn.createStatement();
- st.execute(queries[0]);
- assertFalse(st.getMoreResults());
-
- try {
- st.getResultSet();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- } finally {
- try {
- st.close();
- } catch (SQLException ee) {
- }
- }
-
- try {
- st.getMoreResults();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- /**
- * @test {@link java.sql.Statement#cancel()}
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test fails. See also SQLite.DatabaseTest test of interrupt().",
- method = "cancel",
- args = {}
- )
- @KnownFailure("Bug in implementation of cancel: Does not fulfill spec.")
- public void testCancel() {
- Statement st = null;
- try {
- st = conn.prepareStatement("insert into zoo values (7,'Speedy Gonzales','Mouse');");
-
- CancelThread c = new CancelThread(st);
- InsertThread ins = new InsertThread((PreparedStatement)st);
-
- try {
- ins.t.join();
- c.t.join();
- } catch (InterruptedException e) {
- fail("Error in test setup: ");
- } catch (Exception e){
- // Insert thread may throw an exception
- // that it could not complete statement
- }
-
- // both threads have terminated and cancel should have cancelled the insert statement.
- ResultSet res = st.executeQuery("select * from zoo where id=7");
- assertFalse(res.next());
-
- } catch (SQLException e) {
- fail("SQLException is thrown: " + e.getMessage());
- }
-
- try {
- st.close();
- st.cancel();
- fail("Exception expected");
- } catch (SQLException e) {
- //ok
- }
- }
-
- class CancelThread implements Runnable{
- Thread t;
- Statement stmt;
- CancelThread (Statement aSt) {
- this.stmt = aSt;
- t = new Thread(this,"Cancel thread");
- t.start();
- }
- public void run() {
- Logger.global.info("*Cancel* thread started");
- try {
- Thread.sleep(1500);
- } catch (InterruptedException e1) {
- fail("Error in test setup");
- e1.printStackTrace();
- }
- try {
- Logger.global.info("*Cancel* thread, about to do stmt.cancel()");
- stmt.cancel();
- Logger.global.info("*Cancel* thread, stmt.cancel() done");
- } catch (SQLException e) {
- fail("Error in test setup");
- e.printStackTrace();
- }
- Logger.global.info("*Cancel* thread terminated");
- }
- }
-
- class InsertThread implements Runnable{
- Thread t;
- PreparedStatement stmt;
- InsertThread (PreparedStatement aSt) {
- this.stmt = aSt;
- t = new Thread(this,"Insert thread");
- t.start();
- }
- public void run() {
- Logger.global.info("*Insert* thread started");
- try {
- Thread.sleep(1500);
- } catch (InterruptedException e1) {
- fail("Error in test setup");
- e1.printStackTrace();
- }
- try {
- Logger.global.info("*Insert* thread, about to do insertion");
- stmt.execute();
- stmt.execute();
- Logger.global.info("*Insert* thread inserted");
- } catch (SQLException e) {
- fail("Error in test setup");
- e.printStackTrace();
- }
- Logger.global.info("*Insert* thread terminated");
- }
- }
-
-}