db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r429764 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/compile/ engine/org/apache/derby/iapi/types/ engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/execute/ engine/org/apache/derby/loc/ shared/or...
Date Tue, 08 Aug 2006 18:39:08 GMT
Author: bpendleton
Date: Tue Aug  8 11:39:07 2006
New Revision: 429764

URL: http://svn.apache.org/viewvc?rev=429764&view=rev
Log:
DERBY-688: Enhancements to XML functionality toward XPath/XQuery support

This revision contains d688_phase2_v1_code.patch and d688_phase2_v3_tests.patch

This patch was contributed by Army Brown (qozinx@gmail.com).

Attaching a "phase 2" patch that does the following:

- Adds syntax and binding logic for XMLQUERY operator

- Updates syntax for XMLEXISTS to match XMLQUERY and does some refactoring
so that the two can share code. The most user-visible change in this area
is the change from BY VALUE to BY REF syntax, which required test updates
and corresponding master file updates.

Also as part of these changes I've rewritten some of the parse logic to
make it more easily extendible to a broader XMLQUERY syntax (as defined in
SQL/XML[2006]) when/if Derby supports the broader syntax (esp. optional
context items and variable bindings) in the future.

- These phase 2 patches do *not* actually implement the XMLQUERY operator
yet; they just allow parsing and binding of the operator. Execution-time
logic will come in a subsequent patch.

For the sake of review I've separated the Phase 2 patches into two
different parts:

  d688_phase2_v1_code.patch: The code changes.
  d688_phase2_v3_tests.patch: The test/master changes.

When committed, though, *both* patches should be committed together
in order to avoid test diffs.


Modified:
    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/types/XML.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.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/sqlgrammar.jj
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xmlBinding.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql

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=429764&r1=429763&r2=429764&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 Tue Aug  8 11:39:07 2006
@@ -214,6 +214,7 @@
     static final int XML_PARSE_OPERATOR_NODE = 200;
     static final int XML_SERIALIZE_OPERATOR_NODE = 201;
     static final int XML_EXISTS_OPERATOR_NODE = 202;
+    static final int XML_QUERY_OPERATOR_NODE = 203;
 
     /**
      * 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/types/XML.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/XML.java?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/XML.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/XML.java Tue Aug  8 11:39:07 2006
@@ -76,6 +76,15 @@
     private static final int BASE_MEMORY_USAGE =
         ClassSize.estimateBaseFromCatalog(XML.class);
 
+	// Some syntax-related constants used to determine
+	// operator behavior.
+	public static final short XQ_PASS_BY_REF = 1;
+	public static final short XQ_PASS_BY_VALUE = 2;
+	public static final short XQ_RETURN_SEQUENCE = 3;
+	public static final short XQ_RETURN_CONTENT = 4;
+	public static final short XQ_EMPTY_ON_EMPTY = 5;
+	public static final short XQ_NULL_ON_EMPTY = 6;
+
     // The actual XML data in this implementation is just a simple
     // string, so this class really just wraps a SQLChar and
     // defers most calls to the corresponding calls on that

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java Tue Aug  8 11:39:07 2006
@@ -29,6 +29,8 @@
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.services.compiler.MethodBuilder;
 import org.apache.derby.iapi.services.compiler.LocalField;
+import org.apache.derby.iapi.services.io.StoredFormatIds;
+
 import java.lang.reflect.Modifier;
 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
 import org.apache.derby.impl.sql.compile.ActivationClassBuilder;
@@ -98,24 +100,29 @@
 	// possible.
 
 	public final static int XMLEXISTS_OP = 0;
+	public final static int XMLQUERY_OP = 1;
 
 	// NOTE: in the following 4 arrays, order
 	// IS important.
 
 	static final String[] BinaryOperators = {
 		"xmlexists",
+		"xmlquery"
 	};
 
 	static final String[] BinaryMethodNames = {
 		"XMLExists",
+		"XMLQuery"
 	};
 
 	static final String[] BinaryResultTypes = {
-		ClassName.BooleanDataValue		// XMLExists
+		ClassName.BooleanDataValue,		// XMLExists
+		ClassName.XMLDataValue			// XMLQuery
 	};
 
 	static final String[][] BinaryArgTypes = {
-		{ClassName.StringDataValue, ClassName.XMLDataValue}		// XMLExists
+		{ClassName.StringDataValue, ClassName.XMLDataValue},	// XMLExists
+		{ClassName.StringDataValue, ClassName.XMLDataValue}		// XMLQuery
 	};
 
 	// Class used to compile an XML query expression and/or load/process
@@ -305,8 +312,8 @@
 		rightOperand = rightOperand.bindExpression(fromList, subqueryList, 
 			aggregateVector);
 
-		if (operatorType == XMLEXISTS_OP)
-			return bindXMLExists();
+		if ((operatorType == XMLEXISTS_OP) || (operatorType == XMLQUERY_OP))
+			return bindXMLQuery();
 
 		/* Is there a ? parameter on the left? */
 		if (leftOperand.requiresTypeFromContext())
@@ -335,12 +342,14 @@
 	}
 
     /**
-     * Bind an XMLEXISTS operator.  Makes sure the operand type
-     * and target type are both correct, and sets the result type.
+     * Bind an XMLEXISTS or XMLQUERY operator.  Makes sure
+     * the operand type and target type are both correct
+     * and sets the result type.
      *
      * @exception StandardException Thrown on error
      */
-    public ValueNode bindXMLExists() throws StandardException
+    public ValueNode bindXMLQuery()
+        throws StandardException
     {
         // Check operand types.
         TypeId leftOperandType = leftOperand.getTypeId();
@@ -361,15 +370,17 @@
                 ((CharConstantNode)leftOperand).getString());
         }
 
-        // Right operand is an XML data value.
+        // Right operand must be an XML data value.  NOTE: This
+        // is a Derby-specific restriction, not an SQL/XML one.
+        // We have this restriction because the query engine
+        // that we use (currently Xalan) cannot handle non-XML
+        // context items.
         if ((rightOperandType != null) &&
             !rightOperandType.isXMLTypeId())
         {
             throw StandardException.newException(
-                SQLState.LANG_BINARY_OPERATOR_NOT_SUPPORTED, 
-                    methodName,
-                    leftOperandType.getSQLTypeName(),
-                    rightOperandType.getSQLTypeName());
+                SQLState.LANG_INVALID_CONTEXT_ITEM_TYPE,
+                rightOperandType.getSQLTypeName());
         }
 
         // Is there a ? parameter on the right?
@@ -381,11 +392,23 @@
                 SQLState.LANG_ATTEMPT_TO_BIND_XML);
         }
 
-        // Set the result type of this XMLExists operator--it's always
-        // SQLBoolean.  The "true" in the next line says that the result
-        // can be nullable--which it can be if evaluation of the expression
-        // returns a null (this is per SQL/XML spec section 8.4).
-        setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID, true));
+        // Set the result type of this operator.
+        if (operatorType == XMLEXISTS_OP) {
+        // For XMLEXISTS, the result type is always SQLBoolean.
+        // The "true" in the next line says that the result
+        // can be nullable--which it can be if evaluation of
+        // the expression returns a null (this is per SQL/XML
+        // spec, 8.4)
+            setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID, true));
+        }
+        else {
+        // The result of an XMLQUERY operator is always another
+        // XML data value, per SQL/XML spec 6.17: "...yielding a value
+        // X1 of an XML type."
+            setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+                StoredFormatIds.XML_TYPE_ID));
+        }
+
         return genSQLJavaSQLTree();
     }
 
@@ -461,9 +484,10 @@
 ** but how?
 */
 
-		// If we're dealing with XMLEXISTS, there is some
+		// If we're dealing with XMLEXISTS or XMLQUERY, there is some
 		// additional work to be done.
