db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r958677 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
Date Mon, 28 Jun 2010 18:53:20 GMT
Author: rhillegas
Date: Mon Jun 28 18:53:20 2010
New Revision: 958677

URL: http://svn.apache.org/viewvc?rev=958677&view=rev
Log:
DERBY-4716: Enable BOOLEAN literal defaults in CREATE/ALTER TABLE statements.

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/tests/lang/BooleanValuesTest.java

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=958677&r1=958676&r2=958677&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
Mon Jun 28 18:53:20 2010
@@ -769,6 +769,9 @@ public class ColumnDefinitionNode extend
 
 		switch (colType) {
 
+			case StoredFormatIds.BOOLEAN_TYPE_ID:
+                return ( defaultNode instanceof BooleanConstantNode );
+                
 			case StoredFormatIds.INT_TYPE_ID:
 			// DB2 doesn't allow floating point values to be used
 			// as defaults for integer columns (they ARE allowed

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java?rev=958677&r1=958676&r2=958677&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
Mon Jun 28 18:53:20 2010
@@ -55,6 +55,7 @@ public class BooleanValuesTest  extends 
     private static final String NOT_UNION_COMPATIBLE = "42X61";
     private static final String BAD_CONVERSION = "42846";
     private static final String ILLEGAL_INSERT = "42821";
+    private static final String BAD_DEFAULT = "42894";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -1076,6 +1077,49 @@ public class BooleanValuesTest  extends 
         goodStatement( conn, "drop table booleanIndexed" );
     }
 
+    /**
+     * <p>
+     * Verify that you can declare literal defaults for boolean columns.
+     * </p>
+     */
+    public void test_14_defaults() throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement( conn, "create table booleanDefaults( a int, b boolean default true,
c boolean default false, d boolean default null )" );
+        goodStatement( conn, "insert into booleanDefaults( a ) values ( 0 )" );
+        assertResults
+            (
+             conn,
+             "select * from booleanDefaults order by a",
+             new String[][]
+             {
+                 { "0", "true", "false", null }
+             },
+             false
+             );
+        
+        goodStatement( conn, "alter table booleanDefaults add column e boolean default true"
);
+        assertResults
+            (
+             conn,
+             "select * from booleanDefaults order by a",
+             new String[][]
+             {
+                 { "0", "true", "false", null, "true" }
+             },
+             false
+             );
+
+        goodStatement( conn, "drop table booleanDefaults" );
+
+        expectCompilationError( BAD_DEFAULT, "create table badDefault( a int, b boolean default
0 )" );
+        expectCompilationError( BAD_DEFAULT, "create table badDefault( a int, b boolean default
9.99 )" );
+        expectCompilationError( BAD_DEFAULT, "create table badDefault( a int, b boolean default
5e1 )" );
+        expectCompilationError( BAD_DEFAULT, "create table badDefault( a int, b boolean default
'false' )" );
+        expectCompilationError( BAD_DEFAULT, "create table badDefault( a int, b boolean default
X'DE' )" );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // SQL ROUTINES



Mime
View raw message