db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1354024 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Tue, 26 Jun 2012 14:05:42 GMT
Author: dag
Date: Tue Jun 26 14:05:41 2012
New Revision: 1354024

URL: http://svn.apache.org/viewvc?rev=1354024&view=rev
Log:
DERBY-5829 Lift DB2 restriction on the DEFAULT clause

It removes the restriction on VARCHAR defaults length to maximally 254 characters.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/db2Compatibility.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java?rev=1354024&r1=1354023&r2=1354024&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
Tue Jun 26 14:05:41 2012
@@ -21,42 +21,28 @@
 
 package	org.apache.derby.impl.sql.compile;
 
+import java.sql.Types;
+import java.util.Vector;
+import org.apache.derby.catalog.DefaultInfo;
+import org.apache.derby.catalog.UUID;
+import org.apache.derby.catalog.types.DefaultInfoImpl;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.Limits;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derby.iapi.services.loader.ClassInspector;
-
 import org.apache.derby.iapi.services.sanity.SanityManager;
-import org.apache.derby.iapi.services.io.StoredFormatIds;
-import org.apache.derby.iapi.reference.Limits;
-import org.apache.derby.iapi.error.StandardException;
-
-import org.apache.derby.iapi.sql.compile.CompilerContext;
 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
-
-import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
+import org.apache.derby.iapi.sql.compile.CompilerContext;
+import org.apache.derby.iapi.sql.depend.ProviderList;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
-
 import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.types.StringDataValue;
 import org.apache.derby.iapi.types.TypeId;
-
-import org.apache.derby.iapi.sql.depend.DependencyManager;
-import org.apache.derby.iapi.sql.depend.ProviderList;
-import org.apache.derby.iapi.sql.depend.ProviderInfo;
-
-import org.apache.derby.iapi.reference.SQLState;
-
 import org.apache.derby.impl.sql.execute.ColumnInfo;
 
-import org.apache.derby.catalog.AliasInfo;
-import org.apache.derby.catalog.DefaultInfo;
-import org.apache.derby.catalog.UUID;
-
-import org.apache.derby.catalog.types.DefaultInfoImpl;
-
-import java.util.Vector;
-import java.sql.Types;
-
 /**
  * A ColumnDefinitionNode represents a column definition in a DDL statement.
  * There will be a ColumnDefinitionNode for each column in a CREATE TABLE
@@ -706,9 +692,6 @@ public class ColumnDefinitionNode extend
 	throws StandardException
 	{
 
-		if (defaultText.length() > Limits.DB2_CHAR_MAXWIDTH)
-		// DB2 spec says this isn't allowed.
-			return false;
 
 		/* We can use info about the way the parser works
 		 * to guide this process a little (see the getNumericNode()

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out?rev=1354024&r1=1354023&r2=1354024&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
Tue Jun 26 14:05:41 2012
@@ -923,9 +923,6 @@ ERROR 42894: DEFAULT value or IDENTITY a
 ij> -- decimal value with too much precision.
 create table deftest4 (d decimal(5,2) default 1.2234);
 ERROR 42894: DEFAULT value or IDENTITY attribute value is not valid for column 'D'.
-ij> -- char constant longer than 254.
-create table deftest5 (vc varchar(300) default 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
-ERROR 42894: DEFAULT value or IDENTITY attribute value is not valid for column 'VC'.
 ij> -- function calls (built-in and other) should fail with error 42894 (NOT with 42X01),
to match DB2.
 create table t1 (i int default abs(0));
 ERROR 42894: DEFAULT value or IDENTITY attribute value is not valid for column 'I'.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java?rev=1354024&r1=1354023&r2=1354024&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ColumnDefaultsTest.java
Tue Jun 26 14:05:41 2012
@@ -25,6 +25,7 @@ import java.sql.ResultSet;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
+import org.apache.derbyTesting.functionTests.util.Formatters;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -512,4 +513,60 @@ public final class ColumnDefaultsTest ex
         rollback();
         st.close();
     }
+
+    public void testDerby118_and_5829 () throws SQLException {
+        Statement st = createStatement();
+
+        /*
+         * Lift restriction that even VARCHAR can max have 254 chars in
+         * DEFAULT, another DB2ism.
+         */
+        String sb = Formatters.repeatChar("-", 400);
+
+        st.executeUpdate(
+            "create table tabLongVarchar("
+            + "    c varchar(400) default " + "'" + sb + "')");
+        st.executeUpdate(
+            "insert into  tabLongVarchar" +
+            "    values default");
+
+        ResultSet rs = st.executeQuery("select c from tabLongVarchar");
+        JDBC.assertSingleValueResultSet(rs, sb);
+
+        // Negative test: Make sure we still flag too long string for CHAR
+        // (length > 254).  Note that the check will now only happen at insert
+        // time, as other truncation checks do.
+        st.executeUpdate(
+            "create table tabLongChar("
+            + "    c char(254) default " + "'" + sb + "')");
+        try {
+            st.executeUpdate(
+                "insert into tabLongChar values default");
+            fail();
+        } catch (SQLException e) {
+            assertSQLState("22001", e); // truncate
+        }
+
+        // Interestingly, a float literal for SMALLINT is not disabled for
+        // assignment to integer types.  This is asymmetric, as it is forbidden
+        // for the other integer types, as per the standard, btw.
+        // Remove this test if we forbid this, or add tests for the other
+        // integer types if we decide to allow it, cf discussions on
+        // DERBY-118. For now, we just document this weirdness in this test.
+        st.executeUpdate(
+            "create table tabSmallIntFloat(si smallint default 3.14)");
+        st.executeUpdate(
+            "insert into  tabSmallIntFloat values default");
+        rs = st.executeQuery("select si from tabSmallIntFloat");
+        JDBC.assertSingleValueResultSet(rs, "3");
+
+        // Compare with INT, which fails:
+        try {
+            st.executeUpdate(
+                "create table tabIntFloat(i int default 3.14)");
+            fail();
+        } catch (SQLException e) {
+            assertSQLState("42894", e);
+        }
+    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/db2Compatibility.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/db2Compatibility.sql?rev=1354024&r1=1354023&r2=1354024&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/db2Compatibility.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/db2Compatibility.sql
Tue Jun 26 14:05:41 2012
@@ -455,8 +455,6 @@ create table deftest2 (i int default 3+4
 create table deftest3 (i int default 1.234);
 -- decimal value with too much precision.
 create table deftest4 (d decimal(5,2) default 1.2234);
--- char constant longer than 254.
-create table deftest5 (vc varchar(300) default 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 -- function calls (built-in and other) should fail with error 42894 (NOT with 42X01), to
match DB2.
 create table t1 (i int default abs(0));
 create table t1 (i int default someFunc('hi'));



Mime
View raw message