-		boolean xmlGen = (operatorType == XMLEXISTS_OP);
+		boolean xmlGen =
+			(operatorType == XMLQUERY_OP) || (operatorType == XMLEXISTS_OP);
 
 		if (xmlGen) {
 		// We create an execution-time object so that we can retrieve
@@ -600,6 +624,12 @@
 			{
 				mb.push(dataTypeServices.getScale());		// 4th arg
 				mb.callMethod(VMOpcode.INVOKEINTERFACE, receiverType, methodName, resultTypeName, 4);
+			}
+			else if (xmlGen) {
+			// This is for an XMLQUERY operation, so invoke the method
+			// on our execution-time object.
+				mb.callMethod(VMOpcode.INVOKEVIRTUAL, null,
+					methodName, resultTypeName, 3);
 			}
 			else
 				mb.callMethod(VMOpcode.INVOKEINTERFACE, receiverType, methodName, resultTypeName, 3);

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=429764&r1=429763&r2=429764&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 Tue Aug  8 11:39:07 2006
@@ -578,6 +578,7 @@
             return C_NodeNames.UNARY_OPERATOR_NODE_NAME;
 
           case C_NodeTypes.XML_EXISTS_OPERATOR_NODE:
+          case C_NodeTypes.XML_QUERY_OPERATOR_NODE:
             return C_NodeNames.BINARY_OPERATOR_NODE_NAME;
 
           case C_NodeTypes.GRANT_NODE:

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=429764&r1=429763&r2=429764&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 Tue Aug  8 11:39:07 2006
@@ -2240,7 +2240,8 @@
 	If they are non-reserved, they need to be added to the identifier() rule.
 
 	NOTE: XML, XMLPARSE, XMLSERIALIZE, and XMLEXISTS are considered reserved
-	words to comply with the SQL/XML (2003) standard, section 5.1.
+	words to comply with the SQL/XML (2003) standard, section 5.1.  Similarly,
+	XMLQUERY is a reserved word per SQL/XML (2006).
  */
 
 /* NOTE - If you add a keyword, then you must add it to reservedKeyword()
@@ -2261,9 +2262,10 @@
 |	<RTRIM: "rtrim">
 |	<SUBSTR:	"substr">
 |	<XML:	"xml">
+|	<XMLEXISTS:	"xmlexists">
 |	<XMLPARSE:	"xmlparse">
+|	<XMLQUERY:	"xmlquery">
 |	<XMLSERIALIZE:	"xmlserialize">
-|	<XMLEXISTS:	"xmlexists">
 }
 
 /* NOTE - If you add a keyword, then you must add it to reservedKeyword()
@@ -2271,8 +2273,9 @@
  *
  * NOTE: CONTENT, DOCUMENT, STRIP, WHITESPACE and PASSING are considered NON-
  * reserved words to comply with the SQL/XML (2003) standard, section 5.1.
- * PRESERVE is also listed as non-reserved in the SQL/XML spec, but
- * since that word is already reserved, we leave it alone.
+ * Similarly, EMPTY, RETURNING, and SEQUENCE are all considered NON-reserved
+ * words per SQL/XML (2006).  PRESERVE is also listed as non-reserved in the
+ * SQL/XML spec, but since that word is already reserved, we leave it alone.
  */
 TOKEN [IGNORE_CASE] :
 {	/* Additional JSQL keywords -- non-SQL92 non-reserved Keywords */
@@ -2287,6 +2290,7 @@
 |       <DIRTY: "dirty">
 |	<DOCUMENT: "document">
 |	<EACH: "each">
+|	<EMPTY: "empty">
 |	<EXCLUSIVE: "exclusive">
 |	<FN: "fn">
 |	<INDEX: "index">
@@ -2315,8 +2319,10 @@
 |       <RESET: "reset">
 |	<RESULT: "result">
 |	<RETAIN: "retain">
+|	<RETURNING: "returning">
 |   <RR: "rr">
 |   <RS: "rs">
+|	<SEQUENCE: "sequence">
 |	<SEQUENTIAL: "sequential">
 |	<SETS: "sets">
 |	<SHARE: "share">
@@ -6489,7 +6495,8 @@
                 getToken(1).kind == LOCATE ||
                 getToken(1).kind == XMLPARSE ||
                 getToken(1).kind == XMLSERIALIZE ||
-                getToken(1).kind == XMLEXISTS ) &&
+                getToken(1).kind == XMLEXISTS ||
+                getToken(1).kind == XMLQUERY ) &&
               getToken(2).kind == LEFT_PAREN
               )
     } )
@@ -6668,7 +6675,12 @@
 		return value;
 	}
 |
-	<XMLEXISTS> <LEFT_PAREN> value = xmlExistsValue() <RIGHT_PAREN>
+	<XMLEXISTS> <LEFT_PAREN> value = xmlQueryValue(true) <RIGHT_PAREN>
+	{
+		return value;
+	}
+|
+	<XMLQUERY> <LEFT_PAREN> value = xmlQueryValue(false) <RIGHT_PAREN>
 	{
 		return value;
 	}
@@ -6797,7 +6809,7 @@
 	LOOKAHEAD({ (getToken(1).kind != AS) || (getToken(2).kind == RIGHT_PAREN) })
 	{
 		throw StandardException.newException(
-			SQLState.LANG_XML_KEYWORD_MISSING, "AS <string-type>");
+			SQLState.LANG_XML_KEYWORD_MISSING, "AS");
 	}
 |
 	<AS> targetType = dataTypeDDL()
@@ -6807,71 +6819,328 @@
 }
 
 /*
- * <A NAME="xmlExistsValue">xmlExistsValue</A>
+ * <A NAME="xmlQueryValue">xmlQueryValue</A>
  *
- * Syntax is as follows:
+ * This method is used for parsing the XMLEXISTS and XMLQUERY operators
+ * (which operator depends on the received boolean parameter).
+ *
+ * For XMLEXISTS, the syntax is as follows:
  *
- *   XMLEXISTS( <xpath-expression> PASSING BY VALUE <xml-value-expression> )
+ *   XMLEXISTS( <xpath-expression> PASSING BY REF <xml-value-expression> )
  *
  * The result of this operation will be a boolean true/false/unknown value:
- *   -- Unknown if either <xpath-expression> or <xml-value-expression> is null;
- *   -- True if at least one node in the given xml-value matches the given
- *      XPath expression;
+ *   -- Unknown if either <xquery-expression> or <xml-value-expression> is null;
+ *   -- True if evaluation of the given query expression against the
+ *      given xml-value returns at least one node.
  *   -- False otherwise.
  *
  * For example:
  *
- * ij> SELECT id FROM x_table WHERE XMLEXISTS('/simple' PASSING BY VALUE xdoc);
+ * ij> SELECT id FROM x_table WHERE XMLEXISTS('/simple' PASSING BY REF xdoc);
  * ID
  * -----------
  * 1
  *
+ * ====
+ *
+ * For XMLQUERY, the syntax is as follows:
+ *
+ *   XMLQUERY( <xquery-expression>
+ *      PASSING BY REF <xml-value-expression>
+ *      [ RETURNING SEQUENCE [ BY REF ] ]
+ *      EMPTY ON EMPTY
+ *   )
+ *
+ * The result of this operation will be an XMLDataValue.
+ *
+ * For example:
+ *
+ * ij> SELECT XMLSERIALIZE(
+ *       XMLQUERY('/simple' PASSING BY REF xdoc EMPTY ON EMPTY) AS CHAR(100));
+ * ID
+ * -----------
+ * <simp> doc </simp>
+ *
  */
 ValueNode
