mod_sql: integrating SQL into XML

mod_sql is a provider for the Apache XML Namespace API that harness the Apache DBD Framework to enable SQL queries (and results) to be embedded into XML applications via a namespace. It will typically be used together with mod_form or similar processor to provide a complete and ultra-fast environment for Forms handling with an SQL backend.

mod_sql in context

APIs used by mod_sql

The SQL Namespace

mod_sql implements a namespace for accessing databases from an HTML or XML page. This relies on mod_publisher or mod_xmlns, and requires at least one database driver.

The namespace http://apache.webthing.com/sql# implements the following elements. Most of the complex attributes such as (format, errfmt, query), can be Environment variables (e.g. set in httpd.conf or an SSI set directive), or can be Form variables if mod_form is available. Documentation to follow.

mod_sql is currently experimental. Use at your own risk, and please report problems/bugs.

<sql:dbd driver="foo" version="bar" errmsg="connection to foo failed" dbname="somedb" output="html">
Initialises a connection using driver / version. Selects dbname if the driver supports set_dbname, and sets a format for any output generated. If the operation fails, it logs an error, and returns the errmsg to the client if and only if one is set. The lifetime of the connection is until the closing </sql:dbd>.
<sql:error format="<p>Error from foo: %s</p>"/>
Sets a format string for reporting errors to the browser. If the format is null/unset, errors will be logged but not reported to the browser.
<sql:query query="some SQL statement" errfmt="foobar" />
Executes an SQL statement that doesn't return data (eg INSERT, UPDATE). errfmt if supplied overrides the current <sql:error ... > setting.
<sql:results ....>
Prints a container for the results of a select, depending on the output attribute to sql:dtd. Attributes depend on the output; currently only HTML is supported and this is a no-op for other types.
<sql:select query="some SQL statement" format="<tr><td>%0;</td><td>%2;</td></tr>" errfmt="some other errfmt: %s" />
Executes an SQL statement that returns data (eg SELECT) and prints the results by row using the format string supplied. errfmt if supplied overrides the current <sql:error ... > setting.
<sql:transaction>
Starts an SQL transaction. The transaction maintains state, and when the sql:transaction is closed, it will either be committed or rolled back, depending on whether an error occurred within the transaction. If a driver doesn't support transactions, this is a no-op.

The above API is expected to grow in due course to support more advanced database usage.

Availability

mod_sql.c is available under the GNU General Public License (GPL). As with other opensource modules, we can consider alternative licenses by request.