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 rh...@apache.org on 2008/10/27 14:27:27 UTC
svn commit: r708169 - in /db/derby/code/trunk/java:
engine/org/apache/derby/catalog/types/
engine/org/apache/derby/iapi/sql/compile/
engine/org/apache/derby/impl/sql/compile/
testing/org/apache/derbyTesting/functionTests/master/
testing/org/apache/derb...
Author: rhillegas
Date: Mon Oct 27 06:27:26 2008
New Revision: 708169
URL: http://svn.apache.org/viewvc?rev=708169&view=rev
Log:
DERBY-481: Grammar changes for declaring generated columns.
Added:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java (with props)
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DDLStatementNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
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/DerbyNet/dblook_test_net.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net_territory.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net_territory.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test_territory.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java
db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_Table.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java Mon Oct 27 06:27:26 2008
@@ -117,7 +117,11 @@
if(isDefaultValueAutoinc()){
return "GENERATED_BY_DEFAULT";
}
- return defaultText;
+ else if ( isGeneratedColumn() )
+ {
+ return "GENERATED ALWAYS AS ( " + defaultText + " )";
+ }
+ else { return defaultText; }
}
// Formatable methods
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/C_NodeTypes.java Mon Oct 27 06:27:26 2008
@@ -230,8 +230,11 @@
static final int WINDOW_NODE = 220;
static final int ROW_NUMBER_COLUMN_NODE = 221;
+ // generated columns
+ static final int GENERATION_CLAUSE_NODE = 222;
+
// Final value in set, keep up to date!
- static final int FINAL_VALUE = ROW_NUMBER_COLUMN_NODE;
+ static final int FINAL_VALUE = GENERATION_CLAUSE_NODE;
/**
* Extensions to this interface can use nodetypes > MAX_NODE_TYPE with out fear of collision
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/CompilerContext.java Mon Oct 27 06:27:26 2008
@@ -99,6 +99,8 @@
*/
public static final int MODIFIES_SQL_DATA_PROCEDURE_ILLEGAL = 0x00000800;
+ public static final int NON_DETERMINISTIC_ILLEGAL = 0x00001000;
+
/** Standard SQL is legal */
public static final int SQL_LEGAL = (INTERNAL_SQL_ILLEGAL);
@@ -122,6 +124,11 @@
INTERNAL_SQL_ILLEGAL
);
+ public static final int GENERATION_CLAUSE_RESTRICTION = (
+ CHECK_CONSTRAINT |
+ NON_DETERMINISTIC_ILLEGAL
+ );
+
/////////////////////////////////////////////////////////////////////////////////////
//
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java Mon Oct 27 06:27:26 2008
@@ -299,6 +299,7 @@
{
DataDictionary dd = getDataDictionary();
int numCheckConstraints = 0;
+ int numGenerationClauses = 0;
int numBackingIndexes = 0;
/*
@@ -365,6 +366,8 @@
/* Check the validity of all check constraints */
numCheckConstraints = tableElementList.countConstraints(
DataDictionary.CHECK_CONSTRAINT);
+
+ numGenerationClauses = tableElementList.countGenerationClauses();
}
//If the sum of backing indexes for constraints in alter table statement and total number of indexes on the table
@@ -377,9 +380,10 @@
String.valueOf(Limits.DB2_MAX_INDEXES_ON_TABLE));
}
- if (numCheckConstraints > 0)
+ if ( (numCheckConstraints > 0) || (numGenerationClauses > 0) )
{
- /* In order to check the validity of the check constraints
+ /* In order to check the validity of the check constraints and
+ * generation clauses
* we must goober up a FromList containing a single table,
* the table being alter, with an RCL containing the existing and
* new columns and their types. This will allow us to
@@ -387,31 +391,13 @@
* FromList. When doing this, we verify that there are
* no nodes which can return non-deterministic results.
*/
- FromList fromList = (FromList) getNodeFactory().getNode(
- C_NodeTypes.FROM_LIST,
- getNodeFactory().doJoinOrderOptimization(),
- getContextManager());
- FromBaseTable table = (FromBaseTable)
- getNodeFactory().getNode(
- C_NodeTypes.FROM_BASE_TABLE,
- getObjectName(),
- null,
- null,
- null,
- getContextManager());
- fromList.addFromTable(table);
- fromList.bindTables(dd,
- (FromList) getNodeFactory().getNode(
- C_NodeTypes.FROM_LIST,
- getNodeFactory().doJoinOrderOptimization(),
- getContextManager()));
- tableElementList.appendNewColumnsToRCL(table);
+ FromList fromList = makeFromList( dd, tableElementList, false );
/* Now that we've finally goobered stuff up, bind and validate
- * the check constraints.
+ * the check constraints and generation clauses.
*/
- tableElementList.bindAndValidateCheckConstraints(fromList);
-
+ if (numCheckConstraints > 0) { tableElementList.bindAndValidateCheckConstraints(fromList); }
+ if (numGenerationClauses > 0) { tableElementList.bindAndValidateGenerationClauses(fromList); }
}
//Check if we are in alter table to update the statistics. If yes, then
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/C_NodeNames.java Mon Oct 27 06:27:26 2008
@@ -146,6 +146,8 @@
static final String FROM_VTI_NAME = "org.apache.derby.impl.sql.compile.FromVTI";
+ static final String GENERATION_CLAUSE_NODE_NAME = "org.apache.derby.impl.sql.compile.GenerationClauseNode";
+
static final String GET_CURRENT_CONNECTION_NODE_NAME = "org.apache.derby.impl.sql.compile.GetCurrentConnectionNode";
static final String GRANT_NODE_NAME = "org.apache.derby.impl.sql.compile.GrantNode";
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=708169&r1=708168&r2=708169&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 Oct 27 06:27:26 2008
@@ -76,6 +76,7 @@
DataValueDescriptor defaultValue;
DefaultInfoImpl defaultInfo;
DefaultNode defaultNode;
+ GenerationClauseNode generationClauseNode;
long autoincrementIncrement;
long autoincrementStart;
//This variable tells if the autoincrement column is participating
@@ -129,6 +130,10 @@
convertDefaultNode(this.type);
}
}
+ else if (defaultNode instanceof GenerationClauseNode)
+ {
+ generationClauseNode = (GenerationClauseNode) defaultNode;
+ }
else
{
if (SanityManager.DEBUG)
@@ -211,6 +216,9 @@
{
return type;
}
+
+ /** Set the type of this column */
+ public void setType( DataTypeDescriptor dts ) { type = dts; }
/**
* Set the nullability of the column definition node.
@@ -255,6 +263,11 @@
}
/**
+ * Set the generation clause (Default) bound to this column.
+ */
+ public void setDefaultInfo( DefaultInfoImpl dii ) { defaultInfo = dii; }
+
+ /**
* Return the DefaultNode, if any, associated with this node.
*
* @return The DefaultNode, if any, associated with this node.
@@ -265,6 +278,16 @@
}
/**
+ * Return true if this column has a generation clause.
+ */
+ public boolean hasGenerationClause() { return ( generationClauseNode != null ); }
+
+ /**
+ * Get the generation clause.
+ */
+ public GenerationClauseNode getGenerationClauseNode() { return generationClauseNode; }
+
+ /**
* Is this an autoincrement column?
*
* @return Whether or not this is an autoincrement column.
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java Mon Oct 27 06:27:26 2008
@@ -235,6 +235,7 @@
int numCheckConstraints = 0;
int numReferenceConstraints = 0;
int numUniqueConstraints = 0;
+ int numGenerationClauses = 0;
if (queryExpression != null)
{
@@ -403,6 +404,8 @@
numUniqueConstraints = tableElementList.countConstraints(
DataDictionary.UNIQUE_CONSTRAINT);
+ numGenerationClauses = tableElementList.countGenerationClauses();
+
//temp tables can't have primary key or check or foreign key or unique constraints defined on them
if ((tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) &&
(numPrimaryKeys > 0 || numCheckConstraints > 0 || numReferenceConstraints > 0 || numUniqueConstraints > 0))
@@ -418,9 +421,10 @@
String.valueOf(Limits.DB2_MAX_INDEXES_ON_TABLE));
}
- if (numCheckConstraints > 0)
+ if ( (numCheckConstraints > 0) || (numGenerationClauses > 0) )
{
- /* In order to check the validity of the check constraints
+ /* In order to check the validity of the check constraints and
+ * generation clauses
* we must goober up a FromList containing a single table,
* the table being created, with an RCL containing the
* new columns and their types. This will allow us to
@@ -428,37 +432,13 @@
* FromList. When doing this, we verify that there are
* no nodes which can return non-deterministic results.
*/
- FromList fromList = (FromList) getNodeFactory().getNode(
- C_NodeTypes.FROM_LIST,
- getNodeFactory().doJoinOrderOptimization(),
- getContextManager());
- // DERBY-3043: To avoid a no-such-schema error when
- // binding the check constraint, ensure that the
- // table we bind against has a schema name specified.
- // If it doesn't, fill in the schema name now.
- //
- TableName newTN = getObjectName();
- if (newTN.getSchemaName() == null)
- newTN.setSchemaName(getSchemaDescriptor().getSchemaName());
- FromBaseTable table = (FromBaseTable)
- getNodeFactory().getNode(
- C_NodeTypes.FROM_BASE_TABLE,
- newTN,
- null,
- null,
- null,
- getContextManager());
- table.setTableNumber(0);
- fromList.addFromTable(table);
- table.setResultColumns((ResultColumnList) getNodeFactory().getNode(
- C_NodeTypes.RESULT_COLUMN_LIST,
- getContextManager()));
- tableElementList.appendNewColumnsToRCL(table);
+ FromList fromList = makeFromList( null, tableElementList, true );
/* Now that we've finally goobered stuff up, bind and validate
- * the check constraints.
+ * the check constraints and generation clauses.
*/
- tableElementList.bindAndValidateCheckConstraints(fromList);
+ if (numCheckConstraints > 0) { tableElementList.bindAndValidateCheckConstraints(fromList); }
+ if (numGenerationClauses > 0) { tableElementList.bindAndValidateGenerationClauses(fromList); }
}
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DDLStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DDLStatementNode.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DDLStatementNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DDLStatementNode.java Mon Oct 27 06:27:26 2008
@@ -29,6 +29,7 @@
import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
import org.apache.derby.iapi.sql.compile.CompilerContext;
+import org.apache.derby.iapi.sql.compile.C_NodeTypes;
import org.apache.derby.iapi.sql.conn.Authorizer;
import org.apache.derby.iapi.reference.SQLState;
import org.apache.derby.iapi.error.StandardException;
@@ -428,4 +429,71 @@
if (objectName != null)
objectName.bind( dataDictionary );
}
+
+ /**
+ * Make a from list for binding query fragments in a CREATE/ALTER TABLE
+ * statement.
+ *
+ * @param creatingTable true if this is for CREATE TABLE. false if this is for ALTER TABLE
+ */
+ FromList makeFromList( DataDictionary dd, TableElementList tableElementList, boolean creatingTable )
+ throws StandardException
+ {
+ // DERBY-3043: To avoid a no-such-schema error when
+ // binding the check constraint, ensure that the
+ // table we bind against has a schema name specified.
+ // If it doesn't, fill in the schema name now.
+ //
+ TableName tableName = getObjectName();
+ if (tableName.getSchemaName() == null)
+ { tableName.setSchemaName(getSchemaDescriptor().getSchemaName()); }
+
+ FromList fromList = (FromList) getNodeFactory().getNode
+ (
+ C_NodeTypes.FROM_LIST,
+ getNodeFactory().doJoinOrderOptimization(),
+ getContextManager()
+ );
+ FromBaseTable table = (FromBaseTable) getNodeFactory().getNode
+ (
+ C_NodeTypes.FROM_BASE_TABLE,
+ tableName,
+ null,
+ null,
+ null,
+ getContextManager()
+ );
+
+ if ( creatingTable )
+ {
+ table.setTableNumber(0);
+ fromList.addFromTable(table);
+ table.setResultColumns
+ ((ResultColumnList) getNodeFactory().getNode
+ (
+ C_NodeTypes.RESULT_COLUMN_LIST,
+ getContextManager()
+ )
+ );
+ }
+ else // ALTER TABLE
+ {
+ fromList.addFromTable(table);
+ fromList.bindTables
+ (
+ dd,
+ (FromList) getNodeFactory().getNode
+ (
+ C_NodeTypes.FROM_LIST,
+ getNodeFactory().doJoinOrderOptimization(),
+ getContextManager()
+ )
+ );
+ }
+
+ tableElementList.appendNewColumnsToRCL(table);
+
+ return fromList;
+ }
+
}
Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java?rev=708169&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java Mon Oct 27 06:27:26 2008
@@ -0,0 +1,161 @@
+/*
+
+ Derby - Class org.apache.derby.impl.sql.compile.GenerationClauseNode
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+
+package org.apache.derby.impl.sql.compile;
+
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
+
+import org.apache.derby.iapi.sql.compile.CompilerContext;
+
+import org.apache.derby.iapi.sql.depend.ProviderList;
+
+import org.apache.derby.iapi.reference.SQLState;
+
+import org.apache.derby.iapi.types.TypeId;
+import org.apache.derby.iapi.types.DataTypeDescriptor;
+
+import org.apache.derby.iapi.services.compiler.MethodBuilder;
+import org.apache.derby.iapi.services.compiler.LocalField;
+import org.apache.derby.iapi.services.sanity.SanityManager;
+
+ import org.apache.derby.iapi.store.access.Qualifier;
+
+import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
+
+import java.lang.reflect.Modifier;
+
+import org.apache.derby.iapi.error.StandardException;
+
+import java.sql.Types;
+
+import java.util.Vector;
+
+/**
+ * This node describes a Generation Clause in a column definition.
+ *
+ */
+public class GenerationClauseNode extends ValueNode
+{
+ ///////////////////////////////////////////////////////////////////////////////////
+ //
+ // CONSTANTS
+ //
+ ///////////////////////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////////////////////
+ //
+ // STATE
+ //
+ ///////////////////////////////////////////////////////////////////////////////////
+
+ private ValueNode _generationExpression;
+ private String _expressionText;
+
+ private ValueNode _boundExpression;
+ private ProviderList _apl;
+
+ ///////////////////////////////////////////////////////////////////////////////////
+ //
+ // INITIALIZATION
+ //
+ ///////////////////////////////////////////////////////////////////////////////////
+
+
+ public void init( Object generationExpression, Object expressionText )
+ {
+ _generationExpression = (ValueNode) generationExpression;
+ _expressionText = (String) expressionText;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////
+ //
+ // ACCESSORS
+ //
+ ///////////////////////////////////////////////////////////////////////////////////
+
+ /** Get the defining text of this generation clause */
+ public String getExpressionText() { return _expressionText; }
+
+ /** Set the auxiliary provider list. */
+ void setAuxiliaryProviderList(ProviderList apl) { _apl = apl; }
+
+ /** Return the auxiliary provider list. */
+ public ProviderList getAuxiliaryProviderList() { return _apl; }
+
+ ///////////////////////////////////////////////////////////////////////////////////
+ //
+ // QueryTreeNode BEHAVIOR
+ //
+ ///////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Binding the generation clause.
+ */
+ public ValueNode bindExpression
+ ( FromList fromList, SubqueryList subqueryList, Vector aggregateVector )
+ throws StandardException
+ {
+ _boundExpression = _generationExpression.bindExpression( fromList, subqueryList, aggregateVector );
+
+ return _boundExpression;
+ }
+
+ /**
+ * Generate code for this node.
+ *
+ * @param acb The ExpressionClassBuilder for the class being built
+ * @param mb The method the code to place the code
+ *
+ * @exception StandardException Thrown on error
+ */
+ public void generateExpression(ExpressionClassBuilder acb,
+ MethodBuilder mb)
+ throws StandardException
+ {
+ throw StandardException.newException( SQLState.HEAP_UNIMPLEMENTED_FEATURE );
+ }
+
+ protected boolean isEquivalent(ValueNode other)
+ throws StandardException
+ {
+ if ( !( other instanceof GenerationClauseNode) ) { return false; }
+
+ GenerationClauseNode that = (GenerationClauseNode) other;
+
+ return this._generationExpression.isEquivalent( that._generationExpression );
+ }
+
+ /*
+ Stringify.
+ */
+ public String toString()
+ {
+ return "GENERATED ALWAYS( " + _expressionText + " )";
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////
+ //
+ // MINIONS
+ //
+ ///////////////////////////////////////////////////////////////////////////////////
+
+}
Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NodeFactoryImpl.java Mon Oct 27 06:27:26 2008
@@ -617,6 +617,9 @@
case C_NodeTypes.WINDOW_NODE:
return C_NodeNames.WINDOW_NODE_NAME;
+ case C_NodeTypes.GENERATION_CLAUSE_NODE:
+ return C_NodeNames.GENERATION_CLAUSE_NODE_NAME;
+
case C_NodeTypes.ROW_NUMBER_COLUMN_NODE:
return C_NodeNames.ROW_NUMBER_COLUMN_NODE_NAME;
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java Mon Oct 27 06:27:26 2008
@@ -25,6 +25,7 @@
import org.apache.derby.catalog.AliasInfo;
import org.apache.derby.catalog.types.SynonymAliasInfo;
+import org.apache.derby.iapi.services.i18n.MessageService;
import org.apache.derby.iapi.error.StandardException;
import org.apache.derby.iapi.reference.ClassName;
import org.apache.derby.iapi.reference.JDBC40Translation;
@@ -1157,12 +1158,25 @@
)
throws StandardException
{
- return (TableName) getNodeFactory().getNode
+ return makeTableName
+ ( getNodeFactory(), getContextManager(), schemaName, flatName );
+ }
+
+ public static TableName makeTableName
+ (
+ NodeFactory nodeFactory,
+ ContextManager contextManager,
+ String schemaName,
+ String flatName
+ )
+ throws StandardException
+ {
+ return (TableName) nodeFactory.getNode
(
C_NodeTypes.TABLE_NAME,
schemaName,
flatName,
- getContextManager()
+ contextManager
);
}
@@ -1470,6 +1484,78 @@
"void", 2);
}
+ /**
+ * Bind time logic. Raises an error if this ValueNode, once compiled, returns
+ * unstable results AND if we're in a context where unstable results are
+ * forbidden.
+ *
+ * Called by children who may NOT appear in the WHERE subclauses of ADD TABLE clauses.
+ *
+ * @param fragmentType Type of fragment as a String, for inclusion in error messages.
+ * @param fragmentBitMask Type of fragment as a bitmask of possible fragment types
+ *
+ * @exception StandardException Thrown on error
+ */
+ public void checkReliability( String fragmentType, int fragmentBitMask )
+ throws StandardException
+ {
+ // if we're in a context that forbids unreliable fragments, raise an error
+ if ( ( getCompilerContext().getReliability() & fragmentBitMask ) != 0 )
+ {
+ throwReliabilityException( fragmentType );
+ }
+ }
+
+ /**
+ * Bind time logic. Raises an error if this ValueNode, once compiled, returns
+ * unstable results AND if we're in a context where unstable results are
+ * forbidden.
+ *
+ * Called by children who may NOT appear in the WHERE subclauses of ADD TABLE clauses.
+ *
+ * @param fragmentBitMask Type of fragment as a bitmask of possible fragment types
+ * @param fragmentType Type of fragment as a String, to be fetch for the error message.
+ *
+ * @exception StandardException Thrown on error
+ */
+ public void checkReliability( int fragmentBitMask, String fragmentType )
+ throws StandardException
+ {
+ // if we're in a context that forbids unreliable fragments, raise an error
+ if ( ( getCompilerContext().getReliability() & fragmentBitMask ) != 0 )
+ {
+ String fragmentTypeTxt = MessageService.getTextMessage( fragmentType );
+ throwReliabilityException( fragmentTypeTxt );
+ }
+ }
+
+ /**
+ * Common code for the 2 checkReliability functions. Always throws StandardException.
+ *
+ * @param fragmentType Type of fragment as a string, for inclusion in error messages.
+ * @exception StandardException Throws an error, always.
+ */
+ private void throwReliabilityException( String fragmentType ) throws StandardException
+ {
+ String sqlState;
+ /* Error string somewhat dependent on operation due to different
+ * nodes being allowed for different operations.
+ */
+ if (getCompilerContext().getReliability() == CompilerContext.DEFAULT_RESTRICTION)
+ {
+ sqlState = SQLState.LANG_INVALID_DEFAULT_DEFINITION;
+ }
+ else if (getCompilerContext().getReliability() == CompilerContext.GENERATION_CLAUSE_RESTRICTION)
+ {
+ sqlState = SQLState.LANG_NON_DETERMINISTIC_GENERATION_CLAUSE;
+ }
+ else
+ {
+ sqlState = SQLState.LANG_UNRELIABLE_QUERY_FRAGMENT;
+ }
+ throw StandardException.newException(sqlState, fragmentType);
+ }
+
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java Mon Oct 27 06:27:26 2008
@@ -197,7 +197,7 @@
// The field methodName is used by resolveRoutine and
// is set to the name of the routine (procedureName.getTableName()).
resolveRoutine(fromList, subqueryList, aggregateVector, sd);
-
+
if (ad == null && noSchema && !forCallStatement)
{
// Resolve to a built-in SYSFUN function but only
@@ -210,7 +210,6 @@
resolveRoutine(fromList, subqueryList, aggregateVector, sd);
}
-
/* Throw exception if no routine found */
if (ad == null)
{
@@ -218,6 +217,11 @@
SQLState.LANG_NO_SUCH_METHOD_ALIAS, procedureName);
}
+ if ( !routineInfo.isDeterministic() )
+ {
+ checkReliability( getMethodName(), CompilerContext.NON_DETERMINISTIC_ILLEGAL );
+ }
+
/* Query is dependent on the AliasDescriptor */
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java Mon Oct 27 06:27:26 2008
@@ -30,6 +30,9 @@
import org.apache.derby.iapi.types.DataTypeDescriptor;
import org.apache.derby.iapi.types.StringDataValue;
+import org.apache.derby.iapi.types.TypeId;
+
+import org.apache.derby.catalog.types.DefaultInfoImpl;
import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
import org.apache.derby.iapi.sql.dictionary.DataDictionary;
@@ -379,6 +382,35 @@
return numConstraints;
}
+ /**
+ * Count the number of generation clauses.
+ */
+ public int countGenerationClauses()
+ {
+ int numGenerationClauses = 0;
+ int size = size();
+
+ for (int index = 0; index < size; index++)
+ {
+ ColumnDefinitionNode cdn;
+ TableElementNode element = (TableElementNode) elementAt(index);
+
+ if (! (element instanceof ColumnDefinitionNode))
+ {
+ continue;
+ }
+
+ cdn = (ColumnDefinitionNode) element;
+
+ if ( cdn.hasGenerationClause() )
+ {
+ numGenerationClauses++;
+ }
+ }
+
+ return numGenerationClauses;
+ }
+
/**
* Count the number of columns.
*
@@ -620,6 +652,131 @@
}
/**
+ * Bind and validate all of the generation clauses in this list against
+ * the specified FromList.
+ *
+ * @param fromList The FromList in question.
+ *
+ * @exception StandardException Thrown on error
+ */
+ void bindAndValidateGenerationClauses(FromList fromList)
+ throws StandardException
+ {
+ CompilerContext cc;
+ FromBaseTable table = (FromBaseTable) fromList.elementAt(0);
+ int size = size();
+
+ cc = getCompilerContext();
+
+ Vector aggregateVector = new Vector();
+
+ for (int index = 0; index < size; index++)
+ {
+ ColumnDefinitionNode cdn;
+ TableElementNode element = (TableElementNode) elementAt(index);
+ GenerationClauseNode generationClauseNode;
+ ValueNode generationTree;
+
+ if (! (element instanceof ColumnDefinitionNode))
+ {
+ continue;
+ }
+
+ cdn = (ColumnDefinitionNode) element;
+
+ if (!cdn.hasGenerationClause())
+ {
+ continue;
+ }
+
+ generationClauseNode = cdn.getGenerationClauseNode();
+
+ // bind the check condition
+ // verify that it evaluates to a boolean
+ final int previousReliability = cc.getReliability();
+ try
+ {
+ /* Each generation clause can have its own set of dependencies.
+ * These dependencies need to be shared with the prepared
+ * statement as well. We create a new auxiliary provider list
+ * for the generation clause, "push" it on the compiler context
+ * by swapping it with the current auxiliary provider list
+ * and the "pop" it when we're done by restoring the old
+ * auxiliary provider list.
+ */
+ ProviderList apl = new ProviderList();
+
+ ProviderList prevAPL = cc.getCurrentAuxiliaryProviderList();
+ cc.setCurrentAuxiliaryProviderList(apl);
+
+ // Tell the compiler context to forbid subqueries and
+ // non-deterministic functions.
+ cc.setReliability( CompilerContext.GENERATION_CLAUSE_RESTRICTION );
+ generationTree = generationClauseNode.bindExpression(fromList, (SubqueryList) null,
+ aggregateVector);
+
+ //
+ // If the user did not declare a type for this column, then the column type defaults
+ // to the type of the generation clause.
+ // However, if the user did declare a type for this column, then the
+ // type of the generation clause must be assignable to the declared
+ // type.
+ //
+ DataTypeDescriptor generationClauseType = generationTree.getTypeServices();
+ DataTypeDescriptor declaredType = cdn.getType();
+ if ( declaredType == null ) { cdn.setType( generationClauseType ); }
+ {
+ TypeId declaredTypeId = declaredType.getTypeId();
+ TypeId resolvedTypeId = generationClauseType.getTypeId();
+
+ if ( !getTypeCompiler( resolvedTypeId ).convertible( declaredTypeId, false ) )
+ {
+ throw StandardException.newException
+ ( SQLState.LANG_UNASSIGNABLE_GENERATION_CLAUSE, cdn.getName(), resolvedTypeId.getSQLTypeName() );
+ }
+ }
+
+ // no aggregates, please
+ if (aggregateVector.size() != 0)
+ {
+ throw StandardException.newException( SQLState.LANG_AGGREGATE_IN_GENERATION_CLAUSE, cdn.getName());
+ }
+
+ /* Save the APL off in the constraint node */
+ if (apl.size() > 0)
+ {
+ generationClauseNode.setAuxiliaryProviderList(apl);
+ }
+
+ // Restore the previous AuxiliaryProviderList
+ cc.setCurrentAuxiliaryProviderList(prevAPL);
+ }
+ finally
+ {
+ cc.setReliability(previousReliability);
+ }
+
+ /* We have a valid generation clause, now build an array of
+ * 1-based columnIds that the clause references.
+ */
+ ResultColumnList rcl = table.getResultColumns();
+ int numReferenced = rcl.countReferencedColumns();
+ int[] generationClauseColumnReferences = new int[numReferenced];
+
+ rcl.recordColumnReferences(generationClauseColumnReferences, 1);
+
+ DefaultInfoImpl dii = new DefaultInfoImpl
+ ( generationClauseNode.getExpressionText(), generationClauseColumnReferences );
+ cdn.setDefaultInfo( dii );
+
+ /* Clear the column references in the RCL so each generation clause
+ * starts with a clean list.
+ */
+ rcl.clearColumnReferences();
+ }
+ }
+
+ /**
* Fill in the ConstraintConstantAction[] for this create/alter table.
*
* @param forCreateTable ConstraintConstantAction is for a create table.
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java Mon Oct 27 06:27:26 2008
@@ -842,74 +842,6 @@
}
/**
- * Bind time logic. Raises an error if this ValueNode, once compiled, returns
- * unstable results AND if we're in a context where unstable results are
- * forbidden.
- *
- * Called by children who may NOT appear in the WHERE subclauses of ADD TABLE clauses.
- *
- * @param fragmentType Type of fragment as a String, for inclusion in error messages.
- * @param fragmentBitMask Type of fragment as a bitmask of possible fragment types
- *
- * @exception StandardException Thrown on error
- */
- public void checkReliability( String fragmentType, int fragmentBitMask )
- throws StandardException
- {
- // if we're in a context that forbids unreliable fragments, raise an error
- if ( ( getCompilerContext().getReliability() & fragmentBitMask ) != 0 )
- {
- throwReliabilityException( fragmentType );
- }
- }
-
- /**
- * Bind time logic. Raises an error if this ValueNode, once compiled, returns
- * unstable results AND if we're in a context where unstable results are
- * forbidden.
- *
- * Called by children who may NOT appear in the WHERE subclauses of ADD TABLE clauses.
- *
- * @param fragmentBitMask Type of fragment as a bitmask of possible fragment types
- * @param fragmentType Type of fragment as a String, to be fetch for the error message.
- *
- * @exception StandardException Thrown on error
- */
- public void checkReliability( int fragmentBitMask, String fragmentType )
- throws StandardException
- {
- // if we're in a context that forbids unreliable fragments, raise an error
- if ( ( getCompilerContext().getReliability() & fragmentBitMask ) != 0 )
- {
- String fragmentTypeTxt = MessageService.getTextMessage( fragmentType );
- throwReliabilityException( fragmentTypeTxt );
- }
- }
-
- /**
- * Common code for the 2 checkReliability functions. Always throws StandardException.
- *
- * @param fragmentType Type of fragment as a string, for inclusion in error messages.
- * @exception StandardException Throws an error, always.
- */
- private void throwReliabilityException( String fragmentType ) throws StandardException
- {
- String sqlState;
- /* Error string somewhat dependent on operation due to different
- * nodes being allowed for different operations.
- */
- if (getCompilerContext().getReliability() == CompilerContext.DEFAULT_RESTRICTION)
- {
- sqlState = SQLState.LANG_INVALID_DEFAULT_DEFINITION;
- }
- else
- {
- sqlState = SQLState.LANG_UNRELIABLE_QUERY_FRAGMENT;
- }
- throw StandardException.newException(sqlState, fragmentType);
- }
-
- /**
* Return the variant type for the underlying expression.
* The variant type can be:
* VARIANT - variant within a scan
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=708169&r1=708168&r2=708169&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 Oct 27 06:27:26 2008
@@ -10595,6 +10595,7 @@
{
return value;
}
+
}
/*
@@ -10634,21 +10635,113 @@
autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_CREATE_MODIFY] = ColumnDefinitionNode.CREATE_AUTOINCREMENT;
}
- <GENERATED>
- (
- <ALWAYS> {
- value = null;
- }|
- <BY> <_DEFAULT> {
+ <GENERATED>
+ (
+ value = generatedAlways( autoIncrementInfo )
+ {
+ return value;
+ }
+ |
+ value = generatedByDefault( autoIncrementInfo )
+ {
+ return value;
+ }
+ )
+
+}
+
+/*
+ * <A NAME="generatedAlways">generatedAlways</A>
+ */
+ValueNode
+generatedAlways(long[] autoIncrementInfo) throws StandardException :
+{
+ ValueNode value = null;
+}
+{
+ <ALWAYS>
+ (
+ LOOKAHEAD ( { getToken(1).kind == AS && getToken(2).kind == IDENTITY } )
+ asIdentity( autoIncrementInfo )
+ {
+ return value;
+ }
+ |
+ LOOKAHEAD ( { getToken(1).kind == AS && getToken(2).kind == LEFT_PAREN } )
+ value = generationClause()
+ {
+ return value;
+ }
+ )
+}
+
+/*
+ * <A NAME="generatedByDefault">generatedByDefault</A>
+ */
+
+ValueNode
+generatedByDefault(long[] autoIncrementInfo) throws StandardException :
+{
+ ValueNode value = null;
+}
+{
+ <BY> <_DEFAULT> asIdentity( autoIncrementInfo )
+ {
checkVersion(DataDictionary.DD_VERSION_DERBY_10_1,
"GENERATED BY DEFAULT");
value = (ValueNode) nodeFactory.getNode(C_NodeTypes.DEFAULT_NODE,
- getContextManager()) ;}
- )
+ getContextManager()) ;
+
+ return value;
+ }
+
+}
+
+/*
+ * <A NAME="asIdentity">asIdentity</A>
+ */
+
+void
+asIdentity( long[] autoIncrementInfo) throws StandardException :
+{
+}
+{
<AS> <IDENTITY> [<LEFT_PAREN> autoIncrementBeginEnd(autoIncrementInfo) <RIGHT_PAREN>]
{
- return value;
+ return;
+ }
+
+}
+
+/*
+ * <A NAME="generationClause">generationClause</A>
+ */
+ValueNode
+generationClause() throws StandardException :
+{
+ ValueNode value = null;
+ Token beginToken = null;
+ Token endToken = null;
+}
+{
+ <AS> beginToken = <LEFT_PAREN> value = valueExpression( false ) endToken = <RIGHT_PAREN>
+ {
+ checkVersion(DataDictionary.DD_VERSION_DERBY_10_5, "GENERATED COLUMN");
+
+ return (ValueNode) nodeFactory.getNode
+ (
+ C_NodeTypes.GENERATION_CLAUSE_NODE,
+ value,
+ StringUtil.slice
+ (
+ statementSQLText,
+ beginToken.endOffset + 1,
+ endToken.beginOffset - 1,
+ true
+ ),
+ getContextManager()
+ );
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out Mon Oct 27 06:27:26 2008
@@ -599,6 +599,96 @@
null
null
-----
+T_GENCOL_1
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_1
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( 1 )
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_1
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+B
+2
+INTEGER
+<systemid>
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( a + c )
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
V"3
I
1
@@ -900,6 +990,33 @@
<systemid>
-----
APP
+T_GENCOL_1
+<systemnumber>
+T_GENCOL_1
+false
+null
+false
+<systemid>
+-----
+APP
+T_GENCOL_2
+<systemnumber>
+T_GENCOL_2
+false
+null
+false
+<systemid>
+-----
+APP
+T_GENCOL_3
+<systemnumber>
+T_GENCOL_3
+false
+null
+false
+<systemid>
+-----
+APP
X
<systemnumber>
X
@@ -1795,6 +1912,24 @@
FOO
R
-----
+T_GENCOL_1
+T_GENCOL_1
+T
+APP
+R
+-----
+T_GENCOL_2
+T_GENCOL_2
+T
+APP
+R
+-----
+T_GENCOL_3
+T_GENCOL_3
+T
+APP
+R
+-----
V"3
V"3
V
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net_territory.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net_territory.out?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net_territory.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net_territory.out Mon Oct 27 06:27:26 2008
@@ -599,6 +599,96 @@
null
null
-----
+T_GENCOL_1
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_1
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( 1 )
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_1
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+B
+2
+INTEGER
+<systemid>
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( a + c )
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
V"3
I
1
@@ -900,6 +990,33 @@
<systemid>
-----
APP
+T_GENCOL_1
+<systemnumber>
+T_GENCOL_1
+false
+null
+false
+<systemid>
+-----
+APP
+T_GENCOL_2
+<systemnumber>
+T_GENCOL_2
+false
+null
+false
+<systemid>
+-----
+APP
+T_GENCOL_3
+<systemnumber>
+T_GENCOL_3
+false
+null
+false
+<systemid>
+-----
+APP
X
<systemnumber>
X
@@ -1795,6 +1912,24 @@
FOO
R
-----
+T_GENCOL_1
+T_GENCOL_1
+T
+APP
+R
+-----
+T_GENCOL_2
+T_GENCOL_2
+T
+APP
+R
+-----
+T_GENCOL_3
+T_GENCOL_3
+T
+APP
+R
+-----
V"3
V"3
V
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out Mon Oct 27 06:27:26 2008
@@ -599,6 +599,96 @@
null
null
-----
+T_GENCOL_1
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_1
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( 1 )
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_1
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+B
+2
+INTEGER
+<systemid>
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( a + c )
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
V"3
I
1
@@ -900,6 +990,33 @@
<systemid>
-----
APP
+T_GENCOL_1
+<systemnumber>
+T_GENCOL_1
+false
+null
+false
+<systemid>
+-----
+APP
+T_GENCOL_2
+<systemnumber>
+T_GENCOL_2
+false
+null
+false
+<systemid>
+-----
+APP
+T_GENCOL_3
+<systemnumber>
+T_GENCOL_3
+false
+null
+false
+<systemid>
+-----
+APP
X
<systemnumber>
X
@@ -1795,6 +1912,24 @@
FOO
R
-----
+T_GENCOL_1
+T_GENCOL_1
+T
+APP
+R
+-----
+T_GENCOL_2
+T_GENCOL_2
+T
+APP
+R
+-----
+T_GENCOL_3
+T_GENCOL_3
+T
+APP
+R
+-----
V"3
V"3
V
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net_territory.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net_territory.out?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net_territory.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net_territory.out Mon Oct 27 06:27:26 2008
@@ -599,6 +599,96 @@
null
null
-----
+T_GENCOL_1
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_1
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( 1 )
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_1
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+B
+2
+INTEGER
+<systemid>
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_2
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( a + c )
+<systemid>
+<autoincval>
+null
+null
+-----
+T_GENCOL_3
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+-----
V"3
I
1
@@ -900,6 +990,33 @@
<systemid>
-----
APP
+T_GENCOL_1
+<systemnumber>
+T_GENCOL_1
+false
+null
+false
+<systemid>
+-----
+APP
+T_GENCOL_2
+<systemnumber>
+T_GENCOL_2
+false
+null
+false
+<systemid>
+-----
+APP
+T_GENCOL_3
+<systemnumber>
+T_GENCOL_3
+false
+null
+false
+<systemid>
+-----
+APP
X
<systemnumber>
X
@@ -1795,6 +1912,24 @@
FOO
R
-----
+T_GENCOL_1
+T_GENCOL_1
+T
+APP
+R
+-----
+T_GENCOL_2
+T_GENCOL_2
+T
+APP
+R
+-----
+T_GENCOL_3
+T_GENCOL_3
+T
+APP
+R
+-----
V"3
V"3
V
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out Mon Oct 27 06:27:26 2008
@@ -592,6 +592,96 @@
null
null
----
+T_GENCOL_1
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_1
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( 1 )
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_1
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+B
+2
+INTEGER
+<systemid>
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( a + c )
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
V"3
I
1
@@ -893,6 +983,33 @@
<systemid>
----
APP
+T_GENCOL_1
+<systemnumber>
+T_GENCOL_1
+false
+null
+false
+<systemid>
+----
+APP
+T_GENCOL_2
+<systemnumber>
+T_GENCOL_2
+false
+null
+false
+<systemid>
+----
+APP
+T_GENCOL_3
+<systemnumber>
+T_GENCOL_3
+false
+null
+false
+<systemid>
+----
+APP
X
<systemnumber>
X
@@ -1788,6 +1905,24 @@
FOO
R
----
+T_GENCOL_1
+T_GENCOL_1
+T
+APP
+R
+----
+T_GENCOL_2
+T_GENCOL_2
+T
+APP
+R
+----
+T_GENCOL_3
+T_GENCOL_3
+T
+APP
+R
+----
V"3
V"3
V
@@ -2619,6 +2754,96 @@
null
null
----
+T_GENCOL_1
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_1
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( 1 )
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_1
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+B
+2
+INTEGER
+<systemid>
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( a + c )
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
V"3
I
1
@@ -2920,6 +3145,33 @@
<systemid>
----
APP
+T_GENCOL_1
+<systemnumber>
+T_GENCOL_1
+false
+null
+false
+<systemid>
+----
+APP
+T_GENCOL_2
+<systemnumber>
+T_GENCOL_2
+false
+null
+false
+<systemid>
+----
+APP
+T_GENCOL_3
+<systemnumber>
+T_GENCOL_3
+false
+null
+false
+<systemid>
+----
+APP
X
<systemnumber>
X
@@ -3815,6 +4067,24 @@
FOO
R
----
+T_GENCOL_1
+T_GENCOL_1
+T
+APP
+R
+----
+T_GENCOL_2
+T_GENCOL_2
+T
+APP
+R
+----
+T_GENCOL_3
+T_GENCOL_3
+T
+APP
+R
+----
V"3
V"3
V
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test_territory.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test_territory.out?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test_territory.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test_territory.out Mon Oct 27 06:27:26 2008
@@ -592,6 +592,96 @@
null
null
----
+T_GENCOL_1
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_1
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( 1 )
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_1
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+B
+2
+INTEGER
+<systemid>
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( a + c )
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
V"3
I
1
@@ -893,6 +983,33 @@
<systemid>
----
APP
+T_GENCOL_1
+<systemnumber>
+T_GENCOL_1
+false
+null
+false
+<systemid>
+----
+APP
+T_GENCOL_2
+<systemnumber>
+T_GENCOL_2
+false
+null
+false
+<systemid>
+----
+APP
+T_GENCOL_3
+<systemnumber>
+T_GENCOL_3
+false
+null
+false
+<systemid>
+----
+APP
X
<systemnumber>
X
@@ -1788,6 +1905,24 @@
FOO
R
----
+T_GENCOL_1
+T_GENCOL_1
+T
+APP
+R
+----
+T_GENCOL_2
+T_GENCOL_2
+T
+APP
+R
+----
+T_GENCOL_3
+T_GENCOL_3
+T
+APP
+R
+----
V"3
V"3
V
@@ -2619,6 +2754,96 @@
null
null
----
+T_GENCOL_1
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_1
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( 1 )
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_1
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+B
+2
+INTEGER
+<systemid>
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_2
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+A
+1
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+B
+2
+INTEGER
+GENERATED ALWAYS AS ( a + c )
+<systemid>
+<autoincval>
+null
+null
+----
+T_GENCOL_3
+C
+3
+INTEGER
+null
+null
+<autoincval>
+null
+null
+----
V"3
I
1
@@ -2920,6 +3145,33 @@
<systemid>
----
APP
+T_GENCOL_1
+<systemnumber>
+T_GENCOL_1
+false
+null
+false
+<systemid>
+----
+APP
+T_GENCOL_2
+<systemnumber>
+T_GENCOL_2
+false
+null
+false
+<systemid>
+----
+APP
+T_GENCOL_3
+<systemnumber>
+T_GENCOL_3
+false
+null
+false
+<systemid>
+----
+APP
X
<systemnumber>
X
@@ -3815,6 +4067,24 @@
FOO
R
----
+T_GENCOL_1
+T_GENCOL_1
+T
+APP
+R
+----
+T_GENCOL_2
+T_GENCOL_2
+T
+APP
+R
+----
+T_GENCOL_3
+T_GENCOL_3
+T
+APP
+R
+----
V"3
V"3
V
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java Mon Oct 27 06:27:26 2008
@@ -31,6 +31,8 @@
import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.apache.derby.iapi.util.StringUtil;
+import org.apache.derby.catalog.DefaultInfo;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
@@ -321,59 +323,59 @@
);
}
- // /**
- // * <p>
- // * Verify basic parse/bind logic for declaring generated columns.
- // * </p>
- // */
- // public void test_004_basicParser()
- // throws Exception
- // {
- // Connection conn = getConnection();
- //
- // goodStatement
- // (
- // conn,
- // "create function f_parse_deterministic( a int )\n" +
- // "returns int\n" +
- // "language java\n" +
- // "deterministic\n" +
- // "parameter style java\n" +
- // "no sql\n" +
- // "external name 'java.lang.Math.abs'\n"
- // );
- // goodStatement
- // (
- // conn,
- // "create function f_parse_non_deterministic( a int )\n" +
- // "returns int\n" +
- // "language java\n" +
- // "parameter style java\n" +
- // "no sql\n" +
- // "external name 'java.lang.Math.abs'\n"
- // );
- // goodStatement
- // (
- // conn,
- // "create table t_parse_1\n" +
- // "(\n" +
- // " a int,\n" +
- // " b int generated always as ( f_parse_deterministic( a ) ),\n" +
- // " c int\n" +
- // ")"
- // );
- //
- // expectCompilationError
- // (
- // UNSTABLE_RESULTS,
- // "create table t_parse_shouldFail\n" +
- // "(\n" +
- // " a int,\n" +
- // " b int generated always as ( f_parse_non_deterministic( a ) ),\n" +
- // " c int\n" +
- // ")\n"
- // );
- // }
+ /**
+ * <p>
+ * Verify basic parse/bind logic for declaring generated columns.
+ * </p>
+ */
+ public void test_004_basicParser()
+ throws Exception
+ {
+ Connection conn = getConnection();
+
+ goodStatement
+ (
+ conn,
+ "create function f_parse_deterministic( a int )\n" +
+ "returns int\n" +
+ "language java\n" +
+ "deterministic\n" +
+ "parameter style java\n" +
+ "no sql\n" +
+ "external name 'java.lang.Math.abs'\n"
+ );
+ goodStatement
+ (
+ conn,
+ "create function f_parse_non_deterministic( a int )\n" +
+ "returns int\n" +
+ "language java\n" +
+ "parameter style java\n" +
+ "no sql\n" +
+ "external name 'java.lang.Math.abs'\n"
+ );
+ goodStatement
+ (
+ conn,
+ "create table t_parse_1\n" +
+ "(\n" +
+ " a int,\n" +
+ " b int generated always as ( f_parse_deterministic( a ) ),\n" +
+ " c int\n" +
+ ")"
+ );
+
+ expectCompilationError
+ (
+ UNSTABLE_RESULTS,
+ "create table t_parse_shouldFail\n" +
+ "(\n" +
+ " a int,\n" +
+ " b int generated always as ( f_parse_non_deterministic( a ) ),\n" +
+ " c int\n" +
+ ")\n"
+ );
+ }
// /**
// * <p>
@@ -897,6 +899,68 @@
// );
// }
+ /**
+ * <p>
+ * Verify that column defaults look good for generated columns.
+ * </p>
+ */
+ public void test_009_basicDefaultInfo()
+ throws Exception
+ {
+ Connection conn = getConnection();
+
+ goodStatement
+ (
+ conn,
+ "create table t_di_1\n" +
+ "(\n" +
+ " a int,\n" +
+ " b int generated always as ( 1 ),\n" +
+ " c int\n" +
+ ")"
+ );
+ goodStatement
+ (
+ conn,
+ "create table t_di_2\n" +
+ "(\n" +
+ " a int,\n" +
+ " b int generated always as ( -a ),\n" +
+ " c int\n" +
+ ")"
+ );
+ goodStatement
+ (
+ conn,
+ "create table t_di_3\n" +
+ "(\n" +
+ " a int,\n" +
+ " b int generated always as ( a + c ),\n" +
+ " c int\n" +
+ ")"
+ );
+
+ assertDefaultInfo
+ (
+ conn, "T_DI_1", "B",
+ new int[] {},
+ "1"
+ );
+ assertDefaultInfo
+ (
+ conn, "T_DI_2", "B",
+ new int[] { 1 },
+ "-a"
+ );
+ assertDefaultInfo
+ (
+ conn, "T_DI_3", "B",
+ new int[] { 1, 3 },
+ "a + c"
+ );
+
+ }
+
///////////////////////////////////////////////////////////////////////////////////
//
// MINIONS
@@ -1068,6 +1132,57 @@
return result;
}
+
+ /**
+ * <p>
+ * Assert that a column has the expected generation clause.
+ * </p>
+ */
+ private void assertDefaultInfo
+ ( Connection conn, String tableName, String columnName, int[] expectedReferenceColumns, String expectedDefaultText )
+ throws Exception
+ {
+ DefaultInfo di = getColumnDefault( conn, tableName, columnName );
+
+ assertEquals
+ ( StringUtil.stringify( expectedReferenceColumns ), StringUtil.stringify( di.getReferencedColumnIDs() ) );
+ assertEquals( expectedDefaultText, di.getDefaultText() );
+
+ assertTrue( di.isGeneratedColumn() );
+ }
+
+ /**
+ * <p>
+ * Returns the column default for a column.
+ * </p>
+ */
+ public DefaultInfo getColumnDefault( Connection conn, String tableName, String columnName )
+ throws SQLException
+ {
+ PreparedStatement ps = chattyPrepare
+ (
+ conn,
+ "select c.columndefault\n" +
+ "from sys.syscolumns c, sys.systables t\n" +
+ "where t.tableid = c.referenceid\n" +
+ "and t.tablename = ?\n" +
+ "and c.columnname = ?"
+ );
+ ps.setString( 1, tableName );
+ ps.setString( 2, columnName );
+
+ ResultSet rs = ps.executeQuery();
+ rs.next();
+
+ DefaultInfo result = (DefaultInfo) rs.getObject( 1 );
+
+ rs.close();
+ ps.close();
+
+ return result;
+ }
+
+
///////////////////////////////////////////////////////////////////////////////////
//
// SQL FUNCTIONS
@@ -1140,4 +1255,5 @@
_triggerReports.add( result );
}
+
}
\ No newline at end of file
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/dblook_makeDB.sql Mon Oct 27 06:27:26 2008
@@ -107,6 +107,12 @@
create table "Foo Bar".t6 (num integer, letter char(1));
create table "Foo Bar".t7 (un int, deux int);
+-- generated columns
+create table t_genCol_1( a int, b int generated always as ( 1 ), c int );
+create table t_genCol_2( a int, b int generated always as ( -a ), c int );
+create table t_genCol_3( a int, b int generated always as ( a + c ), c int );
+
+
-- Keys/checks.
create table bar."tWithKeys" (c char(5) not null PRIMARY KEY, i int check (i > 0), vc varchar(10) constraint notevil check (vc != 'evil'));
create table bar.t8 (someInt int constraint "pkOne" not null primary key, fkChar char(5) references bar."tWithKeys" (c) on delete set null);
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java Mon Oct 27 06:27:26 2008
@@ -167,6 +167,40 @@
}
/**
+ * Test that generation clauses are not allowed until you
+ * hard-upgrade to 10.5.
+ *
+ */
+ public void testGenerationClauses() throws SQLException
+ {
+ String sqlstate = null;
+
+ switch (getPhase())
+ {
+ case PH_SOFT_UPGRADE:
+ sqlstate = SQLSTATE_NEED_UPGRADE;
+ break;
+
+ case PH_POST_SOFT_UPGRADE:
+ sqlstate = BAD_SYNTAX;
+ break;
+
+ case PH_HARD_UPGRADE:
+ sqlstate = null;
+ break;
+
+ default:
+ return;
+ }
+
+ possibleError
+ (
+ sqlstate,
+ "create table t_genCol_2( a int, b int generated always as ( -a ), c int )"
+ );
+ }
+
+ /**
* <p>
* Run a statement. If the sqlstate is not null, then we expect that error.
* </p>
Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_Table.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_Table.java?rev=708169&r1=708168&r2=708169&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_Table.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/dblook/DB_Table.java Mon Oct 27 06:27:26 2008
@@ -149,8 +149,14 @@
colDef.append(rs.getString(1));
if (!reinstateAutoIncrement(colName, tableId, colDef) &&
rs.getString(2) != null) {
- colDef.append(" DEFAULT ");
- colDef.append(rs.getString(2));
+
+ String defaultText = rs.getString(2);
+
+ if ( defaultText.startsWith( "GENERATED ALWAYS AS" ) )
+ { colDef.append( " " ); }
+ else { colDef.append(" DEFAULT "); }
+
+ colDef.append( defaultText );
}
}