You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2012/05/21 16:30:25 UTC

svn commit: r1341046 [6/6] - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/ engine/org/apache/derby/iapi/services/io/ engine/org/apache/derby/iapi/sql/ engine/org/apache/derby/iapi/types/ engine/org/apache/derby/impl/sql/execute/ shared...

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaAnotherTest.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaAnotherTest.out?rev=1341046&r1=1341045&r2=1341046&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaAnotherTest.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaAnotherTest.out Mon May 21 14:30:24 2012
@@ -62,6 +62,7 @@ ij> select * from global_xactTable where
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (0  |ACTIVE  |false|APP       |UserTransaction               
+WARNING 01004: Data truncation
 ij> xa_end xa_success 0;
 ij> xa_commit xa_1phase 0;
 ij> xa_datasource 'wombat' shutdown;
@@ -136,6 +137,11 @@ select * from global_xactTable where gxi
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (1  |ACTIVE  |false|MAMTA     |UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 (2  |PREPARED|false|MAMTA     |UserTransaction               
 (3  |PREPARED|false|MAMTA     |UserTransaction               
 (4  |PREPARED|false|MAMTA     |UserTransaction               
@@ -165,6 +171,10 @@ select * from global_xactTable where gxi
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (2  |PREPARED|false|NULL      |UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 (3  |PREPARED|false|NULL      |UserTransaction               
 (4  |PREPARED|false|NULL      |UserTransaction               
 (5  |PREPARED|false|NULL      |UserTransaction               
@@ -217,6 +227,10 @@ ij(LOCAL3)> select * from global_xactTab
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (5  |PREPARED|false|NULL      |UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 (6  |PREPARED|false|MAMTA1    |UserTransaction               
 (7  |PREPARED|false|MAMTA1    |UserTransaction               
 (8  |PREPARED|false|MAMTA1    |UserTransaction               
@@ -237,6 +251,10 @@ select * from global_xactTable where gxi
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (5  |PREPARED|false|NULL      |UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 (6  |PREPARED|false|NULL      |UserTransaction               
 (7  |PREPARED|false|NULL      |UserTransaction               
 (8  |PREPARED|false|NULL      |UserTransaction               
@@ -258,6 +276,10 @@ select * from global_xactTable where gxi
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (5  |PREPARED|false|NULL      |UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 (6  |PREPARED|false|NULL      |UserTransaction               
 (7  |PREPARED|false|NULL      |UserTransaction               
 (8  |PREPARED|false|NULL      |UserTransaction               

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaOffline1.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaOffline1.out?rev=1341046&r1=1341045&r2=1341046&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaOffline1.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaOffline1.out Mon May 21 14:30:24 2012
@@ -78,7 +78,7 @@ ij(XA)> --
 create view lock_table as
 select 
     cast(username as char(8)) as username,
-    cast(t.type as char(8)) as trantype,
+    cast(t.type as char(15)) as trantype,
     cast(l.type as char(8)) as type,
     cast(lockcount as char(3)) as cnt,
     mode,
@@ -142,6 +142,7 @@ ij(XA)> select * from global_xactTable w
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (1  |ACTIVE  |false|APP       |UserTransaction               
+WARNING 01004: Data truncation
 ij(XA)> select global_xid, username, type, status, cast(sql_text as varchar(512)) sql_text from tran_table where global_xid is not null order by global_xid, username, type, status, sql_text;
 GLOBAL_XID                                                                                                                      |USERNAME                                                                                                                        |TYPE                          |STATUS  |SQL_TEXT                                                                                                                        
 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -153,12 +154,14 @@ ij(XA)> select * from global_xactTable w
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (1  |PREPARED|false|APP       |UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 (2  |IDLE    |NULL |APP       |UserTransaction               
 ij(XA)> select * from lock_table order by tabname, type desc, mode, cnt, lockname;
-USERNAME|TRANTYPE|TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE|STATUS  
----------------------------------------------------------------------------
-APP     |UserTran|TABLE   |1   |IX  |FOO         |Tablelock |GRANT|PREPARED
-APP     |UserTran|ROW     |1   |X   |FOO         |(1,8)     |GRANT|PREPARED
+USERNAME|TRANTYPE       |TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE|STATUS  
+----------------------------------------------------------------------------------
+APP     |UserTransaction|TABLE   |1   |IX  |FOO         |Tablelock |GRANT|PREPARED
+APP     |UserTransaction|ROW     |1   |X   |FOO         |(1,8)     |GRANT|PREPARED
 ij(XA)> xa_end xa_success 2;
 ij(XA)> xa_commit xa_1phase 2;
 ij(XA)> xa_recover xa_startrscan;
@@ -186,12 +189,14 @@ ij(XA)> select * from global_xactTable w
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (1  |PREPARED|false|NULL      |UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 (4  |IDLE    |NULL |APP       |UserTransaction               
 ij(XA)> select * from lock_table order by tabname, type desc, mode, cnt, lockname;
-USERNAME|TRANTYPE|TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE|STATUS  
----------------------------------------------------------------------------
-NULL    |UserTran|TABLE   |1   |IX  |FOO         |Tablelock |GRANT|PREPARED
-NULL    |UserTran|ROW     |1   |X   |FOO         |(1,8)     |GRANT|PREPARED
+USERNAME|TRANTYPE       |TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE|STATUS  
+----------------------------------------------------------------------------------
+NULL    |UserTransaction|TABLE   |1   |IX  |FOO         |Tablelock |GRANT|PREPARED
+NULL    |UserTransaction|ROW     |1   |X   |FOO         |(1,8)     |GRANT|PREPARED
 ij(XA)> xa_recover xa_startrscan;
 Recovered 1 in doubt transactions
 Transaction 1 : (1,FILTERED,FILTERED)
@@ -206,9 +211,10 @@ ij(XA)> select * from global_xactTable w
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (4  |IDLE    |NULL |APP       |UserTransaction               
+WARNING 01004: Data truncation
 ij(XA)> select * from lock_table order by tabname, type desc, mode, cnt, lockname;
-USERNAME|TRANTYPE|TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE|STATUS  
----------------------------------------------------------------------------
+USERNAME|TRANTYPE       |TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE|STATUS  
+----------------------------------------------------------------------------------
 ij(XA)> xa_recover xa_startrscan;
 Recovered 0 in doubt transactions
 ij(XA)> xa_end xa_success 4;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaSimpleNegative.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaSimpleNegative.out?rev=1341046&r1=1341045&r2=1341046&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaSimpleNegative.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xaSimpleNegative.out Mon May 21 14:30:24 2012
@@ -119,6 +119,8 @@ ij(XA)> select * from global_xactTable o
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (0  |ACTIVE  |false|NEGATIVETE|UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 NULL|IDLE    |NULL |APP       |UserTransaction               
 ij(XA)> disconnect;
 ij> xa_end xa_fail 0;
@@ -147,6 +149,9 @@ ij(XA)> select * from global_xactTable o
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (2  |ACTIVE  |false|NEGATIVETE|UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 NULL|IDLE    |NULL |APP       |UserTransaction               
 NULL|IDLE    |NULL |NEGATIVETE|UserTransaction               
 ij(XA)> xa_end xa_success 2;
@@ -216,6 +221,10 @@ ij(XA)> select * from global_xactTable o
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (1  |PREPARED|false|NEGATIVETE|UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 (3  |IDLE    |NULL |NEGATIVETE|UserTransaction               
 NULL|IDLE    |NULL |APP       |UserTransaction               
 ij(XA)> drop table foo;
@@ -250,6 +259,8 @@ ij(XA)> select * from global_xactTable o
 GXID|STATUS  |READ&|USERNAME  |TYPE                          
 -------------------------------------------------------------
 (3  |ACTIVE  |false|NEGATIVETE|UserTransaction               
+WARNING 01004: Data truncation
+WARNING 01004: Data truncation
 NULL|IDLE    |NULL |APP       |UserTransaction               
 ij(XA)> -- ERROR: bad flag
 xa_end xa_noflags 3;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CastingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CastingTest.java?rev=1341046&r1=1341045&r2=1341046&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CastingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CastingTest.java Mon May 21 14:30:24 2012
@@ -22,11 +22,13 @@
 package org.apache.derbyTesting.functionTests.tests.lang;
 
 import java.sql.Connection;
+import java.sql.DataTruncation;
 import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
+import java.sql.SQLWarning;
 import java.sql.Statement;
 import java.sql.Types;
 
@@ -826,6 +828,150 @@ public static String[][]SQLData =
         }
     }
 
+    /**
+     * Test that a java.sql.DataTruncation warning is created when a cast
+     * results in truncation. DERBY-129.
+     */
+    public void testDataTruncationWarning() throws SQLException {
+        Statement s = createStatement();
+
+        // Test truncation of character data
+        checkDataTruncationResult(s,
+            "values (cast('abc' as char(2)), cast('de'   as char(2)))," +
+            "       (cast('fg'  as char(2)), cast('hi'   as char(2)))," +
+            "       (cast('jkl' as char(2)), cast('mnop' as char(2)))");
+        checkDataTruncationResult(s,
+            "values (cast('abc' as varchar(2)), cast('de'   as varchar(2)))," +
+            "       (cast('fg'  as varchar(2)), cast('hi'   as varchar(2)))," +
+            "       (cast('jkl' as varchar(2)), cast('mnop' as varchar(2)))");
+        checkDataTruncationResult(s,
+            "values (cast('abc' as clob(2)), cast('de'   as clob(2)))," +
+            "       (cast('fg'  as clob(2)), cast('hi'   as clob(2)))," +
+            "       (cast('jkl' as clob(2)), cast('mnop' as clob(2)))");
+
+        // Exact same test as above for binary data
+        checkDataTruncationResult(s,
+            "values (cast(x'abcdef' as char(2) for bit data),"+
+            "        cast(x'abcd' as char(2) for bit data))," +
+            "       (cast(x'abcd' as char(2) for bit data)," +
+            "        cast(x'cdef' as char(2) for bit data))," +
+            "       (cast(x'012345' as char(2) for bit data)," +
+            "        cast(x'6789ABCD' as char(2) for bit data))");
+        checkDataTruncationResult(s,
+            "values (cast(x'abcdef' as varchar(2) for bit data),"+
+            "        cast(x'abcd' as varchar(2) for bit data))," +
+            "       (cast(x'abcd' as varchar(2) for bit data)," +
+            "        cast(x'cdef' as varchar(2) for bit data))," +
+            "       (cast(x'012345' as varchar(2) for bit data)," +
+            "        cast(x'6789ABCD' as varchar(2) for bit data))");
+        checkDataTruncationResult(s,
+            "values" +
+            "    (cast(x'abcdef' as blob(2)), cast(x'abcd' as blob(2))), " +
+            "    (cast(x'abcd' as blob(2)),   cast(x'cdef' as blob(2))), " +
+            "    (cast(x'012345' as blob(2)), cast(x'6789ABCD' as blob(2)))");
+
+        // DataTruncation's javadoc says that getDataSize() and
+        // getTransferSize() should return number of bytes. Derby uses
+        // UTF-8. Test with some characters outside the US-ASCII range to
+        // verify that the returned values are in bytes and not in chars.
+        ResultSet rs = s.executeQuery(
+                "values cast('abc\u00E6\u00F8\u00E5' as varchar(4))");
+        assertTrue(rs.next());
+        assertEquals("abc\u00E6", rs.getString(1));
+        // The warning should say the string is truncated from 9 bytes to
+        // 5 bytes, not from 6 characters to 4 characters.
+        assertDataTruncation(rs.getWarnings(), -1, true, false, 9, 5);
+        assertFalse(rs.next());
+        rs.close();
+
+        // Test that there's a warning on the statement if truncation happens
+        // in an operation that doesn't return a ResultSet.
+        setAutoCommit(false);
+        s.execute("create table t1_d129 (x8 char(8) for bit data)");
+        s.execute("create table t2_d129 (x4 char(4) for bit data)");
+        s.execute("insert into t1_d129(x8) values x'0123456789ABCDEF'");
+        assertNull(s.getWarnings());
+        s.execute("insert into t2_d129(x4) " +
+                  "select cast(x8 as char(4) for bit data) from t1_d129");
+        assertDataTruncation(s.getWarnings(), -1, true, false, 8, 4);
+        rollback();
+    }
+
+    /**
+     * <p>
+     * Check the results for the queries in testDataTruncation().
+     * </p>
+     *
+     * <p>
+     * The method expects a query that returns three rows with columns of a
+     * character string or binary string data type, where some of the values
+     * are cast to a narrower data type.
+     * </p>
+     *
+     * <p>
+     * Expect the following truncations to have taken place:
+     * </p>
+     *
+     * <ol>
+     * <li>Row 1, column 1: truncated from 3 to 2 bytes</li>
+     * <li>Row 3, column 1: truncated from 3 to 2 bytes</li>
+     * <li>Row 3, column 2: truncated from 4 to 2 bytes</li>
+     * </ol>
+     */
+    private void checkDataTruncationResult(Statement s, String sql)
+            throws SQLException {
+        ResultSet rs = s.executeQuery(sql);
+
+        // First row should have one warning (column 1)
+        assertTrue(rs.next());
+        SQLWarning w = rs.getWarnings();
+        assertDataTruncation(w, -1, true, false, 3, 2);
+        w = w.getNextWarning();
+        assertNull(w);
+        rs.clearWarnings(); // workaround for DERBY-5765
+
+        // Second row should have no warnings
+        assertTrue(rs.next());
+        assertNull(rs.getWarnings());
+
+        // Third row should have two warnings (column 1 and 2)
+        assertTrue(rs.next());
+        w = rs.getWarnings();
+        assertDataTruncation(w, -1, true, false, 3, 2);
+        // Client driver doesn't support nested warnings
+        if (usingEmbedded()) {
+            w = w.getNextWarning();
+            assertDataTruncation(w, -1, true, false, 4, 2);
+        }
+        w = w.getNextWarning();
+        assertNull(w);
+        rs.clearWarnings(); // workaround for DERBY-5765
+
+        // No more rows
+        assertFalse(rs.next());
+        rs.close();
+
+        // There should be no warnings on the statement or the connection
+        assertNull(s.getWarnings());
+        assertNull(getConnection().getWarnings());
+    }
+
+    private void assertDataTruncation(
+            SQLWarning w, int index, boolean read, boolean parameter,
+            int dataSize, int transferSize) throws SQLException {
+        assertNotNull("No warning", w);
+        if (!(w instanceof DataTruncation)) {
+            fail("Not a DataTruncation warning", w);
+        }
+
+        DataTruncation dt = (DataTruncation) w;
+        assertEquals("Column index", index, dt.getIndex());
+        assertEquals("Read", read, dt.getRead());
+        assertEquals("Parameter", parameter, dt.getParameter());
+        assertEquals("Data size", dataSize, dt.getDataSize());
+        assertEquals("Transfer size", transferSize, dt.getTransferSize());
+    }
+
     protected void tearDown() throws SQLException, Exception {
         Statement scb = createStatement();
 
@@ -1035,11 +1181,11 @@ public static String[][]SQLData =
     }
 
     /**
-     * Testing server-side behaviour so run in embedded only.
+     * Create a test suite with all the tests in this class. Although we're
+     * testing embedded functionality, also run the test in client/server
+     * mode to ensure that warnings and errors travel across the wire.
      */
     public static Test suite() {
-
-        return TestConfiguration.embeddedSuite(CastingTest.class);
-
+        return TestConfiguration.defaultSuite(CastingTest.class);
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LockTableQuery.subsql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LockTableQuery.subsql?rev=1341046&r1=1341045&r2=1341046&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LockTableQuery.subsql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LockTableQuery.subsql Mon May 21 14:30:24 2012
@@ -16,7 +16,7 @@
 --
 select 
     cast(username as char(8)) as username,
-    cast(t.type as char(8)) as trantype,
+    cast(t.type as char(15)) as trantype,
     cast(l.type as char(8)) as type,
     cast(lockcount as char(3)) as cnt,
     mode,

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/cast.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/cast.sql?rev=1341046&r1=1341045&r2=1341046&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/cast.sql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/cast.sql Mon May 21 14:30:24 2012
@@ -25,8 +25,7 @@
 
 -- shrink/grow bit and char
 -- no exceptions should be raised.
--- once we have warnings we'll expect
--- a warning when shrinking non space/zeros
+-- expect a warning when shrinking non-space
 
 -- shrink
 values (cast ('hell' as char(2)));

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/LockTableQuery.subsql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/LockTableQuery.subsql?rev=1341046&r1=1341045&r2=1341046&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/LockTableQuery.subsql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/LockTableQuery.subsql Mon May 21 14:30:24 2012
@@ -17,7 +17,7 @@
 create view lock_table as
 select 
     cast(username as char(8)) as username,
-    cast(t.type as char(8)) as trantype,
+    cast(t.type as char(15)) as trantype,
     cast(l.type as char(8)) as type,
     cast(lockcount as char(3)) as cnt,
     mode,