Module "sql"
============

The base module for accessing SQL databases.

Additional database driver modules need to be loaded for the backend
databases.
 
builtin encode_sql(text);
-------------------------

This function encodes a string to be used in an SQL query. I.e. the string
will be put in single quotes and every single quote in it will be replaced
with two single quotes.

This function is designed to be used with the encoding/quoting operator (::).
 

builtin sql_connect(driver_name, driver_data);
----------------------------------------------

This function creates an SQL database handle.

The backend driver for the database must be loaded already when this
function is called. E.g.:

	load "sql_sqlite";
	var db = sql_connect("sqlite", "");

The database handler returned by this function may then be used as first
argument for the sql() function.

An SqlEx exception is thrown on errors.
 

builtin sql(database_handler, query);
-------------------------------------

This function executes an SQL query.

If the query returns data, it is passed back using the return value of this
function.

The database handler must be created using sql_connect().

The return value is an array with an element for every database tuple in the
result set. Those elements then have a named children for each field in the
tuple, with the field name returned from the database as key. E.g.:

	var db = sql_connect("sqlite", "/var/lib/myapp/database.db");

	var r = sql(db, "SELECT username, userid FROM users");

	foreach i (r)
		debug "User '${r[i].username}' has ID '${r[i].userid}'.";

An SqlEx exception is thrown on errors.
 

object SqlEx
------------

An instance of this object is thrown on database errors.
 

var SqlEx.description;
~~~~~~~~~~~~~~~~~~~~~~

A description text describing the error.
Some backend drivers might add additional object members.
 