-	xmlExistsValue() throws StandardException :
+	xmlQueryValue(boolean existsOnly) throws StandardException :
+{
+	// The query expression (currently must be an expression
+	// supported by Xalan--i.e. XPath only).
+	ValueNode xqueryExpr = null;
+
+	// Context item for the query; not required by SQL/XML spec,
+	// but required by Derby for now.
+	ValueNode xmlValue = null;
+
+	// User-specified default passing mechanism.  Since Derby only
+	// supports one type of passing mechanism--BY REF--this value
+	// isn't currently used.
+	short defaultPassingMech = -1;
+}
+{
+	xqueryExpr = additiveExpression(null, 0, false)
+	<PASSING> defaultPassingMech = xmlPassingMechanism()
+		xmlValue = xqVarList()
+	(
+		LOOKAHEAD( { !existsOnly } )
+		[ xqReturningClause() [ xmlPassingMechanism() ] ]
+			xqEmptyHandlingClause()
+		{ /* Right now, we only support one kind of returning clause
+		   * (RETURNING SEQUENCE) and one kind of handling clause
+		   * (EMPTY ON EMPTY), so there's nothing more to do here--
+		   * we just needed to check the syntax.  In the future
+		   * we may need to add more logic here to support the
+		   * other options.  Note: if no returning clause is
+		   * specified, RETURNING SEQUENCE is implied (because
+		   * that's all we support).
+		   */
+		}
+	|
+		LOOKAHEAD( { existsOnly } )
+		{ /* For XMLEXISTS there's nothing more to parse.  We need
+		   * this LOOKAHEAD in order to tell the parser that we're
+		   * done parsing and thus it shouldn't look for (nor allow)
+		   * any more tokens (neither xqReturningClause() nor
+		   * xqEmptyHandlingClause() is allowed for the XMLEXISTS
+		   * operator).
+		   */
+		}
+	)
+	{
+		ValueNode vNode = (ValueNode) nodeFactory.getNode(
+			(existsOnly
+				? C_NodeTypes.XML_EXISTS_OPERATOR_NODE
+				: C_NodeTypes.XML_QUERY_OPERATOR_NODE),
+			xqueryExpr,
+			xmlValue,
+			(existsOnly
+				? ReuseFactory.getInteger(BinaryOperatorNode.XMLEXISTS_OP)
+				: ReuseFactory.getInteger(BinaryOperatorNode.XMLQUERY_OP)),
+			getContextManager());
+
+		return vNode;
+	}
+}
+
+/**
+ * <A NAME="xqVarList">xqVarList</A>
+ *
+ * Parse a list of XML query variables, which can include at most one
+ * XML value to be used as the "context item" for the query.  If
+ * such a context item was found, return that item; for all other
+ * variable declarations we currently throw a "not supported" error
+ * because Xalan doesn't allowing binding of variables.
+ */
+
+ValueNode xqVarList()
+	throws StandardException :
 {
-	ValueNode xpathExpr;
-	ValueNode xmlValue;
+	// Placeholder for the XML context item as we parse the
+	// argument list.
+	ValueNode [] xmlValue = new ValueNode [] { (ValueNode)null };
 }
 {
-	xpathExpr = additiveExpression(null,0,false)
-		xmlPassingMechanism() xmlValue = additiveExpression(null, 0, false)
+	xqVariable(xmlValue)
+		( <COMMA> xqVariable(xmlValue) )*
 	{
-		return (ValueNode) nodeFactory.getNode(
-					C_NodeTypes.XML_EXISTS_OPERATOR_NODE,
-					xpathExpr,
-					xmlValue,
-					ReuseFactory.getInteger(BinaryOperatorNode.XMLEXISTS_OP),
-					getContextManager());
+		return xmlValue[0];
+	}
+}
+
+/**
+ * <A NAME="xqVariable">xqVariable</A>
+ *
+ * Parse an XML query variable.  If the argument is an XML value
+ * to be used as the "context item" for a query, then store the
+ * value in the first slot of the received ValueNode array;
+ * otherwise, throw a "not supported" errror (for now).
+ */
+
+void xqVariable(ValueNode [] xmlVal) throws StandardException :
+{
+	ValueNode curVal;
+	String varName = null;
+	short passingMech = -1;
+}
+{
+	curVal = additiveExpression(null,0, false)
+	[
+		LOOKAHEAD( { getToken(1).kind == AS } )
+		<AS> varName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
+		{
+			/* From XQuery 1.0: "The <identifier> I contained in XQV
+			 * shall be an XML 1.1 NCName."  From XML 1.1:
+			 *
+			 *   [4] NCName ::= (Letter | '_') (NCNameChar)*
+			 *   [5] NCNameChar ::= Letter | Digit | '.' | '-' | '_' |
+			 *                    CombiningChar | Extender
+			 *
+			 * Since Derby's definition of an "identifier" is a subset
+			 * of NCName, we just use Derby's definition.  This means
+			 * that some valid NCNames won't be recognized by Derby--
+			 * but since the ones we _do_ recognize are all still valid
+			 * NCNames, we're not breaking any rules.
+			 */
+
+			/* All of that said, since we use Xalan as the underlying
+			 * query engine and Xalan doesn't support variable binding,
+			 * there's no point in letting the user specify variables
+			 * right now.  So we disallow it.  In the future we'll have
+			 * to add logic here to store the variables and pass them
+			 * to the correct operator for binding/execution.
+			 */
+			throw StandardException.newException(
+				SQLState.LANG_UNSUPPORTED_XML_FEATURE, "PASSING ... AS");
+		}
+	] 
+	(
+		[ passingMech = xmlPassingMechanism() ]
+		{
+			if (varName == null)
+			{
+				/* We get here if we just parsed an XML context item.
+				 * That said, if we already have one (xmlVal[0] is not
+				 * null) then we can't allow second one, per SQL/XML[2006]
+				 * (6.17: Syntax Rules:5.b.i): "XMQ shall contain exactly
+				 * one <XML query context item> XQCI."
+				 */
+				if (xmlVal[0] != null)
+				{
+					throw StandardException.newException(
+						SQLState.LANG_MULTIPLE_XML_CONTEXT_ITEMS);
+				}
+
+				xmlVal[0] = curVal;
+
+				/* Note: It's possible that a passing mechanism was
+				 * specified for the context item; if so its value is
+				 * stored in passingMech.  However, we don't actually
+			 	 * store that passing mechanism anywhere because we
+				 * (currently) only support BY REF, so we know what
+			 	 * it has to be.  If we add support for other passing
+			 	 * mechanisms (namely, BY VALUE) in the future, we'll
+			 	 * have to store the passing mechanism provided by
+			 	 * the user and process it at compilation/execution
+				 * time.
+				 */
+			}
+		}
+	)
+	{ // By this time we've parsed everything we need so there's nothing
+	  // more to do.  The reason we're left with this empty block is
+	  // is that most of the syntax is optional.  We end up here if
+	  // none of the optional syntax was given, in which case all we
+	  // need to do is store curVal--and we already did that.
 	}
 }
 
 /*
  * <A NAME="xmlPassingMechanism">xmlPassingMechanism</A>
  *
- * For now, we only support the BY VALUE option because,
- * at query time, we take the XML string value from disk and
- * pass it into Xalan, which creates a "copy" of the XML
- * value internally (as DOM/DTM) and then executes against
- * that.  Because Xalan creates this copy, this impl
- * is BY VALUE.
- *
+ * For now, we only support the BY REF option because
+ * that gives us better performance (allows us to avoid
+ * performing potentially deep copies of XML nodes).  This
+ * means that if the same XML value is passed BY REF into
+ * two different XML arguments for a single operator, then
+ * every node in the first XML argument must have an
+ * identical node in the second XML argument, and the
+ * ids for both nodes must be the same.  That said,
+ * since we don't support variable binding yet, this
+ * becomes a non-issue because we can't pass XML values.
+ * In the future, though, we may choose to support the
+ * passing/binding of variables (the only reason we
+ * don't now is because Xalan doesn't support it) and
+ * if we do, BY REF should provide better performance
+ * due to lack of deep copying.
  */
-void
+short
 	xmlPassingMechanism() throws StandardException :
 {
 }
 {
-	LOOKAHEAD( { getToken(3).kind == REF })
-	<PASSING> <BY> <REF>
+	LOOKAHEAD( { getToken(2).kind == REF })
+	<BY> <REF>
 	{ // pass the XML value by reference
-		throw StandardException.newException(
-			SQLState.LANG_UNSUPPORTED_XML_FEATURE, "BY REF");
+		return org.apache.derby.iapi.types.XML.XQ_PASS_BY_REF;
 	}
 |
-	<PASSING> <BY> <VALUE>
+	<BY> <VALUE>
 	{ // pass a 'copy' of the XML value.
-		return;
+		throw StandardException.newException(
+			SQLState.LANG_UNSUPPORTED_XML_FEATURE, "BY VALUE");
+	}
+}
+
+/*
+ * <A NAME="xqReturningClause">xqReturningClause</A>
+ *
+ * For now we only support "RETURNING SEQUENCE".  The reason
+ * is that this applies to the XMLQUERY operator and the
+ * results of evaluating a query expression in Xalan against
+ * an XML value can be an arbritary sequence of items--including
+ * atomic values.  For simplicity we just return the values
+ * as they are, without doing any further work.  SQL/XML[2006]
+ * says that if we supported RETURNING CONTENT then we'd have
+ * to construct an XQuery document from the results--but we don't
+ * do that extra work for now, so we just say that we return
+ * SEQUENCE.
+ *
+ * NOTE: This means that we may not be able to store the results
+ * of an XMLQUERY operation into a Derby XML column.  Right now
+ * an XML column can only hold valid DOCUMENT nodes, which translates
+ * into a sequence of exactly one org.w3c.dom.Node.  So if the
+ * result of an XMLQUERY operation is not a sequence of exactly
+ * one Node, then that result will *not* be storable into
+ * Derby XML columns.
+ */
+short
+	xqReturningClause() throws StandardException :
+{
+}
+{
+	LOOKAHEAD( { getToken(2).kind == SEQUENCE } )
+	<RETURNING> <SEQUENCE>
+	{ // XMLQUERY should return result as a sequence.
+	  // NOTE: since Derby XML columns only allow DOCUMENT(UNTYPED),
+	  // the result of an XMLQUERY operator that returns SEQUENCE
+	  // might not be storable into an XML column.
+		return org.apache.derby.iapi.types.XML.XQ_RETURN_SEQUENCE;
+	}
+|
+	<RETURNING> <CONTENT>
+	{ // XMLQUERY should return 'content'.
+		throw StandardException.newException(
+			SQLState.LANG_UNSUPPORTED_XML_FEATURE, "RETURNING CONTENT");
+	}
+}
+
+/*
+ * <A NAME="xqEmptyHandlingClause">xqEmptyHandlingClause</A>
+ *
+ * Defines what the behavior should be when an XMLQUERY operator
+ * results in an empty sequence.  For now we just return the
+ * empty sequence.
+ */
+short
+	xqEmptyHandlingClause() throws StandardException :
+{
+}
+{
+	LOOKAHEAD( { getToken(1).kind == EMPTY })
+	<EMPTY> <ON> <EMPTY>
+	{ // XMLQUERY should return an empty sequence when result of
+	  // the query is an empty sequence (i.e. when there are no
+	  // results).
+		return org.apache.derby.iapi.types.XML.XQ_EMPTY_ON_EMPTY;
+	}
+|
+	<NULL> <ON> <EMPTY>
+	{ // XMLQUERY should return a null XML value when result of
+	  // the query is an empty sequence (i.e. when there are no
+	  // results).
+		throw StandardException.newException(
+			SQLState.LANG_UNSUPPORTED_XML_FEATURE, "NULL ON EMPTY");
 	}
 }
 
