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 ma...@apache.org on 2007/06/29 18:24:32 UTC
svn commit: r551942 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Author: mamta
Date: Fri Jun 29 09:24:30 2007
New Revision: 551942
URL: http://svn.apache.org/viewvc?view=rev&rev=551942
Log:
DERBY-2831
Forgot to enter a test case during 551793 checkin. This commit just creates a function in non-existent database to ensure
we don't throw null pointer exception.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java?view=diff&rev=551942&r1=551941&r2=551942
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java Fri Jun 29 09:24:30 2007
@@ -222,12 +222,13 @@
/**
* CreateAliasNode creates the RoutineAliasInfo for a user defined function
- * in it's init method, which is called by the parser. But at that time, we
- * do not have the SchemaDescriptor ready to determine the collation
- * type. Hence, at the bind time, when we do have the SchemaDescriptor
- * available, we should go back and fix the RoutineAliasIno to have correct
- * collation for it's character string parameters and also fix it's return
- * type's collation if the return type is a character string.
+ * or procedure in it's init method, which is called by the parser. But at
+ * that time, we do not have the SchemaDescriptor ready to determine the
+ * collation type. Hence, at the bind time, when we do have the
+ * SchemaDescriptor available, we should go back and fix the
+ * RoutineAliasInfo to have correct collation for its character string
+ * parameters and also fix its return type (for functions) so as to have
+ * correct collation if it is returning character string type.
*
* This method here checks if the RoutineAliasInfo has any character string
* types associated with it. If not, then the RoutineAliasInfo that got
@@ -239,13 +240,17 @@
private boolean anyStringTypeDescriptor() {
RoutineAliasInfo rai = (RoutineAliasInfo)aliasInfo;
TypeDescriptor aType = rai.getReturnType();
+ TypeId compTypeId;
/*
** Try for a built in type matching the
** type name.
*/
- TypeId compTypeId = TypeId.getBuiltInTypeId(aType.getTypeName());
- if (compTypeId != null && compTypeId.isStringTypeId())
- return true;
+ if (aType != null) //that means we are not dealing with a procedure
+ {
+ compTypeId = TypeId.getBuiltInTypeId(aType.getTypeName());
+ if (compTypeId != null && compTypeId.isStringTypeId())
+ return true;
+ }
if (rai.getParameterCount() != 0) {
int paramCount = rai.getParameterCount();
TypeDescriptor[] paramTypes = rai.getParameterTypes();
@@ -264,17 +269,23 @@
* typeid, length and nullability to create a new DataTypeDescriptor and
* then have it take the collation type of the schema in which the method
* is getting defined in. This is because all the character strings
- * associated with the definition of the user defined function should take
- * the collation of the schema in which this user defined function is
- * getting created.
+ * associated with the definition of the user defined function/procedure
+ * should take the collation of the schema in which this user defined
+ * function is getting created.
*
* @param changeTD TypeDescriptor with incorrect collation setting
* @return New TypeDescriptor with collation of the schema in which
- * the function is getting created.
+ * the function/procedure is getting created.
* @throws StandardException
*/
private TypeDescriptor typeDescriptorWithCorrectCollation(TypeDescriptor changeTD)
throws StandardException {
+ //We could have been called for the return type but for procedures
+ //there is no return type and hence we should be careful that we
+ //don't run into null ptr exception. So before doing anything, check if
+ //the passed parameter is null and if so, then simply return.
+ if (changeTD == null)
+ return changeTD;
TypeId compTypeId = TypeId.getBuiltInTypeId(changeTD.getTypeName());
//No work to do if type id does not correspond to a character string
if (compTypeId != null && compTypeId.isStringTypeId()) {
@@ -307,10 +318,11 @@
public void bindStatement() throws StandardException
{
- //Are we dealing with user defined function?
- if (aliasType == AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR) {
- //Does the user defined function have any character string types
- //in it's definition
+ //Are we dealing with user defined function or procedure?
+ if (aliasType == AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR ||
+ aliasType == AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR) {
+ //Does the user defined function/procedure have any character
+ //string types in it's definition
if (anyStringTypeDescriptor()){
RoutineAliasInfo oldAliasInfo = (RoutineAliasInfo)aliasInfo;
TypeDescriptor[] newParamTypes = null;
@@ -321,7 +333,7 @@
TypeDescriptor[] oldParamTypes = oldAliasInfo.getParameterTypes();
//Go through the parameters and pick the character string
//type and set their collation to the collation of the
- //schema in which the function is getting defined.
+ //schema in which the function/procedure is getting defined.
for (int i = 0; i < paramCount; i++)
newParamTypes[i] = typeDescriptorWithCorrectCollation(oldParamTypes[i]);
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?view=diff&rev=551942&r1=551941&r2=551942
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java Fri Jun 29 09:24:30 2007
@@ -718,7 +718,12 @@
"'org.apache.derbyTesting.functionTests.tests.lang.RoutineTest.concat' "+
" LANGUAGE JAVA PARAMETER STYLE JAVA");
//DERBY-2831 Creating a function inside a non-existent schema should not
- //fail when it's return type is of character string type.
+ //fail when it's return type is of character string type. Following is a
+ //simple test case copied from DERBY-2831
+ s.executeUpdate("CREATE FUNCTION AA.B() RETURNS VARCHAR(10) NO SQL " +
+ "PARAMETER STYLE JAVA LANGUAGE JAVA EXTERNAL NAME 'aaa.bbb.ccc' ");
+ //following fails as expected because aaa.bbb.ccc doesn't exist
+ assertStatementError("XJ001", s, "SELECT AA.B() FROM CUSTOMER ");
//Start of parameter testing
//Start with simple ? param in a string comparison