Cocoon Documentation
The SQL logicsheet is deprecated and no longer supported, and it is recommended that you use the ESQL logicsheet instead. This documentation is provided for those who are still using the SQL logicsheet.
The SQL logicsheet is an XSP logicsheet that performs sql queries and serializes their results as XML. This allows you to work with data from a wide variety of different sources when using Cocoon.
Check your cocoon.properties for this line and add it if it's not already there:
processor.xsp.logicsheet.sql.java = resource://org/apache/cocoon/processor/xsp/library/sql/sql.xsl
Note the line break is for formatting purposes, it should not appear in your cocoon.properties file.
If you are going to use connection pools, then make sure that you have followed the installation steps for the connection pools.
Map the
http://www.apache.org/1999/SQL
namespace to the sql prefix. Elements in the sql taglib namespace will be interpreted as input to the sql taglib and will be stripped from the output.
This is typically done like this:
<xsp:page language="java" xmlns:sql="http://www.apache.org/1999/SQL" xmlns:xsp="http://www.apache.org/1999/XSP/Core" > . . . </xsp:page>
The only element in the sql taglib namespace that may appear as a descendent of an element in another namespace is the execute-query
element. It indicates that a sql query should be executed. The result XML will replace this element.
The execute-query
element will contain child elements in the sql taglib namespace which specify parameters for the query. It is an error if it contains children (not necessarily descendents) in another namespace. No other element in the sql taglib namespace may contain children in the sql taglib namespace.
The list of valid sql taglib configuration elements is:
Note that the query element may contain elements from other XSP-enabled namespaces, like request or session. The others may not right now, though I'm certainly willing to consider changing that if desired. I'm still new at this XSP thing too.
Let's step through an example of using a connection defined to be "helpdesk" that uses oracle. In the cocoon.properties have something simular to this:
#### ORACLE processor.xsp.pool.database.helpdesk.driver=oracle.jdbc.driver.OracleDriver processor.xsp.pool.database.helpdesk.url=jdbc:oracle:thin:@localhost:1521:dldf processor.xsp.pool.database.helpdesk.username=dnUser processor.xsp.pool.database.helpdesk.password=dbPass # The number of database connections to cache in the ConnectionPool. processor.xsp.pool.database.helpdesk.maxConnections=3
then in my xml file, I would use the connection pool name "helpdesk" as:
<sql:execute-query> <sql:use-connection>helpdesk</sql:use-connection> <sql:skip-rows>0</sql:skip-rows> <sql:max-rows>50</sql:max-rows> <sql:null-indicator>y</sql:null-indicator> <sql:count-attribute>BOB</sql:count-attribute> <sql:doc-element>ROWSET</sql:doc-element> <sql:row-element>ROW</sql:row-element> <sql:tag-case>preserve</sql:tag-case> <sql:id-attribute>ID</sql:id-attribute> <sql:query> SELECT last_name, first_name, initials FROM EMPLOYEE </sql:query> </sql:execute-query>
Notice that for the connection pool, you do not use the driver, dburl, username, nor password tags. Lets look at an example that does not use the connection pool:
<sql:execute-query> <sql:driver>com.informix.jdbc.IfxDriver</sql:driver> <sql:dburl>jdbc:informix-sqli://localhost:1526/database:informixserver=server</sql:dburl> <sql:username>dbUser</sql:username> <sql:password>dbPass</sql:password> <sql:skip-rows>0</sql:skip-rows> <sql:max-rows>50</sql:max-rows> <sql:tag-case>preserve</sql:tag-case> <sql:count-attribute>count</sql:count-attribute> <sql:doc-element>ROWSET</sql:doc-element> <sql:row-element>ROW</sql:row-element> <sql:null-indicator>omit</sql:null-indicator> <sql:id-attribute>ID</sql:id-attribute> <sql:query>SELECT * FROM CUSTOMER;</sql:query> </sql:execute-query>
The SQL logicsheet will try to name the column elements with the names of the columns from the queries, applying case styling as indicated by the sql:tag-case element. You must ensure that those column names are valid XML element names - e.g. no spaces or strange characters. For instance, MAX(*) is forbidden. You must alias these columns with the AS command - MAX(*) AS THEMAX.
Generally, column values are formatted naively - the taglib requests an Object from the ResultSet and invoked the toString() method. Some columns return byte or character arrays - in that case, we construct a new String using the array as a construction argument.
These defaults may be overridden by supplying one or more sql:column-format elements. Each sql:column-format element may contain these child elements:
For each sql:column-format element, a new instance of the Format subclass specified by the sql:class element is constructed using the construction parameters specified by the sql:parameter elements. The constructor must accept only Strings as parameters; if other datatypes are required for a class you wish to use, you must provide your own decorator wrapper for that class. Values from the named column are formatting using the format method. Here is an example:
<sql:column-format> <sql:name>my_date</sql:name> <sql:class>java.text.SimpleDateFormat</sql:class> <sql:parameter>MM/dd/yyyy</sql:parameter> </sql:column-format>
Copyright © 1999-2001 The Apache Software Foundation.
All rights reserved.