db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1062822 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
Date Mon, 24 Jan 2011 15:11:50 GMT
Author: rhillegas
Date: Mon Jan 24 15:11:50 2011
New Revision: 1062822

URL: http://svn.apache.org/viewvc?rev=1062822&view=rev
Log:
DERBY-4869: Check in a test case verifying a JDBC 4.1 spec clarification: an exception should
be raised if a PreparedStatement or CallableStatement is used to compile SQL text.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java?rev=1062822&r1=1062821&r2=1062822&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
Mon Jan 24 15:11:50 2011
@@ -462,6 +462,115 @@ public class StatementJdbc20Test extends
         }
     }
     
+    /**
+     * <p>
+     * Spec clarifications in JDBC 4.1. Verify that an exception is raised if a PreparedStatement
+     * or CallableStatement tries to execute one of the methods which compiles SQL text.
+     * </p>
+     */
+    public  void    test_clarification_jdbc4_1()    throws Exception
+    {
+        Connection  conn = getConnection();
+
+        PreparedStatement   ps = conn.prepareStatement( "select * from sys.syscolumns" );
+        CallableStatement   cs = conn.prepareCall( "call dynamic_results()" );
+
+        vetNotAllowed( ps );
+        vetNotAllowed( cs );
+
+        ps.close();
+        cs.close();
+    }
+    private void    vetNotAllowed( Statement stmt ) throws Exception
+    {
+        println( "Vetting a " + stmt.getClass().getName() );
+        
+        try {
+            stmt.execute( "select * from sys.systables" );
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            stmt.execute( "select * from sys.systables", Statement.NO_GENERATED_KEYS );
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            stmt.execute( "select * from sys.systables", new int[] { 1 } );
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            stmt.execute( "select * from sys.systables", new String[] { "COLUMNNAME" } );
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            stmt.executeQuery( "select * from sys.systables" );
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            stmt.executeUpdate( "insert into tab1 values(1, 2, 3.1)" );
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            stmt.executeUpdate( "insert into tab1 values(1, 2, 3.1)", Statement.NO_GENERATED_KEYS
);
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            stmt.executeUpdate( "insert into tab1 values(1, 2, 3.1)", new int[] { 1 } );
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            stmt.executeUpdate( "insert into tab1 values(1, 2, 3.1)", new String[] { "COLUMNNAME"
} );
+            failVNA();
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+    }
+    private void    failVNA() throws Exception
+    {
+            fail( "Should have failed when run on a PreparedStatement or CallableStatement"
);
+    }
+
     ///////////////////////////////////////////////////////////////////////
     //
     // PROCEDURES



Mime
View raw message