db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r958565 - 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/jdbcapi/ testing/org/apache/derbyTesting/functionTes...
Date Mon, 28 Jun 2010 13:03:35 GMT
Author: rhillegas
Date: Mon Jun 28 13:03:34 2010
New Revision: 958565

URL: http://svn.apache.org/viewvc?rev=958565&view=rev
Log:
DERBY-4716: Allow BOOLEAN-typed columns in tables.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.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/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=958565&r1=958564&r2=958565&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Mon Jun
28 13:03:34 2010
@@ -3911,7 +3911,7 @@ columnDefinition(TableElementList tableE
 
 	/* identifier() used to be columnName() */
 	columnName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) 
-	[ ( typeDescriptor[0] = dataTypeDDL( false ) ) ]
+	[ ( typeDescriptor[0] = dataTypeDDL() ) ]
 	[ defaultNode = defaultAndConstraints(typeDescriptor, tableElementList, columnName, autoIncrementInfo)
]
 	{
 		// Only pass autoincrement info for autoincrement columns
@@ -3960,13 +3960,13 @@ defaultAndConstraints(DataTypeDescriptor
  * <A NAME="dataTypeDDL">dataTypeDDL</A>
  */
 DataTypeDescriptor
-dataTypeDDL( boolean booleanDatatypeAllowed ) throws StandardException :
+dataTypeDDL() throws StandardException :
 {
 	DataTypeDescriptor	typeDescriptor;
 }
 {
 	LOOKAHEAD( { commonDatatypeName(false) } )
-	typeDescriptor = dataTypeCommon( booleanDatatypeAllowed )
+	typeDescriptor = dataTypeCommon()
 	{
 		return typeDescriptor;
 	}
@@ -3983,12 +3983,12 @@ dataTypeDDL( boolean booleanDatatypeAllo
    the Java interface TypeDescriptor.
 */
 TypeDescriptor
-catalogType( boolean booleanDatatypeAllowed ) throws StandardException :
+catalogType() throws StandardException :
 {
 	DataTypeDescriptor	typeDescriptor;
 }
 {
-	typeDescriptor = dataTypeDDL( booleanDatatypeAllowed )
+	typeDescriptor = dataTypeDDL()
 	{
 		return typeDescriptor.getCatalogType();
 	}
@@ -4007,7 +4007,7 @@ dataTypeCast() throws StandardException 
 	// This lookahead is required because the names of the built-in
 	// datatypes are not reserved words
 	LOOKAHEAD( { commonDatatypeName(true) } )
-	typeDescriptor = dataTypeCommon( true )
+	typeDescriptor = dataTypeCommon()
 	{
 		return typeDescriptor;
 	}
@@ -4022,7 +4022,7 @@ dataTypeCast() throws StandardException 
  * <A NAME="dataTypeCommon">dataTypeCommon</A>
  */
 DataTypeDescriptor
-dataTypeCommon( boolean booleanDatatypeAllowed ) throws StandardException :
+dataTypeCommon() throws StandardException :
 {
 	DataTypeDescriptor	typeDescriptor;
 	boolean checkCS = false;
@@ -4049,7 +4049,6 @@ dataTypeCommon( boolean booleanDatatypeA
 	typeDescriptor = datetimeType()
 | <BOOLEAN>
 {
-	if ( !booleanDatatypeAllowed) { checkInternalFeature(TypeId.BOOLEAN_NAME); }
 	if ((getCompilerContext().getReliability() & CompilerContext.INTERNAL_SQL_ILLEGAL) !=
0)
     {
         checkVersion(DataDictionary.DD_VERSION_DERBY_10_7, "BOOLEAN");
@@ -7205,7 +7204,7 @@ DataTypeDescriptor xmlSerializeTargetTyp
 			ReuseFactory.getInteger(getToken(1).beginColumn));
 	}
 |
-	<AS> targetType = dataTypeDDL( true )
+	<AS> targetType = dataTypeDDL()
 	{
 		return targetType;
 	}
@@ -10778,7 +10777,7 @@ procedureParameterDefinition(Vector[] li
 	[   LOOKAHEAD( { dataTypeCheck(2) })
 	    parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
 	]
-	typeDescriptor = dataTypeDDL( true )
+	typeDescriptor = dataTypeDDL()
 	{
 		list[0].addElement(parameterName);
 		list[1].addElement(typeDescriptor.getCatalogType());
@@ -10873,7 +10872,7 @@ functionParameterDefinition(Vector[] lis
 	[   LOOKAHEAD( { dataTypeCheck(2) })
 	    parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
 	]
-	typeDescriptor = dataTypeDDL( true ) 
+	typeDescriptor = dataTypeDDL() 
 	{
 		list[0].addElement(parameterName);
 		list[1].addElement(typeDescriptor.getCatalogType());
@@ -10892,7 +10891,7 @@ functionReturnDataType() throws Standard
 }
 {
     (
-        typeDescriptor = catalogType( true )
+        typeDescriptor = catalogType()
          |
         typeDescriptor = functionTableType()
     )
@@ -10959,7 +10958,7 @@ throws StandardException :
 }
 {
 	name = identifier( Limits.MAX_IDENTIFIER_LENGTH, true )
-	typeDescriptor = dataTypeDDL( true )
+	typeDescriptor = dataTypeDDL()
 	{
 		names.add( name );
 		types.add( typeDescriptor.getCatalogType() );
@@ -13319,7 +13318,7 @@ columnAlterClause(String columnName) thr
 }
 {
 	LOOKAHEAD( {getToken(2).kind == DATA} )
-	<SET> <DATA> <TYPE> typeDescriptor = dataTypeDDL( false )
+	<SET> <DATA> <TYPE> typeDescriptor = dataTypeDDL()
 	{
 		return (TableElementNode) nodeFactory.getNode(
 						C_NodeTypes.MODIFY_COLUMN_TYPE_NODE,
@@ -13835,11 +13834,11 @@ List/*<TypeDescriptor>*/ parameterTypeLi
     TypeDescriptor type;
 }
 {
-    [ type = catalogType( true )
+    [ type = catalogType()
         {
             list.add(type);
         }
-      ( <COMMA> type = catalogType( true )
+      ( <COMMA> type = catalogType()
         {
             list.add(type);
         }

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=958565&r1=958564&r2=958565&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
Mon Jun 28 13:03:34 2010
@@ -173,10 +173,7 @@ ij> drop schema "sysok" restrict;
 0 rows inserted/updated/deleted
 ij> -- data types not supported
 create table NOTYPE(i int, b BOOLEAN);
-ERROR 42X01: Syntax error: BOOLEAN.
-Issue the 'help' command for general information on IJ command syntax.
-Any unrecognized commands are treated as potential SQL commands and executed directly.
-Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
+0 rows inserted/updated/deleted
 ij> create table NOTYPE(i int, b TINYINT);
 ERROR 42X94: TYPE 'TINYINT' does not exist.
 ij> create table NOTYPE(i int, b java.lang.String);
@@ -579,10 +576,7 @@ ij> DROP TABLE tb2;
 ij> -- INSTANCEOF in where clause of select, delete, update,
 -- beetle 5224
 create table t1 (i int, s smallint, c10 char(10), vc30 varchar(30), b boolean);
-ERROR 42X01: Syntax error: BOOLEAN.
-Issue the 'help' command for general information on IJ command syntax.
-Any unrecognized commands are treated as potential SQL commands and executed directly.
-Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
+0 rows inserted/updated/deleted
 ij> create table mm (x org.apache.derbyTesting.functionTests.util.ManyMethods);
 ERROR 42X01: Syntax error: Encountered "." at line 1, column 30.
 Issue the 'help' command for general information on IJ command syntax.
@@ -668,7 +662,7 @@ Any unrecognized commands are treated as
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> -- clean up
 drop table t1;
-ERROR 42Y55: 'DROP TABLE' cannot be performed on 'T1' because it does not exist.
+0 rows inserted/updated/deleted
 ij> drop table mm;
 ERROR 42Y55: 'DROP TABLE' cannot be performed on 'MM' because it does not exist.
 ij> drop table sc;
@@ -687,10 +681,7 @@ Any unrecognized commands are treated as
 Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
 ij> --- boolean datatype already disabled
 create table testtype3(col1 boolean);
-ERROR 42X01: Syntax error: BOOLEAN.
-Issue the 'help' command for general information on IJ command syntax.
-Any unrecognized commands are treated as potential SQL commands and executed directly.
-Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
+0 rows inserted/updated/deleted
 ij> create table testtype4(col1 LONG NVARCHAR);
 ERROR 0A000: Feature not implemented: LONG NVARCHAR.
 ij> create table testtype5(col1 LONG VARBINARY);
@@ -736,7 +727,7 @@ ERROR 42Y55: 'DROP TABLE' cannot be perf
 ij> drop table testtype2;
 ERROR 42Y55: 'DROP TABLE' cannot be performed on 'TESTTYPE2' because it does not exist.
 ij> drop table testtype3;
-ERROR 42Y55: 'DROP TABLE' cannot be performed on 'TESTTYPE3' because it does not exist.
+0 rows inserted/updated/deleted
 ij> drop table testtype4;
 ERROR 42Y55: 'DROP TABLE' cannot be performed on 'TESTTYPE4' because it does not exist.
 ij> drop table testtype5;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.java?rev=958565&r1=958564&r2=958565&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMetaDataJdbc30Test.java
Mon Jun 28 13:03:34 2010
@@ -263,7 +263,15 @@ public class ParameterMetaDataJdbc30Test
              "returns varchar( 100 ) language java parameter style java no sql\n" +
              "external name 'org.apache.derbyTesting.functionTests.tests.lang.BooleanValuesTest.booleanValue'\n"
              );
+        stmt.executeUpdate
+            (
+             "create table t_boolean( b boolean )"
+             );
         stmt.close();
+
+        //
+        // Test metadata for parameters to boolean-valued functions.
+        //
         PreparedStatement ps = prepareStatement("values( booleanValue( ? ) )");
 
         ParameterMetaData paramMetaData = ps.getParameterMetaData();
@@ -279,6 +287,23 @@ public class ParameterMetaDataJdbc30Test
         testParameterMetaData(paramMetaData, parameterMetaDataArray0);
 
 		ps.close();
+
+        //
+        // Test metadata for boolean-valued columns.
+        //
+        ps = prepareStatement("insert into t_boolean values(?)");
+        ps.setBoolean(1, true);
+
+        paramMetaData = ps.getParameterMetaData();
+		assertEquals("Unexpected parameter count", 1, paramMetaData.getParameterCount());
+        parameterMetaDataArray0 = new String[][]
+            {
+                //isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName,
getParameterClassName, getParameterMode
+                {"PARAMETER_NULLABLE", "false", "1", "0", "16", "BOOLEAN", "java.lang.Boolean",
"PARAMETER_MODE_IN"},
+            };
+        testParameterMetaData(paramMetaData, parameterMetaDataArray0);
+
+        ps.close();
 	}
 
     /**

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=958565&r1=958564&r2=958565&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 13:03:34 2010
@@ -54,6 +54,7 @@ public class BooleanValuesTest  extends 
     private static final String BAD_CAST = "22018";
     private static final String NOT_UNION_COMPATIBLE = "42X61";
     private static final String BAD_CONVERSION = "42846";
+    private static final String ILLEGAL_INSERT = "42821";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -405,6 +406,22 @@ public class BooleanValuesTest  extends 
                  "external name 'org.apache.derbyTesting.functionTests.tests.lang.BooleanValuesTest.booleanValue'\n"
                  );
         }
+        
+        if ( !tableExists( conn, "BOOLEAN_TABLE" ) )
+        {
+            //
+            // create table
+            //
+            goodStatement
+                (
+                 conn,
+                 "create table boolean_table\n" +
+                 "(\n" +
+                 "    key_col int,\n" +
+                 "    boolean_col  boolean\n" +
+                 ")\n"
+                 );
+        }
     }
 
 
@@ -925,7 +942,97 @@ public class BooleanValuesTest  extends 
         rs.close();        
     }
                                                                                 
+    /**
+     * <p>
+     * Verify that tables with boolean columns behave well.
+     * </p>
+     */
+    public void test_12_booleanColumns() throws Exception
+    {
+        Connection conn = getConnection();
 
+        goodStatement( conn, "insert into boolean_table( key_col, boolean_col ) values (
0, true ), ( 1, false ), ( 2, null )" );
+        assertResults
+            (
+             conn,
+             "select * from boolean_table order by boolean_col",
+             new String[][]
+             {
+                 { "1", "false" },
+                 { "0", "true" },
+                 { "2", null },
+             },
+             false
+             );
+        goodStatement( conn, "delete from boolean_table" );
+
+        vetBadInsert( "bigint_col" );
+        vetBadInsert( "blob_col" );
+        vetBadInsert( "char_for_bit_data_col" );
+        vetBadInsert( "date_col" );
+        vetBadInsert( "decimal_col" );
+        vetBadInsert( "real_col" );
+        vetBadInsert( "double_col" );
+        vetBadInsert( "int_col" );
+        vetBadInsert( "long_varchar_for_bit_data_col" );
+        vetBadInsert( "numeric_col" );
+        vetBadInsert( "smallint_col" );
+        vetBadInsert( "time_col" );
+        vetBadInsert( "timestamp_col" );
+        vetBadInsert( "varchar_for_bit_data_col" );
+
+        vetStringInsert( conn, "char_col" );
+        vetStringInsert( conn, "clob_col" );
+        vetStringInsert( conn, "long_varchar_col" );
+        vetStringInsert( conn, "varchar_col" );
+        
+    }
+    private void vetBadInsert( String columnName ) throws Exception
+    {
+        expectCompilationError
+            (
+             ILLEGAL_INSERT,
+             "insert into boolean_table( key_col, boolean_col ) select key_col, " + columnName
+ " from all_types"
+             );
+    }
+    private void vetStringInsert( Connection conn, String columnName ) throws Exception
+    {
+        goodStatement( conn, "insert into boolean_table( key_col, boolean_col ) select key_col,
" + columnName + " from string_types where key_col < 18" );
+        assertResults
+            (
+             conn,
+             "select * from boolean_table order by key_col",
+             new String[][]
+             {
+                 { "0", "false" },
+                 { "1", "true" },
+                 { "2", null },
+                 { "3", null },
+                 { "4", "false" },
+                 { "5", "true" },
+                 { "6", null },
+                 { "7", null },
+                 { "10", "false" },
+                 { "11", "true" },
+                 { "12", null },
+                 { "13", null },
+                 { "14", "false" },
+                 { "15", "true" },
+                 { "16", null },
+                 { "17", null },
+             },
+             false
+             );
+        
+        for ( int i = 20; i < 24; i++ )
+        {
+            expectExecutionError
+                ( conn, BAD_CAST, "insert into boolean_table( key_col, boolean_col ) select
key_col, " + columnName + " from string_types where key_col = " + i );
+        }
+
+        goodStatement( conn, "delete from boolean_table" );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // SQL ROUTINES



Mime
View raw message