@@ -12475,6 +12744,7 @@
 |	tok = <XMLPARSE>
 |	tok = <XMLSERIALIZE>
 |	tok = <XMLEXISTS>
+|	tok = <XMLQUERY>
 )
 	{
 		// Remember whether last token was a delimited identifier
@@ -12534,6 +12804,7 @@
 	|	tok = <DB2SQL>
 	|	tok = <DOCUMENT>
 	|	tok = <EACH>
+	|	tok = <EMPTY>
 	|	tok = <EXCLUSIVE>
 	|	tok = <FN>
 	|	tok = <FORTRAN>
@@ -12594,6 +12865,7 @@
 	|	tok = <RESTART>
 	|	tok = <RESULT>
 	|	tok = <RETAIN>
+	|	tok = <RETURNING>
 	|	tok = <RETURNS>
 	|	tok = <ROW>
 //	|	tok = <ROW_COUNT>
@@ -12601,6 +12873,7 @@
 	|   tok = <RS>
 	|	tok = <SCALE>
 	|	tok = <SAVEPOINT>
+	|	tok = <SEQUENCE>
 	|	tok = <SEQUENTIAL>
 	|	tok = <SERIALIZABLE>
 	|	tok = <SETS>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SqlXmlExecutor.java Tue Aug  8 11:39:07 2006
@@ -21,6 +21,7 @@
 package org.apache.derby.impl.sql.execute;
 
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.sql.Activation;
 
 import org.apache.derby.iapi.types.BooleanDataValue;
@@ -120,7 +121,7 @@
 
     // The activation from which we load the compile-time XML
     // objects (including the compiled XML query expression in
-    // case of XMLEXISTS).
+    // case of XMLEXISTS and XMLQUERY).
     private Activation activation;
     private int sqlXUtilId;
 
@@ -159,7 +160,7 @@
     }
 
     /**
-     * Constructor 3: Used for XMLEXISTS ops.
+     * Constructor 3: Used for XMLEXISTS/XMLQUERY ops.
      * @param activation Activation from which to retrieve saved objects
      * @param utilId Id by which we find saved objects in activation
      */
@@ -229,6 +230,31 @@
         XMLDataValue xmlContext) throws StandardException
     {
         return xmlContext.XMLExists(getSqlXmlUtil());
+    }
+
+    /**
+     * Make the call to perform an XMLQUERY operation on the
+     * received XML data value and store the result in the
+     * received result holder (or, if it's null, create a
+     * new one).
+     *
+     * @param xExpr Query expression to be evaluated
+     * @param xmlContext Context node against which to evaluate
+     *  the expression.
+     * @param result XMLDataValue in which to store the result
+     * @return The received XMLDataValue with its content set to
+     *  result of evaulating the query expression against xmlContext.
+     *  If the received XMLDataValue is null, then create a new one
+     *  and set its content to correspond to the received xmlText.
+     */
+    public XMLDataValue XMLQuery(StringDataValue xExpr,
+        XMLDataValue xmlContext, XMLDataValue result)
+        throws StandardException
+    {
+        // Incremental development (DERBY-688); this is not yet
+        // implemented.
+        throw StandardException.newException(
+            SQLState.NOT_IMPLEMENTED, "XMLQUERY");
     }
 
     /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties Tue Aug  8 11:39:07 2006
@@ -1018,6 +1018,8 @@
 X0X17.S=Invalid target type for XMLSERIALIZE: ''{0}''.
 X0X18.S=XML feature not supported: ''{0}''.
 X0X19.S=XML query expression must be a string literal.
