db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1136371 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/metadata.properties testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Date Thu, 16 Jun 2011 10:54:34 GMT
Author: kahatlen
Date: Thu Jun 16 10:54:33 2011
New Revision: 1136371

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

Removed hard-coded maximum length for the start value and increment in
the meta-data query.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties?rev=1136371&r1=1136370&r2=1136371&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties Thu Jun
16 10:54:33 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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?rev=1136371&r1=1136370&r2=1136371&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Thu Jun 16 10:54:33 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



Mime
View raw message