<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en">

    <xsd:annotation>
	<xsd:documentation xml:lang="en">
	    XML Schema Definition (.xsd) for the XML Query Language for XpressEngine.

	    XpressEngine is an open source framework for creating your web sites.
	    http://xpressengine.org/

	    Author: Adrian Constantin, Arnia Software (adrian.constantin@arnia.ro)
	    Date:   08 mar 2012

	    Strictly speaking the term "query language" is improper since the
	    language also describes the SQL data change statements (INSERT, UPDATE, 
	    DELETE), not only query statements (SELECT).

	    Although SQL does not distinguish between the syntax of queries and
	    sub-queries, the XML Query Language identifies 4 query types:
	     - TableSubquery:
		- possibly empty (for a base table given by name)
		- abstract (used as a base for the TableType)
		- query navigation only (LIMIT, OFFSET)
	     - ExpressionSubquery
		- should include at least a table
		- query nagivation only
	     - Select-list subquery
		- should include at least a table
		- query nagivation only
		- optional alias
	     - QueryStatement
		- should include at least a table
		- query navigation and pagination
		- 'id' and 'alias' attributes

	    The XML types hierarchy here shows as follows:

	    +-- VarNameDefaultType
	    +-- SortColumnType
	    |
	    +-- MainStatementNavigationType
	    |	+-- SimpleQueryNavigationType
	    |
	    +-- SqlStatementContentModel (abstract)
	    |	+-- SqlStatementContents (abstract)
	    |	|   +-- SqlQueryContents (abstract)
	    |	|   |	+-- SqlQueryType
	    |	|   |	    +-- ExpressionSubqueryContents
	    |	|   |		+-- ExpressionSubqueryType
	    |	|   +-- SqlStatementType
	    |	|
	    |	+-- SqlTableSubquery (abstract)
	    |	    +-- TableType
	    |
	    +-- TablesType
	    |
	    +-- ColumnType
	    +-- ColumnsType
	    |
	    +-- ConditionType
	    +-- ConditionsGroupType
	    +-- ConditionsType
	    |
	    +-- GroupType
	    +-- GroupsType
	    |
	    +-- IndexHintType
	    +-- IndexHintsType
	    |
	    +-- pipeAttributeType
	    +-- dbTargetAttributeType	(for db-specific index hints)
	    +-- HintTypeAttributeType

	    +-- conditionAttrs	(attribute group)
	    +-- argumentAttrs	(query-argument attributes)

	    The types defined here closely model the behavior of php classes in
	    classes/xml/xmlquery/**/*.php
	</xsd:documentation>
    </xsd:annotation>

    <xsd:complexType name="VarNameDefaultType">
	<xsd:annotation>
	    <xsd:documentation>
		Common XSD type for page-row-count/current-page/page-count elements
		that are empty and only take a variable name and/or a default as
		attributes.

		Note that a variable name here means an index in a php array, which 
		can be any string, not just an [a-zA-Z0-9_]* identifier.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="xsd:anyType">
		<xsd:attribute name="var" type="xsd:string" />
		<xsd:attribute name="default" type="xsd:unsignedLong" />
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="SortColumnType">
	<xsd:annotation>
	    <xsd:documentation>
		A column name in an ORDER BY clause, given directly by name
		(default attribute) or in a variable (var attribute). Either
		one of the two attributes is required
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="xsd:anyType">
		<xsd:attribute name="var" type="xsd:string" />
		<xsd:attribute name="default" type="xsd:string" />
		<xsd:attribute name="order" type="xsd:string">
		    <xsd:annotation>
			<xsd:documentation>
			    XE treats the values "asc" and "desc" as the corresponding SQL
			    keywords, while all the other values are taken as a parameter
			    name.
			</xsd:documentation>
		    </xsd:annotation>
		</xsd:attribute>
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="MainStatementNavigationType">
	<xsd:annotation>
	    <xsd:documentation>
		XE sorting and paging for a main-statement query.

		Defined as a sequence of choices so that the &lt;index&gt; element
		can appear more than once.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:sequence>
	    <xsd:choice minOccurs="1" maxOccurs="unbounded">
		<xsd:element name="index" type="SortColumnType" />
		<xsd:element name="list_count" type="VarNameDefaultType" />
		<xsd:element name="page" type="VarNameDefaultType" />
		<xsd:element name="page_count" type="VarNameDefaultType" />
	    </xsd:choice>
	</xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="SimpleQueryNavigationType">
	<xsd:annotation>
	    <xsd:documentation>
		Sub-queries do not include a page_count
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="MainStatementNavigationType">
		<xsd:sequence>
		    <xsd:choice minOccurs="0" maxOccurs="unbounded">
			<xsd:element name="index" type="SortColumnType" />
			<xsd:element name="list_count" type="VarNameDefaultType" />
			<xsd:element name="page" type="VarNameDefaultType" />
		    </xsd:choice>
		</xsd:sequence>
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="SqlStatementContentModel" abstract="true">
	<xsd:annotation>
	    <xsd:documentation>
		The base of the SQL query and statement type hierarchy in the XML
		query language.

		References all possible SQL stetement clauses, while none of them
		is declared as required. It is the most generic SQL statement or
		query type, though no such SQL statement instantiates it directly.

		The &lt;index_hint&gt; element could be allowed to appear multiple
		times, in case different hints for different databases will be
		allowed by the syntax.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:all>
	    <xsd:element name="columns" minOccurs="0" type="ColumnsType" />
	    <xsd:element name="tables" minOccurs="0" type="TablesType">
		<xsd:unique name="table_aliases">
		    <xsd:selector xpath="table" />
		    <xsd:field xpath="@alias" />
		</xsd:unique>
	    </xsd:element>
	    <xsd:element name="conditions" minOccurs="0" type="ConditionsType" />
	    <xsd:element name="groups" minOccurs="0" type="GroupsType">
		<xsd:unique name="statement_content_model_groups">
		    <xsd:selector xpath="group" />
		    <xsd:field xpath="@column" />
		</xsd:unique>
	    </xsd:element>
	    <xsd:element name="navigation" minOccurs="0" type="MainStatementNavigationType" />
	    <xsd:element name="index_hint" minOccurs="0" type="IndexHintsType" />
	</xsd:all>
    </xsd:complexType>

    <xsd:complexType name="SqlStatementContents" abstract="true">
	<xsd:annotation>
	    <xsd:documentation>
		An SQL generic DELETE, UPDATE, INSERT or SELECT statement.
		The only common clause for these statements is the table-specification,
		for which reason the &lt;tables&gt; element is the only one required by
		the syntax
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="SqlStatementContentModel">
		<xsd:all>
		    <xsd:element name="columns" minOccurs="0" type="ColumnsType" />
		    <xsd:element name="tables" minOccurs="1" type="TablesType">
			<xsd:unique name="table_aliases2">
			    <xsd:selector xpath="table" />
			    <xsd:field xpath="@alias" />
			</xsd:unique>
		    </xsd:element>
		    <xsd:element name="conditions" minOccurs="0" type="ConditionsType" />
		    <xsd:element name="groups" minOccurs="0" type="GroupsType">
			<xsd:unique name="statement_contents_groups">
			    <xsd:selector xpath="group" />
			    <xsd:field xpath="@column" />
			</xsd:unique>
		    </xsd:element>
		    <xsd:element name="navigation" minOccurs="0" type="MainStatementNavigationType" />
		    <xsd:element name="index_hint" minOccurs="0" type="IndexHintsType" />
		</xsd:all>
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>
    
    <xsd:complexType name="SqlQueryContents" abstract="true">
	<xsd:annotation>
	    <xsd:documentation>
		An SQL SELECT statement (used to form sub-queries), represented as 
		a case of (derived from) a generic SQL statement.

		In adition to the the table-specification required by the base
		SqlStatementContents type, SQL queries also require a select-list.
		This, however is implied to be "*" if missing.
		So this type is the same as its base type, but is keep to represent
		a SQL query, as opposed to a generic SQL statement.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="SqlStatementContents">
		<xsd:all>
		    <xsd:element name="columns" minOccurs="0" type="ColumnsType" />
		    <xsd:element name="tables" minOccurs="1" type="TablesType">
			<xsd:unique name="table_aliases3">
			    <xsd:selector xpath="table" />
			    <xsd:field xpath="@alias" />
			</xsd:unique>
		    </xsd:element>
		    <xsd:element name="conditions" minOccurs="0" type="ConditionsType" />
		    <xsd:element name="groups" minOccurs="0" type="GroupsType">
			<xsd:unique name="query_contents_groups">
			    <xsd:selector xpath="group" />
			    <xsd:field xpath="@column" />
			</xsd:unique>
		    </xsd:element>
		    <xsd:element name="navigation" minOccurs="0" type="SimpleQueryNavigationType" />
		    <xsd:element name="index_hint" minOccurs="0" type="IndexHintsType" />
		</xsd:all>
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="SqlTableSubquery">
	<xsd:annotation>
	    <xsd:documentation>
		Content model for &lt;table&gt; element. The &lt;table&gt; element may stand
		for one of:
		    - a base table or view, with only a table name and an optional alias,
		    - a base table in a join, with the table name and join type attributes, 
			and the join conditions as content,
		    - a sub-query, with the contents of a query and the alias attribute.

		Note that the current syntax provides no means to express a joined sub-query.
		Also the schema definition syntax (XSD) does not allow rules to enforce 
		exactly one of the above cases in a given element, but rather to only express
		the sum (union) of all 3 cases for the &lt;table&gt; element.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="SqlStatementContentModel">
		<xsd:all>
		    <xsd:element name="columns" minOccurs="0" type="ColumnsType" />
		    <xsd:element name="tables" minOccurs="0" type="TablesType">
			<xsd:unique name="table_aliases4">
			    <xsd:selector xpath="table" />
			    <xsd:field xpath="@alias" />
			</xsd:unique>
		    </xsd:element>
		    <xsd:element name="conditions" minOccurs="0" type="ConditionsType" />
		    <xsd:element name="groups" minOccurs="0" type="GroupsType">
			<xsd:unique name="table_subquery_groups">
			    <xsd:selector xpath="group" />
			    <xsd:field xpath="@column" />
			</xsd:unique>
		    </xsd:element>
		    <xsd:element name="navigation" minOccurs="0" type="SimpleQueryNavigationType" />
		    <xsd:element name="index_hint" minOccurs="0" type="IndexHintsType" />
		</xsd:all>
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:simpleType name="actionAttributeType">
	<xsd:annotation>
	    <xsd:documentation xmlns:lang="en">
		There are many more SQL statement types defined by the SQL language, but
		currently the above 4 types are supported by the XML Query language in XE.

		However certain SQL CREATE statements are also supported in the XML
		Schema Language in XE.
	    </xsd:documentation>
	</xsd:annotation>
	<xsd:restriction base="xsd:Name">
	    <xsd:pattern value="[dD][eE][lL][eE][tT][eE]" />
	    <xsd:pattern value="[uU][pP][dD][aA][tT][eE]" />
	    <xsd:pattern value="[sS][eE][lL][eE][cC][tT]" />
	    <xsd:pattern value="[iI][nN][sS][eE][rR][tT]" />
	    <xsd:pattern value="[iI][nN][sS][eE][rR][tT]-[sS][eE][lL][eE][cC][tT]" />
	</xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="SqlStatementType">
	<xsd:complexContent>
	    <xsd:extension base="SqlStatementContents">
		<xsd:attribute name="id" type="xsd:Name" use="required" />
		<xsd:attribute name="action" type="actionAttributeType" use="required">
		</xsd:attribute>
	    </xsd:extension>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="SqlQueryType">
	<xsd:annotation>
	    <xsd:documentation>
		Element type for a SQL sub-query in the SELECT list or an expression.
		Subqueries directly in the FROM clause are expressed by TableType.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:extension base="SqlQueryContents">
		<xsd:attribute name="alias" type="xsd:string" use="optional" />
	    </xsd:extension>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="ExpressionSubqueryContents">
	<xsd:annotation>
	    <xsd:documentation>
		Base type for expression sub-queries (used in &lt;condition&gt;s),
		which have no alias.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="SqlQueryType">
		<xsd:all>
		    <xsd:element name="columns" minOccurs="0" type="ColumnsType" />
		    <xsd:element name="tables" minOccurs="1" type="TablesType">
			<xsd:unique name="table_aliases5">
			    <xsd:selector xpath="table" />
			    <xsd:field xpath="@alias" />
			</xsd:unique>
		    </xsd:element>
		    <xsd:element name="conditions" minOccurs="0" type="ConditionsType" />
		    <xsd:element name="groups" minOccurs="0" type="GroupsType">
			<xsd:unique name="expression_subquery_groups">
			    <xsd:selector xpath="group" />
			    <xsd:field xpath="@column" />
			</xsd:unique>
		    </xsd:element>
		    <xsd:element name="navigation" minOccurs="0" type="SimpleQueryNavigationType" />
		    <xsd:element name="index_hint" minOccurs="0" type="IndexHintsType" />
		</xsd:all>

		<xsd:attribute name="alias" type="xsd:string" use="prohibited" />
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="ColumnsType">
	<xsd:annotation>
	    <xsd:documentation>
		Columns list for a SELECT, UPDATE, INSERT statement
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:sequence>
	    <xsd:choice minOccurs="0" maxOccurs="unbounded">
		<xsd:element name="column" type="ColumnType" />
		<xsd:element name="query" type="SqlQueryType" />
	    </xsd:choice>
	</xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="ColumnType">
	<xsd:annotation>
	    <xsd:documentation>
		A column name for a SELECT, UPDATE, INSERT statement.
		SELECT statements can have a (simple) expression as the column
		name and can have an alias.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="xsd:anyType">
		<xsd:attribute name="name" type="xsd:string" use="optional" />
		<xsd:attribute name="alias" type="xsd:string" use="optional" />
		<xsd:attribute name="click_count" type="xsd:unsignedLong" use="optional" />
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="TablesType">
	<xsd:annotation>
	    <xsd:documentation>
		For table subqueries use &lt;table query="true"&gt;.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:sequence>
	    <xsd:element name="table" type="TableType" maxOccurs="unbounded" />
	    <!-- <xsd:element name="query" type="QueryType" /> -->
	</xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="TableType">
	<xsd:annotation>
	    <xsd:documentation>
		A &lt;table&gt; should include the content of a query if the table is a 
		subquery, that is if it also specifies the query="true" attribute.

		A &lt;table&gt; that specifies type="join-type..." for joining with other
		tables, should include a &lt;conditions&gt; element with the join 
		condition(s).

		The particular SqlTableSubquery type is defined and needed for the base
		type, instead of the general SqlQueryType, becase the contents of a
		&lt;table&gt; element can still be empty in case of a base table, while a
		subquery always has a FROM clause and a select list.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:extension base="SqlTableSubquery">
		<xsd:attribute name="query" use="optional">
		    <xsd:annotation>
			<xsd:documentation>
			    Only the query="true" value should be used. The false
			    value is listed here just for completeness.

			    The query and name attributes should be mutually exclusive;
			    a sub-query should only use aliases, that is the alias
			    attribute, instead of name.
			</xsd:documentation>
		    </xsd:annotation>

		    <xsd:simpleType>
			<xsd:restriction base="xsd:Name">
			    <xsd:enumeration value="false" />
			    <xsd:enumeration value="true" />
			</xsd:restriction>
		    </xsd:simpleType>
		</xsd:attribute>

		<xsd:attribute name="name" type="xsd:string" use="optional">
		    <xsd:annotation>
			<xsd:documentation>
			    With the use of proper quoting, almost any string can be a SQL
			    (table) name (the exceptions are certain clases of Unicode
			    characters listed in the SQL standard).
			</xsd:documentation>
		    </xsd:annotation>
		</xsd:attribute>

		<xsd:attribute name="alias" type="xsd:string"  use="optional" />

		<xsd:attribute name="type" use="optional">
		    <xsd:annotation>
			<xsd:documentation>
			    Attributes "type" and "query" should be mutually exclusive, since both
			    of them require the same &lt;conditions&gt; element in the content for
			    the &lt;table&gt;, but for different purposes.

			    The type="inner join" and type="full outer join" cases are not
			    implemented.
			</xsd:documentation>
		    </xsd:annotation>
		    <xsd:simpleType>
			<xsd:restriction base="xsd:string">
			    <!-- <xsd:enumeration value="inner join" /> -->
			    <xsd:enumeration value="left join" />
			    <xsd:enumeration value="left outer join" />
			    <xsd:enumeration value="right join" />
			    <xsd:enumeration value="right outer join" />
			    <!-- <xsd:enumeration value="outer join" /> -->
			    <!-- <xsd:enumeration value="full outer join" /> -->
			</xsd:restriction>
		    </xsd:simpleType>
		</xsd:attribute>
	    </xsd:extension>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="ConditionsType">
	<xsd:annotation>
	    <xsd:documentation>
		Condition expressions in a WHERE clause. Using the &lt;group&gt;
		element is simillar to using parentheses in SQL.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:sequence>
	    <xsd:choice minOccurs="0" maxOccurs="unbounded">
		<xsd:element name="condition" type="ConditionType" />
		<xsd:element name="query" type="ExpressionSubqueryType" />
		<xsd:element name="group" type="ConditionsGroupType" />
	    </xsd:choice>
	</xsd:sequence>
    </xsd:complexType>

    <xsd:simpleType name="pipeAttributeType">
	<xsd:annotation>
	    <xsd:documentation>
		SQL logical operators AND and OR.
		
		Most database systems also support the non-standard operator XOR,
		but Transact-SQL just claims the bitwise operator ^ can be used
		instead, and does not provide XOR.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:restriction base="xsd:string">
	    <xsd:pattern value="[aA][nN][dD]" />
	    <xsd:pattern value="[oO][rR]" />
	</xsd:restriction>
    </xsd:simpleType>

    <xsd:attributeGroup name="conditionAttrs">
	<xsd:annotation>
	    <xsd:documentation>
		Attributes to describe a SQL sub-expression, common to simple subexpression
		and to subexpressions with a subquery as operand
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:attribute name="operation" use="required">
	    <xsd:simpleType>
		<xsd:restriction base="xsd:string">
		    <xsd:enumeration value="equal" />
		    <xsd:enumeration value="notequal" />
		    <xsd:enumeration value="excess" />
		    <xsd:enumeration value="more" />
		    <xsd:enumeration value="below" />
		    <xsd:enumeration value="less" />
		    <xsd:enumeration value="below" />
		    <xsd:enumeration value="null" />
		    <xsd:enumeration value="notnull" />
		    <xsd:enumeration value="in" />
		    <xsd:enumeration value="notin" />
		    <xsd:enumeration value="and" />
		    <xsd:enumeration value="or" />
		    <xsd:enumeration value="xor" />
		    <xsd:enumeration value="not" />
		    <xsd:enumeration value="between" />
		    <xsd:enumeration value="like" />
		    <xsd:enumeration value="like_prefix" />
		    <xsd:enumeration value="like_tail" />
		    <xsd:enumeration value="notlike" />
		    <xsd:enumeration value="notlike_prefix" />
		    <xsd:enumeration value="notlike_tail" />
		</xsd:restriction>
	    </xsd:simpleType>
	</xsd:attribute>

	<xsd:attribute name="column" type="xsd:string" use="required" />

	<xsd:attribute name="pipe" type="pipeAttributeType">
	    <xsd:annotation>
		<xsd:documentation>
		    The pipe attribute is only optional when there is one condition
		    in the &lt;conditions&gt; / &lt;group&gt; element.
		</xsd:documentation>
	    </xsd:annotation>
	</xsd:attribute>
    </xsd:attributeGroup>

    <xsd:attributeGroup name="argumentAttrs">
	<xsd:attribute name="filter">
	    <xsd:simpleType>
		<xsd:restriction base="xsd:string">
		    <xsd:enumeration value="email" />
		    <xsd:enumeration value="email_address" />
		    <xsd:enumeration value="homepage" />
		    <xsd:enumeration value="userid" />
		    <xsd:enumeration value="user_id" />
		    <xsd:enumeration value="number" />
		    <xsd:enumeration value="numbers" />
		    <xsd:enumeration value="alpha" />
		    <xsd:enumeration value="alpha_number" />
		</xsd:restriction>
	    </xsd:simpleType>
	</xsd:attribute>

	<xsd:attribute name="default" type="xsd:string">
	    <xsd:annotation>
		<xsd:documentation>
		    Certain values have special meaning:
			- ipaddress()
			- unixtime()
			- curdate()
			- plus(int count)
			- minus(int count)
			- multiply(int count)
			- sequence()

		    However these values are only special to XE, while for the schema
		    definition they are strings.
		</xsd:documentation>
	    </xsd:annotation>
	</xsd:attribute>

	<xsd:attribute name="notnull">
	    <xsd:simpleType>
		<xsd:restriction base="xsd:string">
		    <xsd:enumeration value="notnull" />
		</xsd:restriction>
	    </xsd:simpleType>
	</xsd:attribute>

	<xsd:attribute name="minlength" type="xsd:unsignedLong" />
	<xsd:attribute name="maxlength" type="xsd:unsignedLong" />
    </xsd:attributeGroup>

    <xsd:complexType name="ExpressionSubqueryType">
	<xsd:annotation>
	    <xsd:documentation>
		Element type for sub-expresions with a subquery term.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:extension base="ExpressionSubqueryContents">
		<xsd:attributeGroup ref="conditionAttrs" />
	    </xsd:extension>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="ConditionType">
	<xsd:annotation>
	    <xsd:documentation>
		Currently only conditions of the form:
		    "column" op var_name
		    "column" op (sub-query)
		are allowed by the XML query language syntax.

		The &lt;query&gt; element should only be provided as content if
		var or default attributes are not provided.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:extension base="xsd:anyType">
		<xsd:attributeGroup ref="conditionAttrs" />

		<xsd:attribute name="var" type="xsd:string" use="optional" />

		<xsd:attributeGroup ref="argumentAttrs" />
	    </xsd:extension>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="ConditionsGroupType">
	<xsd:annotation>
	    <xsd:documentation>
		Groups of conditions in a WHERE clause.
		Same as the global ConditionsType, plus the pipe="and|or" attribute.

		The pipes attribute is only optional in the (unlikely) case that the
		&lt;conditions&gt; element contains only the group.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:extension base="ConditionsType">
		<xsd:attribute name="pipe" type="pipeAttributeType" />
	    </xsd:extension>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="GroupsType">
	<xsd:annotation>
	    <xsd:documentation>
		The GROUP BY clase.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:sequence>
	    <xsd:element name="group" type="GroupType" maxOccurs="unbounded" />
	</xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="GroupType">
	<xsd:annotation>
	    <xsd:documentation>
		A column name in the GROUP BY clause.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="xsd:anyType">
		<xsd:attribute name="column" type="xsd:string" use="required" />
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:simpleType name="dbTargetAttributeType">
	<xsd:annotation>
	    <xsd:documentation>
		Possible values for the "for" attribute on &lt;index&gt; hint
		elements in &lt;index_hint&gt;.

		Specifies one of the possible databases supported by XE
		(database targets) or ALL.

		Currently the 'ALL' value must be uppercase, although the database
		types (mysql, mssql, cubrid) are case-insensitive.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:restriction base="xsd:string">
	    <xsd:pattern value="ALL" />
	    <xsd:pattern value="[Cc][Uu][Bb][Rr][Ii][Dd]" />
	    <xsd:pattern value="[Mm][Yy][Ss][Qq][Ll]" />
	    <xsd:pattern value="[Mm][Ss][Ss][Qq][Ll]" />
	</xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="HintTypeAttributeType">
	<xsd:annotation>
	    <xsd:documentation>
		Possible index hint types: IGNORE, USE or FORCE.

		Only mysql makes effective use of hints to IGNORE an index,
		while mssql and CUBRID discard such hints, meaning the index
		might still be used.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:restriction base="xsd:string">
	    <xsd:enumeration value="IGNORE" />
	    <xsd:enumeration value="USE" />
	    <xsd:enumeration value="FORCE" />
	</xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="IndexHintsType">
	<xsd:annotation>
	    <xsd:documentation>
		List of index hints, either for a specific database, or for any database.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:sequence>
	    <xsd:element name="index" type="IndexHintType" maxOccurs="unbounded" />
	</xsd:sequence>

	<xsd:attribute name="for" type="dbTargetAttributeType" use="required" />
    </xsd:complexType>

    <xsd:complexType name="IndexHintType">
	<xsd:annotation>
	    <xsd:documentation>
		Hint to use/not-use a certain index for a certain table in a query or in
		a statement.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:extension base="xsd:anyType">
		<xsd:attribute name="table" type="xsd:string" use="required" />
		<xsd:attribute name="name" type="xsd:string" use="required" />
		<xsd:attribute name="type" type="HintTypeAttributeType" use="required" />
	    </xsd:extension>
	</xsd:complexContent>
    </xsd:complexType>

</xsd:schema>
