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 2011/06/22 13:56:31 UTC

svn commit: r1138416 - in /db/derby/code/branches/10.8: ./ java/engine/org/apache/derby/impl/jdbc/metadata.properties java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java tools/ant/properties/release.properties

Author: kahatlen
Date: Wed Jun 22 11:56:30 2011
New Revision: 1138416

URL: http://svn.apache.org/viewvc?rev=1138416&view=rev
Log:
DERBY-5274: getColumns() doesn't work with auto generated identity columns that start with large numbers

Merged fix from trunk (revision 1136371) and bumped version number to
make databases upgraded from earlier revisions on the branch pick up
the fixed meta-data query.

Modified:
    db/derby/code/branches/10.8/   (props changed)
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/metadata.properties
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
    db/derby/code/branches/10.8/tools/ant/properties/release.properties

Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun 22 11:56:30 2011
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.7:1061570,1061578,1082235
-/db/derby/code/trunk:1063809,1088633,1091000,1091221,1091285,1092067,1092795,1094315,1094572,1094728,1096741,1096890,1097247,1097249,1097460,1097469,1097471,1101059,1101839,1102620,1102826,1103681,1103718,1103742,1125305,1126358,1126468,1127825,1127883,1129136,1129764,1129797,1130077,1130084,1130632,1130895,1131030,1131272,1132546,1132664,1132860,1132928,1133741,1133752,1136397,1136844
+/db/derby/code/trunk:1063809,1088633,1091000,1091221,1091285,1092067,1092795,1094315,1094572,1094728,1096741,1096890,1097247,1097249,1097460,1097469,1097471,1101059,1101839,1102620,1102826,1103681,1103718,1103742,1125305,1126358,1126468,1127825,1127883,1129136,1129764,1129797,1130077,1130084,1130632,1130895,1131030,1131272,1132546,1132664,1132860,1132928,1133741,1133752,1136371,1136397,1136844

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/metadata.properties
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/metadata.properties?rev=1138416&r1=1138415&r2=1138416&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/metadata.properties (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/metadata.properties Wed Jun 22 11:56:30 2011
@@ -337,9 +337,15 @@ getColumns=\
 		    (CASE WHEN (AUTOINCREMENTINC is NULL) THEN  \
 			   CAST (NULL AS VARCHAR(254)) ELSE \
                'AUTOINCREMENT: start ' || \
-							(CAST (RTRIM(CAST(AUTOINCREMENTSTART AS CHAR(12))) AS VARCHAR(12))) || \
+                   -- The AUTOINCREMENT* columns have incorrect meta-data \n \
+                   -- if the database was created with an old version of  \n \
+                   -- Derby (see DERBY-1745 and DERBY-5274), and the CHAR \n \
+                   -- function won't work. Wrap them in a BIGINT function \n \
+                   -- call to fix the meta-data, even though the columns  \n \
+                   -- already are of type BIGINT.                         \n \
+							RTRIM(CHAR(BIGINT(AUTOINCREMENTSTART))) || \
 							' increment ' || \
-							(CAST (RTRIM(CAST(AUTOINCREMENTINC AS CHAR(12))) AS VARCHAR(12))) END ) ELSE \
+							RTRIM(CHAR(BIGINT(AUTOINCREMENTINC))) END ) ELSE \
  				CAST (COLUMNDEFAULT AS VARCHAR(254)) END AS COLUMN_DEF, \
 		CAST( NULL AS INT) AS SQL_DATA_TYPE, \
 		CAST( NULL AS INT) AS SQL_DATETIME_SUB, \

Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?rev=1138416&r1=1138415&r2=1138416&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java (original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java Wed Jun 22 11:56:30 2011
@@ -5018,6 +5018,54 @@ public class DatabaseMetaDataTest extend
         DriverManager.getConnection(
         "jdbc:default:connection").getMetaData().isReadOnly();
     }
+
+    /**
+     * getColumns() used to fail with a truncation error if an auto-increment
+     * column had a start value or an increment that was very large (that is,
+     * when its CHAR representation exceeded 12 characters). DERBY-5274.
+     */
+    public void testGetColumns_DERBY5274() throws SQLException {
+        // Disable auto-commit to allow easy cleanup.
+        setAutoCommit(false);
+
+        Statement s = createStatement();
+
+        // Create a test table with an identity column whose start value and
+        // increment are very large.
+        final long bignum = 648518346341351400L;
+        s.execute("create table derby5274(x bigint not null " +
+                  "generated always as identity (" +
+                  "start with " + bignum + ", increment by " + bignum + "))");
+
+        // Expected values for various columns in the meta-data.
+        String[][] expected = {
+            {"TABLE_SCHEM", "APP"},
+            {"TABLE_NAME", "DERBY5274"},
+            {"COLUMN_NAME", "X"},
+            {"COLUMN_DEF",
+                "AUTOINCREMENT: start " + bignum + " increment " + bignum},
+            {"IS_NULLABLE", "NO"},
+        };
+
+        // Get meta-data for the column in the test table. This used to fail
+        // with a truncation error before DERBY-5274.
+        ResultSet rs = getDMD().getColumns(null, null, "DERBY5274", null);
+
+        // Verify that the returned meta-data looks right.
+        assertTrue("No columns found", rs.next());
+        for (int i = 0; i < expected.length; i++) {
+            String label = expected[i][0];
+            String expectedVal = expected[i][1];
+            assertEquals(label, expectedVal, rs.getString(label));
+        }
+
+        // There's only one column in the test table, so there should be no
+        // more rows in the meta-data.
+        JDBC.assertEmpty(rs);
+
+        // Clean up.
+        rollback();
+    }
     
     /**
      *  dummy method to test getProcedureColumns

Modified: db/derby/code/branches/10.8/tools/ant/properties/release.properties
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/tools/ant/properties/release.properties?rev=1138416&r1=1138415&r2=1138416&view=diff
==============================================================================
--- db/derby/code/branches/10.8/tools/ant/properties/release.properties (original)
+++ db/derby/code/branches/10.8/tools/ant/properties/release.properties Wed Jun 22 11:56:30 2011
@@ -15,7 +15,7 @@
 
 
 drdamaint=0
-maint=1000004
+maint=1000005
 major=10
 minor=8
 eversion=10.8
@@ -23,4 +23,4 @@ beta=false
 copyright.comment=Copyright 1997, 2011 The Apache Software Foundation or its licensors, as applicable.
 vendor=The Apache Software Foundation
 copyright.year=2011
-release.id.long=10.8.1.4
+release.id.long=10.8.1.5