Using the Command Line Utility
The DataDirect XQuery command line utility allows you to quickly run and test XQueries through a console window.
To invoke this utility, enter the following command at a prompt from the /lib subdirectory of your DataDirect XQuery installation directory (for example, ddxq/lib):
Alternatively, you can specify the path to the lib directory in the command line, for example:
NOTE: If your XQuery needs to locate classes other than the DataDirect XQuery classes – if you are specifying a custom URI resolver, for example – you must perform one of the following actions:
- Set your CLASSPATH to include the path to the jar files or directories for these classes and invoke the utility using the following command:
java com.ddtek.xquery.Query
NOTE: If you are connecting to PostgreSQL, you must add the PostgreSQL JDBC driver jar file to the CLASSPATH in addition to ddxq.jar. Refer to your PostgreSQL JDBC driver documentation for the name of the jar file.
- Add the class path to the command line:
java -cp c:\myClasses com.ddtek.xquery.Query
See Example 8.
NOTE: If you are connecting to PostgreSQL, you must add the PostgreSQL JDBC driver jar file to the CLASSPATH in addition to ddxq.jar. Refer to your PostgreSQL JDBC driver documentation for the name of the jar file.
The following table lists the options available for the utility.
Table 1-1. Command Line Utility Options Option Description Specifies the CollectionURIResolver class to use. See the NOTE about setting your CLASSPATH for custom URI resolvers. Generates an XQuery execution plan and, optionally, specifies the format of the plan. If a format is not specified, XHTML is generated. Specifies a connection URI. See Relational Data Source Connections.NOTE: On UNIX and Linux, the value for this option must be enclosed with double quotes, for example: Specifies the ModuleURIResolver class to use. See the NOTE about setting your CLASSPATH for custom URI resolvers. Disallows calls to Java methods. Sends results (output) to specified file. Specifies XQuery or JDBC global options. See Using Option Declarations and Extension Expressions for more information. Specifies data source and connection options. See DDXQDataSource and DDXQJDBCConnection Properties for more information. Displays a stack trace in case of an exception. Specifies the URIResolver class to use. See the NOTE about setting your CLASSPATH for custom URI resolvers. Specifies an initial context item in the form of a file name or a URI. Displays version and timing information. Enables automatic updating of sources. Display version information. Displays the help for the command-line utility. Specifies a query string parameter and its value. Specifies a query number parameter and its value. On UNIX and Linux, the value for this option must be enclosed with double quotes, for example:java -jar ddxq.jar q.xq "#i=2"
Specifies a query document parameter and its value. Specifies a serialization option and its value.
Example 1: Executes a Simple XQuery
This example executes the simple query {2+5}.
Example 2: Retrieves Values from an Initial Context Item
This example retrieves all values for UserId from the initial context item users.xml.
Example 3: Retrieves Values and Writes Them to a File
This example retrieves all values for UserId and writes the results to a file named out.xml.
Example 4: Executes an XQuery in a File
This example executes the XQuery contained in the file myXQuery.xq using the initial context item input.xml.
Example 5: Binds a Query Document Parameter
This example executes the XQuery contained in the file myXQuery.xq binding the query document parameter inputDoc to the input.xml document.
Example 6: Binds a Query String Parameter and Sets an Option
This example executes the XQuery contained in the file myXQuery.xq binding the query string parameter param1 to the character string Jonathan and setting the serialization option indent to yes so that results are indented.
Example 7: Accesses a Relational Data Source
This example executes the XQuery contained in the file myXQuery2.xq that accesses a relational data source. See the NOTE about specifying connection URLs.
java -jar ddxq.jar -jdbc "jdbc:xquery:sqlserver://localhost:1433;databaseName=pubs; user=sa" myXQuery2.xqExample 8: Specifies a Document URI
This example retrieves all values for UserId, specifies a document URI, and writes the results to a file named out.xml.