+X0X20.S=Multiple XML context items are not allowed.
+X0X21.S=Context item must have type ''XML''; ''{0}'' is not allowed.
 X0XML.S=Encountered unexpected error while processing XML; see next exception for details.
 
 X0Y16.S=''{0}'' is not a view.  If it is a table, then use DROP TABLE instead.

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java (original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java Tue Aug  8 11:39:07 2006
@@ -1208,6 +1208,8 @@
 	String LANG_INVALID_XMLSERIALIZE_TYPE                              = "X0X17.S";
 	String LANG_UNSUPPORTED_XML_FEATURE                                = "X0X18.S";
 	String LANG_INVALID_XML_QUERY_EXPRESSION                           = "X0X19.S";
+	String LANG_MULTIPLE_XML_CONTEXT_ITEMS                             = "X0X20.S";
+	String LANG_INVALID_CONTEXT_ITEM_TYPE                              = "X0X21.S";
 	String LANG_UNEXPECTED_XML_EXCEPTION                               = "X0XML.S";
 
 	// X0Y01 used to be DUPLICATE_KEY_CONSTRAINT

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out Tue Aug  8 11:39:07 2006
@@ -164,7 +164,7 @@
 1 row inserted/updated/deleted
 ij> update t1 set x = xmlparse(document '<update> document was inserted as part of an UPDATE </update>' preserve whitespace) where i = 1;
 1 row inserted/updated/deleted
-ij> update t1 set x = xmlparse(document '<update2> document was inserted as part of an UPDATE </update2>' preserve whitespace) where xmlexists('/update' passing by value x);
+ij> update t1 set x = xmlparse(document '<update2> document was inserted as part of an UPDATE </update2>' preserve whitespace) where xmlexists('/update' passing by ref x);
 1 row inserted/updated/deleted
 ij> select i from t1 where xmlparse(document '<hein/>' preserve whitespace) is not null;
 I          
@@ -215,9 +215,9 @@
 1 row inserted/updated/deleted
 ij> -- These should fail.
 select xmlserialize(x) from t1;
-ERROR X0X16: XML syntax error; missing keyword(s): 'AS <string-type>'.
+ERROR X0X16: XML syntax error; missing keyword(s): 'AS'.
 ij> select xmlserialize(x as) from t1;
-ERROR X0X16: XML syntax error; missing keyword(s): 'AS <string-type>'.
+ERROR X0X16: XML syntax error; missing keyword(s): 'AS'.
 ij> select xmlserialize(x as int) from t1;
 ERROR X0X17: Invalid target type for XMLSERIALIZE: 'INTEGER'.
 ij> select xmlserialize(x as varchar(20) for bit data) from t1;
@@ -338,26 +338,30 @@
 ERROR 42X01: Syntax error: Encountered "x" at line 1, column 40.
 ij> select i from t1 where xmlexists('//*' passing x);
 ERROR 42X01: Syntax error: Encountered "x" at line 1, column 48.
-ij> select i from t1 where xmlexists('//*' passing by ref x);
-ERROR X0X18: XML feature not supported: 'BY REF'.
-ij> select i from t1 where xmlexists('//*' passing by value i);
-ERROR 42Y95: The 'XMLExists' operator with a left operand type of 'CHAR' and a right operand type of 'INTEGER' is not supported.
+ij> select i from t1 where xmlexists('//*' passing by value x);
+ERROR X0X18: XML feature not supported: 'BY VALUE'.
+ij> select i from t1 where xmlexists('//*' passing by ref i);
+ERROR X0X21: Context item must have type 'XML'; 'INTEGER' is not allowed.
+ij> select i from t1 where xmlexists(i passing by ref x);
+ERROR X0X19: XML query expression must be a string literal.
+ij> select i from t1 where xmlexists(i passing by ref x, x);
+ERROR X0X20: Multiple XML context items are not allowed.
 ij> -- These should succeed.
-select i from t1 where xmlexists('//*' passing by value x);
+select i from t1 where xmlexists('//*' passing by ref x);
 I          
 -----
 1          
 5          
 6          
 7          
-ij> select i from t1 where xmlexists('//person' passing by value x);
+ij> select i from t1 where xmlexists('//person' passing by ref x);
 I          
 -----
-ij> select i from t1 where xmlexists('//lets' passing by value x);
+ij> select i from t1 where xmlexists('//lets' passing by ref x);
 I          
 -----
 7          
-ij> select xmlexists('//lets' passing by value x) from t1;
+ij> select xmlexists('//lets' passing by ref x) from t1;
 1     
 -----
 0     
@@ -367,7 +371,7 @@
 0     
 0     
 1     
-ij> select xmlexists('//try[text()='' this out '']' passing by value x) from t1;
+ij> select xmlexists('//try[text()='' this out '']' passing by ref x) from t1;
 1     
 -----
 0     
@@ -377,7 +381,7 @@
 0     
 0     
 1     
-ij> select xmlexists('//let' passing by value x) from t1;
+ij> select xmlexists('//let' passing by ref x) from t1;
 1     
 -----
 0     
@@ -387,7 +391,7 @@
 0     
 0     
 0     
-ij> select xmlexists('//try[text()='' this in '']' passing by value x) from t1;
+ij> select xmlexists('//try[text()='' this in '']' passing by ref x) from t1;
 1     
 -----
 0     
@@ -397,7 +401,7 @@
 0     
 0     
 0     
-ij> select i, xmlexists('//let' passing by value x) from t1;
+ij> select i, xmlexists('//let' passing by ref x) from t1;
 I |2     
 -----
 1 |0     
@@ -407,7 +411,7 @@
 5 |0     
 6 |0     
 7 |0     
-ij> select i, xmlexists('//lets' passing by value x) from t1;
+ij> select i, xmlexists('//lets' passing by ref x) from t1;
 I |2     
 -----
 1 |0     
@@ -417,26 +421,26 @@
 5 |0     
 6 |0     
 7 |1     
-ij> values xmlexists('//let' passing by value xmlparse(document '<lets> try this </lets>' preserve whitespace));
+ij> values xmlexists('//let' passing by ref xmlparse(document '<lets> try this </lets>' preserve whitespace));
 1     
 -----
 0     
-ij> values xmlexists('//lets' passing by value xmlparse(document '<lets> try this </lets>' preserve whitespace));
+ij> values xmlexists('//lets' passing by ref xmlparse(document '<lets> try this </lets>' preserve whitespace));
 1     
 -----
 1     
-ij> select xmlserialize(x1 as clob) from t5 where xmlexists('//*' passing by value x1);
+ij> select xmlserialize(x1 as clob) from t5 where xmlexists('//*' passing by ref x1);
 1                                                                                                                               
 -----
-ij> select xmlserialize(x2 as clob) from t5 where xmlexists('//*' passing by value x2);
+ij> select xmlserialize(x2 as clob) from t5 where xmlexists('//*' passing by ref x2);
 1                                                                                                                               
 -----
 <notnull/>                                                                                                                      
-ij> select xmlserialize(x1 as clob), xmlexists('//*' passing by value xmlparse(document '<badboy/>' preserve whitespace)) from t5;
+ij> select xmlserialize(x1 as clob), xmlexists('//*' passing by ref xmlparse(document '<badboy/>' preserve whitespace)) from t5;
 1 |2     
 -----
 NULL |1     
-ij> select xmlserialize(x1 as clob), xmlexists('//goodboy' passing by value xmlparse(document '<badboy/>' preserve whitespace)) from t5;
+ij> select xmlserialize(x1 as clob), xmlexists('//goodboy' passing by ref xmlparse(document '<badboy/>' preserve whitespace)) from t5;
 1 |2     
 -----
 NULL |0     
@@ -444,16 +448,16 @@
 I |2 |3         
 -----
 1 |NULL |<ok/>     
-ij> select i from t7 where xmlexists('/ok' passing by value x1) and xmlexists('/ok' passing by value x2);
+ij> select i from t7 where xmlexists('/ok' passing by ref x1) and xmlexists('/ok' passing by ref x2);
 I          
 -----
-ij> select i from t7 where xmlexists('/ok' passing by value x1) or xmlexists('/ok' passing by value x2);
+ij> select i from t7 where xmlexists('/ok' passing by ref x1) or xmlexists('/ok' passing by ref x2);
 I          
 -----
 1          
 ij> -- XMLEXISTS can be used wherever a boolean function is allowed,
 ----- for ex, a check constraint...
-create table t6 (i int, x xml check (xmlexists('//should' passing by value x)));
+create table t6 (i int, x xml check (xmlexists('//should' passing by ref x)));
 0 rows inserted/updated/deleted
 ij> insert into t6 values (1, xmlparse(document '<should/>' preserve whitespace));
 1 row inserted/updated/deleted
@@ -476,7 +480,7 @@
 1 row inserted/updated/deleted
 ij> insert into t8 values (5, xmlparse(document '<hi/>' preserve whitespace));
 1 row inserted/updated/deleted
-ij> select xmlexists('//child::*[name()="none"]' passing by value x) from t8;
+ij> select xmlexists('//child::*[name()="none"]' passing by ref x) from t8;
 1     
 -----
 0     
@@ -484,7 +488,7 @@
 0     
 0     
 0     
-ij> select xmlexists('//child::*[name()=''hi'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[name()=''hi'']' passing by ref x) from t8;
 1     
 -----
 0     
@@ -492,7 +496,7 @@
 0     
 0     
 1     
-ij> select xmlexists('//child::*[local-name()=''hi'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''hi'']' passing by ref x) from t8;
 1     
 -----
 1     
@@ -500,7 +504,7 @@
 0     
 0     
 1     
-ij> select xmlexists('//child::*[local-name()=''bye'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'']' passing by ref x) from t8;
 1     
 -----
 0     
@@ -508,7 +512,7 @@
 1     
 1     
 0     
-ij> select xmlexists('//*[namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//*[namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1     
 -----
 1     
@@ -516,7 +520,7 @@
 0     
 1     
 0     
-ij> select xmlexists('//*[namespace::*[string()=''http://www.good.bye'']]' passing by value x) from t8;
+ij> select xmlexists('//*[namespace::*[string()=''http://www.good.bye'']]' passing by ref x) from t8;
 1     
 -----
 0     
@@ -524,7 +528,7 @@
 1     
 0     
 0     
-ij> select xmlexists('//child::*[local-name()=''hi'' and namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''hi'' and namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1     
 -----
 1     
@@ -532,7 +536,7 @@
 0     
 0     
 0     
-ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.good.bye'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.good.bye'']]' passing by ref x) from t8;
 1     
 -----
 0     
@@ -540,7 +544,7 @@
 1     
 0     
 0     
-ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1     
 -----
 0     

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out Tue Aug  8 11:39:07 2006
@@ -164,7 +164,7 @@
 1 row inserted/updated/deleted
 ij> update t1 set x = xmlparse(document '<update> document was inserted as part of an UPDATE </update>' preserve whitespace) where i = 1;
 1 row inserted/updated/deleted
-ij> update t1 set x = xmlparse(document '<update2> document was inserted as part of an UPDATE </update2>' preserve whitespace) where xmlexists('/update' passing by value x);
+ij> update t1 set x = xmlparse(document '<update2> document was inserted as part of an UPDATE </update2>' preserve whitespace) where xmlexists('/update' passing by ref x);
 1 row inserted/updated/deleted
 ij> select i from t1 where xmlparse(document '<hein/>' preserve whitespace) is not null;
 I          
@@ -215,9 +215,9 @@
 1 row inserted/updated/deleted
 ij> -- These should fail.
 select xmlserialize(x) from t1;
-ERROR X0X16: XML syntax error; missing keyword(s): 'AS <string-type>'.
+ERROR X0X16: XML syntax error; missing keyword(s): 'AS'.
 ij> select xmlserialize(x as) from t1;
-ERROR X0X16: XML syntax error; missing keyword(s): 'AS <string-type>'.
+ERROR X0X16: XML syntax error; missing keyword(s): 'AS'.
 ij> select xmlserialize(x as int) from t1;
 ERROR X0X17: Invalid target type for XMLSERIALIZE: 'INTEGER'.
 ij> select xmlserialize(x as varchar(20) for bit data) from t1;
@@ -338,26 +338,30 @@
 ERROR 42X01: Syntax error: Encountered "x" at line 1, column 40.
 ij> select i from t1 where xmlexists('//*' passing x);
 ERROR 42X01: Syntax error: Encountered "x" at line 1, column 48.
-ij> select i from t1 where xmlexists('//*' passing by ref x);
-ERROR X0X18: XML feature not supported: 'BY REF'.
-ij> select i from t1 where xmlexists('//*' passing by value i);
-ERROR 42Y95: The 'XMLExists' operator with a left operand type of 'CHAR' and a right operand type of 'INTEGER' is not supported.
+ij> select i from t1 where xmlexists('//*' passing by value x);
+ERROR X0X18: XML feature not supported: 'BY VALUE'.
+ij> select i from t1 where xmlexists('//*' passing by ref i);
+ERROR X0X21: Context item must have type 'XML'; 'INTEGER' is not allowed.
+ij> select i from t1 where xmlexists(i passing by ref x);
+ERROR X0X19: XML query expression must be a string literal.
+ij> select i from t1 where xmlexists(i passing by ref x, x);
+ERROR X0X20: Multiple XML context items are not allowed.
 ij> -- These should succeed.
-select i from t1 where xmlexists('//*' passing by value x);
+select i from t1 where xmlexists('//*' passing by ref x);
 I          
 -----
 1          
 5          
 6          
 7          
-ij> select i from t1 where xmlexists('//person' passing by value x);
+ij> select i from t1 where xmlexists('//person' passing by ref x);
 I          
 -----
-ij> select i from t1 where xmlexists('//lets' passing by value x);
+ij> select i from t1 where xmlexists('//lets' passing by ref x);
 I          
 -----
 7          
-ij> select xmlexists('//lets' passing by value x) from t1;
+ij> select xmlexists('//lets' passing by ref x) from t1;
 1     
 -----
 0     
@@ -367,7 +371,7 @@
 0     
 0     
 1     
-ij> select xmlexists('//try[text()='' this out '']' passing by value x) from t1;
+ij> select xmlexists('//try[text()='' this out '']' passing by ref x) from t1;
 1     
 -----
 0     
@@ -377,7 +381,7 @@
 0     
 0     
 1     
-ij> select xmlexists('//let' passing by value x) from t1;
+ij> select xmlexists('//let' passing by ref x) from t1;
 1     
 -----
 0     
@@ -387,7 +391,7 @@
 0     
 0     
 0     
-ij> select xmlexists('//try[text()='' this in '']' passing by value x) from t1;
+ij> select xmlexists('//try[text()='' this in '']' passing by ref x) from t1;
 1     
 -----
 0     
@@ -397,7 +401,7 @@
 0     
 0     
 0     
-ij> select i, xmlexists('//let' passing by value x) from t1;
+ij> select i, xmlexists('//let' passing by ref x) from t1;
 I |2     
 -----
 1 |0     
@@ -407,7 +411,7 @@
 5 |0     
 6 |0     
 7 |0     
-ij> select i, xmlexists('//lets' passing by value x) from t1;
+ij> select i, xmlexists('//lets' passing by ref x) from t1;
 I |2     
 -----
 1 |0     
@@ -417,26 +421,26 @@
 5 |0     
 6 |0     
 7 |1     
-ij> values xmlexists('//let' passing by value xmlparse(document '<lets> try this </lets>' preserve whitespace));
+ij> values xmlexists('//let' passing by ref xmlparse(document '<lets> try this </lets>' preserve whitespace));
 1     
 -----
 0     
-ij> values xmlexists('//lets' passing by value xmlparse(document '<lets> try this </lets>' preserve whitespace));
+ij> values xmlexists('//lets' passing by ref xmlparse(document '<lets> try this </lets>' preserve whitespace));
 1     
 -----
 1     
-ij> select xmlserialize(x1 as clob) from t5 where xmlexists('//*' passing by value x1);
+ij> select xmlserialize(x1 as clob) from t5 where xmlexists('//*' passing by ref x1);
 1                                                                                                                               
 -----
-ij> select xmlserialize(x2 as clob) from t5 where xmlexists('//*' passing by value x2);
+ij> select xmlserialize(x2 as clob) from t5 where xmlexists('//*' passing by ref x2);
 1                                                                                                                               
 -----
 <notnull/>                                                                                                                      
-ij> select xmlserialize(x1 as clob), xmlexists('//*' passing by value xmlparse(document '<badboy/>' preserve whitespace)) from t5;
+ij> select xmlserialize(x1 as clob), xmlexists('//*' passing by ref xmlparse(document '<badboy/>' preserve whitespace)) from t5;
 1 |2     
 -----
 NULL |1     
-ij> select xmlserialize(x1 as clob), xmlexists('//goodboy' passing by value xmlparse(document '<badboy/>' preserve whitespace)) from t5;
+ij> select xmlserialize(x1 as clob), xmlexists('//goodboy' passing by ref xmlparse(document '<badboy/>' preserve whitespace)) from t5;
 1 |2     
 -----
 NULL |0     
@@ -444,16 +448,16 @@
 I |2 |3         
 -----
 1 |NULL |<ok/>     
-ij> select i from t7 where xmlexists('/ok' passing by value x1) and xmlexists('/ok' passing by value x2);
+ij> select i from t7 where xmlexists('/ok' passing by ref x1) and xmlexists('/ok' passing by ref x2);
 I          
 -----
-ij> select i from t7 where xmlexists('/ok' passing by value x1) or xmlexists('/ok' passing by value x2);
+ij> select i from t7 where xmlexists('/ok' passing by ref x1) or xmlexists('/ok' passing by ref x2);
 I          
 -----
 1          
 ij> -- XMLEXISTS can be used wherever a boolean function is allowed,
 ----- for ex, a check constraint...
-create table t6 (i int, x xml check (xmlexists('//should' passing by value x)));
+create table t6 (i int, x xml check (xmlexists('//should' passing by ref x)));
 0 rows inserted/updated/deleted
 ij> insert into t6 values (1, xmlparse(document '<should/>' preserve whitespace));
 1 row inserted/updated/deleted
@@ -476,7 +480,7 @@
 1 row inserted/updated/deleted
 ij> insert into t8 values (5, xmlparse(document '<hi/>' preserve whitespace));
 1 row inserted/updated/deleted
-ij> select xmlexists('//child::*[name()="none"]' passing by value x) from t8;
+ij> select xmlexists('//child::*[name()="none"]' passing by ref x) from t8;
 1     
 -----
 0     
@@ -484,7 +488,7 @@
 0     
 0     
 0     
-ij> select xmlexists('//child::*[name()=''hi'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[name()=''hi'']' passing by ref x) from t8;
 1     
 -----
 0     
@@ -492,7 +496,7 @@
 0     
 0     
 1     
-ij> select xmlexists('//child::*[local-name()=''hi'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''hi'']' passing by ref x) from t8;
 1     
 -----
 1     
@@ -500,7 +504,7 @@
 0     
 0     
 1     
-ij> select xmlexists('//child::*[local-name()=''bye'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'']' passing by ref x) from t8;
 1     
 -----
 0     
@@ -508,7 +512,7 @@
 1     
 1     
 0     
-ij> select xmlexists('//*[namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//*[namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1     
 -----
 1     
@@ -516,7 +520,7 @@
 0     
 1     
 0     
-ij> select xmlexists('//*[namespace::*[string()=''http://www.good.bye'']]' passing by value x) from t8;
+ij> select xmlexists('//*[namespace::*[string()=''http://www.good.bye'']]' passing by ref x) from t8;
 1     
 -----
 0     
@@ -524,7 +528,7 @@
 1     
 0     
 0     
-ij> select xmlexists('//child::*[local-name()=''hi'' and namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''hi'' and namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1     
 -----
 1     
@@ -532,7 +536,7 @@
 0     
 0     
 0     
-ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.good.bye'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.good.bye'']]' passing by ref x) from t8;
 1     
 -----
 0     
@@ -540,7 +544,7 @@
 1     
 0     
 0     
-ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1     
 -----
 0     

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out Tue Aug  8 11:39:07 2006
@@ -165,7 +165,7 @@
 1 row inserted/updated/deleted
 ij> update t1 set x = xmlparse(document '<update> document was inserted as part of an UPDATE </update>' preserve whitespace) where i = 1;
 1 row inserted/updated/deleted
-ij> update t1 set x = xmlparse(document '<update2> document was inserted as part of an UPDATE </update2>' preserve whitespace) where xmlexists('/update' passing by value x);
+ij> update t1 set x = xmlparse(document '<update2> document was inserted as part of an UPDATE </update2>' preserve whitespace) where xmlexists('/update' passing by ref x);
 1 row inserted/updated/deleted
 ij> select i from t1 where xmlparse(document '<hein/>' preserve whitespace) is not null;
 I          
@@ -216,9 +216,9 @@
 1 row inserted/updated/deleted
 ij> -- These should fail.
 select xmlserialize(x) from t1;
-ERROR X0X16: XML syntax error; missing keyword(s): 'AS <string-type>'.
+ERROR X0X16: XML syntax error; missing keyword(s): 'AS'.
 ij> select xmlserialize(x as) from t1;
-ERROR X0X16: XML syntax error; missing keyword(s): 'AS <string-type>'.
+ERROR X0X16: XML syntax error; missing keyword(s): 'AS'.
 ij> select xmlserialize(x as int) from t1;
 ERROR X0X17: Invalid target type for XMLSERIALIZE: 'INTEGER'.
 ij> select xmlserialize(x as varchar(20) for bit data) from t1;
@@ -354,26 +354,30 @@
 ERROR 42X01: Syntax error: Encountered "x" at line 1, column 40.
 ij> select i from t1 where xmlexists('//*' passing x);
 ERROR 42X01: Syntax error: Encountered "x" at line 1, column 48.
-ij> select i from t1 where xmlexists('//*' passing by ref x);
-ERROR X0X18: XML feature not supported: 'BY REF'.
-ij> select i from t1 where xmlexists('//*' passing by value i);
-ERROR 42Y95: The 'XMLExists' operator with a left operand type of 'CHAR' and a right operand type of 'INTEGER' is not supported.
+ij> select i from t1 where xmlexists('//*' passing by value x);
+ERROR X0X18: XML feature not supported: 'BY VALUE'.
+ij> select i from t1 where xmlexists('//*' passing by ref i);
+ERROR X0X21: Context item must have type 'XML'; 'INTEGER' is not allowed.
+ij> select i from t1 where xmlexists(i passing by ref x);
+ERROR X0X19: XML query expression must be a string literal.
+ij> select i from t1 where xmlexists(i passing by ref x, x);
+ERROR X0X20: Multiple XML context items are not allowed.
 ij> -- These should succeed.
-select i from t1 where xmlexists('//*' passing by value x);
+select i from t1 where xmlexists('//*' passing by ref x);
 I          
 -----------
 1          
 5          
 6          
 7          
-ij> select i from t1 where xmlexists('//person' passing by value x);
+ij> select i from t1 where xmlexists('//person' passing by ref x);
 I          
 -----------
-ij> select i from t1 where xmlexists('//lets' passing by value x);
+ij> select i from t1 where xmlexists('//lets' passing by ref x);
 I          
 -----------
 7          
-ij> select xmlexists('//lets' passing by value x) from t1;
+ij> select xmlexists('//lets' passing by ref x) from t1;
 1    
 -----
 false
@@ -383,7 +387,7 @@
 false
 false
 true 
-ij> select xmlexists('//try[text()='' this out '']' passing by value x) from t1;
+ij> select xmlexists('//try[text()='' this out '']' passing by ref x) from t1;
 1    
 -----
 false
@@ -393,7 +397,7 @@
 false
 false
 true 
-ij> select xmlexists('//let' passing by value x) from t1;
+ij> select xmlexists('//let' passing by ref x) from t1;
 1    
 -----
 false
@@ -403,7 +407,7 @@
 false
 false
 false
-ij> select xmlexists('//try[text()='' this in '']' passing by value x) from t1;
+ij> select xmlexists('//try[text()='' this in '']' passing by ref x) from t1;
 1    
 -----
 false
@@ -413,7 +417,7 @@
 false
 false
 false
-ij> select i, xmlexists('//let' passing by value x) from t1;
+ij> select i, xmlexists('//let' passing by ref x) from t1;
 I          |2    
 -----------------
 1          |false
@@ -423,7 +427,7 @@
 5          |false
 6          |false
 7          |false
-ij> select i, xmlexists('//lets' passing by value x) from t1;
+ij> select i, xmlexists('//lets' passing by ref x) from t1;
 I          |2    
 -----------------
 1          |false
@@ -433,26 +437,26 @@
 5          |false
 6          |false
 7          |true 
-ij> values xmlexists('//let' passing by value xmlparse(document '<lets> try this </lets>' preserve whitespace));
+ij> values xmlexists('//let' passing by ref xmlparse(document '<lets> try this </lets>' preserve whitespace));
 1    
 -----
 false
-ij> values xmlexists('//lets' passing by value xmlparse(document '<lets> try this </lets>' preserve whitespace));
+ij> values xmlexists('//lets' passing by ref xmlparse(document '<lets> try this </lets>' preserve whitespace));
 1    
 -----
 true 
-ij> select xmlserialize(x1 as clob) from t5 where xmlexists('//*' passing by value x1);
+ij> select xmlserialize(x1 as clob) from t5 where xmlexists('//*' passing by ref x1);
 1                                                                                                                               
 --------------------------------------------------------------------------------------------------------------------------------
-ij> select xmlserialize(x2 as clob) from t5 where xmlexists('//*' passing by value x2);
+ij> select xmlserialize(x2 as clob) from t5 where xmlexists('//*' passing by ref x2);
 1                                                                                                                               
 --------------------------------------------------------------------------------------------------------------------------------
 <notnull/>                                                                                                                      
-ij> select xmlserialize(x1 as clob), xmlexists('//*' passing by value xmlparse(document '<badboy/>' preserve whitespace)) from t5;
+ij> select xmlserialize(x1 as clob), xmlexists('//*' passing by ref xmlparse(document '<badboy/>' preserve whitespace)) from t5;
 1                                                                                                                               |2    
 --------------------------------------------------------------------------------------------------------------------------------------
 NULL                                                                                                                            |true 
-ij> select xmlserialize(x1 as clob), xmlexists('//goodboy' passing by value xmlparse(document '<badboy/>' preserve whitespace)) from t5;
+ij> select xmlserialize(x1 as clob), xmlexists('//goodboy' passing by ref xmlparse(document '<badboy/>' preserve whitespace)) from t5;
 1                                                                                                                               |2    
 --------------------------------------------------------------------------------------------------------------------------------------
 NULL                                                                                                                            |false
@@ -460,16 +464,16 @@
 I          |2         |3         
 ---------------------------------
 1          |NULL      |<ok/>     
-ij> select i from t7 where xmlexists('/ok' passing by value x1) and xmlexists('/ok' passing by value x2);
+ij> select i from t7 where xmlexists('/ok' passing by ref x1) and xmlexists('/ok' passing by ref x2);
 I          
 -----------
-ij> select i from t7 where xmlexists('/ok' passing by value x1) or xmlexists('/ok' passing by value x2);
+ij> select i from t7 where xmlexists('/ok' passing by ref x1) or xmlexists('/ok' passing by ref x2);
 I          
 -----------
 1          
 ij> -- XMLEXISTS can be used wherever a boolean function is allowed,
 -- for ex, a check constraint...
-create table t6 (i int, x xml check (xmlexists('//should' passing by value x)));
+create table t6 (i int, x xml check (xmlexists('//should' passing by ref x)));
 0 rows inserted/updated/deleted
 ij> insert into t6 values (1, xmlparse(document '<should/>' preserve whitespace));
 1 row inserted/updated/deleted
@@ -492,7 +496,7 @@
 1 row inserted/updated/deleted
 ij> insert into t8 values (5, xmlparse(document '<hi/>' preserve whitespace));
 1 row inserted/updated/deleted
-ij> select xmlexists('//child::*[name()="none"]' passing by value x) from t8;
+ij> select xmlexists('//child::*[name()="none"]' passing by ref x) from t8;
 1    
 -----
 false
@@ -500,7 +504,7 @@
 false
 false
 false
-ij> select xmlexists('//child::*[name()=''hi'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[name()=''hi'']' passing by ref x) from t8;
 1    
 -----
 false
@@ -508,7 +512,7 @@
 false
 false
 true 
-ij> select xmlexists('//child::*[local-name()=''hi'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''hi'']' passing by ref x) from t8;
 1    
 -----
 true 
@@ -516,7 +520,7 @@
 false
 false
 true 
-ij> select xmlexists('//child::*[local-name()=''bye'']' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'']' passing by ref x) from t8;
 1    
 -----
 false
@@ -524,7 +528,7 @@
 true 
 true 
 false
-ij> select xmlexists('//*[namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//*[namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1    
 -----
 true 
@@ -532,7 +536,7 @@
 false
 true 
 false
-ij> select xmlexists('//*[namespace::*[string()=''http://www.good.bye'']]' passing by value x) from t8;
+ij> select xmlexists('//*[namespace::*[string()=''http://www.good.bye'']]' passing by ref x) from t8;
 1    
 -----
 false
@@ -540,7 +544,7 @@
 true 
 false
 false
-ij> select xmlexists('//child::*[local-name()=''hi'' and namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''hi'' and namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1    
 -----
 true 
@@ -548,7 +552,7 @@
 false
 false
 false
-ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.good.bye'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.good.bye'']]' passing by ref x) from t8;
 1    
 -----
 false
@@ -556,7 +560,7 @@
 true 
 false
 false
-ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+ij> select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 1    
 -----
 false

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xmlBinding.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xmlBinding.java?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xmlBinding.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xmlBinding.java Tue Aug  8 11:39:07 2006
@@ -161,7 +161,7 @@
         try {
             pSt = conn.prepareStatement(
                 "select i from xTable.t1 where " +
-                "XMLEXISTS('//*' PASSING BY VALUE ?)");
+                "XMLEXISTS('//*' PASSING BY REF ?)");
             bindAndExecute(pSt, 1, Types.VARCHAR, null, "X0X14", true);
         } catch (SQLException se) {
             checkException(se, "X0X14");
@@ -354,7 +354,7 @@
             // be fine, but the subsequent "execute" should fail.
             PreparedStatement pSt = conn.prepareStatement(
                 "select i from xTable.t1 where " +
-                "XMLEXISTS (? PASSING BY VALUE x)");
+                "XMLEXISTS (? PASSING BY REF x)");
             pSt.setString(1, "//*");
             pSt.execute();
 
@@ -527,7 +527,7 @@
     {
         PreparedStatement pSt = conn.prepareStatement(
             "select i from " + tableName + " where " +
-            "xmlexists('" + xPath + "' passing by value x)");
+            "xmlexists('" + xPath + "' passing by ref x)");
 
         System.out.println("Running XMLEXISTS with: " + xPath);
         ResultSet rs = pSt.executeQuery();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql?rev=429764&r1=429763&r2=429764&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql Tue Aug  8 11:39:07 2006
@@ -99,7 +99,7 @@
 insert into t2 values (1, xmlparse(document '<should> work as planned </should>' preserve whitespace));
 insert into t5 (x1, x2) values (null, xmlparse(document '<notnull/>' preserve whitespace));
 update t1 set x = xmlparse(document '<update> document was inserted as part of an UPDATE </update>' preserve whitespace) where i = 1;
-update t1 set x = xmlparse(document '<update2> document was inserted as part of an UPDATE </update2>' preserve whitespace) where xmlexists('/update' passing by value x);
+update t1 set x = xmlparse(document '<update2> document was inserted as part of an UPDATE </update2>' preserve whitespace) where xmlexists('/update' passing by ref x);
 select i from t1 where xmlparse(document '<hein/>' preserve whitespace) is not null;
 select i from t1 where xmlparse(document '<hein/>' preserve whitespace) is not null order by i;
 
@@ -167,31 +167,33 @@
 select i from t1 where xmlexists('//*');
 select i from t1 where xmlexists('//*' x);
 select i from t1 where xmlexists('//*' passing x);
-select i from t1 where xmlexists('//*' passing by ref x);
-select i from t1 where xmlexists('//*' passing by value i);
--- These should succeed.
 select i from t1 where xmlexists('//*' passing by value x);
-select i from t1 where xmlexists('//person' passing by value x);
-select i from t1 where xmlexists('//lets' passing by value x);
-select xmlexists('//lets' passing by value x) from t1;
-select xmlexists('//try[text()='' this out '']' passing by value x) from t1;
-select xmlexists('//let' passing by value x) from t1;
-select xmlexists('//try[text()='' this in '']' passing by value x) from t1;
-select i, xmlexists('//let' passing by value x) from t1;
-select i, xmlexists('//lets' passing by value x) from t1;
-values xmlexists('//let' passing by value xmlparse(document '<lets> try this </lets>' preserve whitespace));
-values xmlexists('//lets' passing by value xmlparse(document '<lets> try this </lets>' preserve whitespace));
-select xmlserialize(x1 as clob) from t5 where xmlexists('//*' passing by value x1);
-select xmlserialize(x2 as clob) from t5 where xmlexists('//*' passing by value x2);
-select xmlserialize(x1 as clob), xmlexists('//*' passing by value xmlparse(document '<badboy/>' preserve whitespace)) from t5;
-select xmlserialize(x1 as clob), xmlexists('//goodboy' passing by value xmlparse(document '<badboy/>' preserve whitespace)) from t5;
+select i from t1 where xmlexists('//*' passing by ref i);
+select i from t1 where xmlexists(i passing by ref x);
+select i from t1 where xmlexists(i passing by ref x, x);
+-- These should succeed.
+select i from t1 where xmlexists('//*' passing by ref x);
+select i from t1 where xmlexists('//person' passing by ref x);
+select i from t1 where xmlexists('//lets' passing by ref x);
+select xmlexists('//lets' passing by ref x) from t1;
+select xmlexists('//try[text()='' this out '']' passing by ref x) from t1;
+select xmlexists('//let' passing by ref x) from t1;
+select xmlexists('//try[text()='' this in '']' passing by ref x) from t1;
+select i, xmlexists('//let' passing by ref x) from t1;
+select i, xmlexists('//lets' passing by ref x) from t1;
+values xmlexists('//let' passing by ref xmlparse(document '<lets> try this </lets>' preserve whitespace));
+values xmlexists('//lets' passing by ref xmlparse(document '<lets> try this </lets>' preserve whitespace));
+select xmlserialize(x1 as clob) from t5 where xmlexists('//*' passing by ref x1);
+select xmlserialize(x2 as clob) from t5 where xmlexists('//*' passing by ref x2);
+select xmlserialize(x1 as clob), xmlexists('//*' passing by ref xmlparse(document '<badboy/>' preserve whitespace)) from t5;
+select xmlserialize(x1 as clob), xmlexists('//goodboy' passing by ref xmlparse(document '<badboy/>' preserve whitespace)) from t5;
 select i, xmlserialize(x1 as char(10)), xmlserialize (x2 as char(10)) from t7;
-select i from t7 where xmlexists('/ok' passing by value x1) and xmlexists('/ok' passing by value x2);
-select i from t7 where xmlexists('/ok' passing by value x1) or xmlexists('/ok' passing by value x2);
+select i from t7 where xmlexists('/ok' passing by ref x1) and xmlexists('/ok' passing by ref x2);
+select i from t7 where xmlexists('/ok' passing by ref x1) or xmlexists('/ok' passing by ref x2);
 
 -- XMLEXISTS can be used wherever a boolean function is allowed,
 -- for ex, a check constraint...
-create table t6 (i int, x xml check (xmlexists('//should' passing by value x)));
+create table t6 (i int, x xml check (xmlexists('//should' passing by ref x)));
 insert into t6 values (1, xmlparse(document '<should/>' preserve whitespace));
 insert into t6 values (1, xmlparse(document '<shouldnt/>' preserve whitespace));
 select xmlserialize(x as char(20)) from t6;
@@ -203,15 +205,15 @@
 insert into t8 values (3, xmlparse(document '<a:bye xmlns:a="http://www.good.bye"/>' preserve whitespace));
 insert into t8 values (4, xmlparse(document '<b:bye xmlns:b="http://www.hi.there"/>' preserve whitespace));
 insert into t8 values (5, xmlparse(document '<hi/>' preserve whitespace));
-select xmlexists('//child::*[name()="none"]' passing by value x) from t8;
-select xmlexists('//child::*[name()=''hi'']' passing by value x) from t8;
-select xmlexists('//child::*[local-name()=''hi'']' passing by value x) from t8;
-select xmlexists('//child::*[local-name()=''bye'']' passing by value x) from t8;
-select xmlexists('//*[namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
-select xmlexists('//*[namespace::*[string()=''http://www.good.bye'']]' passing by value x) from t8;
-select xmlexists('//child::*[local-name()=''hi'' and namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
-select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.good.bye'']]' passing by value x) from t8;
-select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.hi.there'']]' passing by value x) from t8;
+select xmlexists('//child::*[name()="none"]' passing by ref x) from t8;
+select xmlexists('//child::*[name()=''hi'']' passing by ref x) from t8;
+select xmlexists('//child::*[local-name()=''hi'']' passing by ref x) from t8;
+select xmlexists('//child::*[local-name()=''bye'']' passing by ref x) from t8;
+select xmlexists('//*[namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
+select xmlexists('//*[namespace::*[string()=''http://www.good.bye'']]' passing by ref x) from t8;
+select xmlexists('//child::*[local-name()=''hi'' and namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
+select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.good.bye'']]' passing by ref x) from t8;
+select xmlexists('//child::*[local-name()=''bye'' and namespace::*[string()=''http://www.hi.there'']]' passing by ref x) from t8;
 
 -- clean up.
 drop table t0;



Mime
View raw message