Module dado.sql

Compose SQL statements.

Info:

  • Release: $Id: sql.lua,v 1.39 2017/04/05 19:14:08 tomas Exp $

Functions

escape (s) Escape a character or a character class in a string.
quote (s) Quote a value to be included in an SQL statement.
quotedconcat (tab) Quote all values associated with the integer keys in a table and concat them on a string, separated by a comma (,).
AND (tab) Composes simple (almost trivial) SQL AND-expressions.
isinteger (id) Checks if the argument is an integer.
select (columns, tabname, cond, extra) Builds a string with a SELECT command.
subselect (columns, tabname, cond, extra) Builds a string with a SELECT command to be inserted into another SQL query.
insert (tabname, contents) Builds a string with an INSERT command.
update (tabname, contents, cond) Builds a string with an UPDATE command.
delete (tabname, cond) Builds a string with a DELETE command.


Functions

escape (s)
Escape a character or a character class in a string. It also removes character with codes < 32 (except \t (\9), \n (\10) and \r (\13)).

Parameters:

  • s String to be processed.

Returns:

    String or nil if no string was given.
quote (s)
Quote a value to be included in an SQL statement. The exception is when the string is surrounded by balanced "(())"; in this case it won't be quoted.

Parameters:

  • s String or number or boolean.

Returns:

    String with quoted value.
quotedconcat (tab)
Quote all values associated with the integer keys in a table and concat them on a string, separated by a comma (,). This function is particularly useful to produce expressions for the IN operator.

Parameters:

  • tab Table with the sequence of values.

Returns:

    String in the for of a comma separated values.
AND (tab)
Composes simple (almost trivial) SQL AND-expressions. There is no "magic" in this funcion, except that it 'quotes' the values. Hence, for expressions which have any operator other than '=', you should write them explicitly. There is no OR-expression equivalent function (I don't know how to express it conveniently in Lua).

Parameters:

  • tab Table with key-value pairs representing equalities.

Returns:

    String with the resulting expression.
isinteger (id)
Checks if the argument is an integer. Use this function to check whether a value can be used as a database integer key.

Parameters:

  • id String with the key to check.

Returns:

    Boolean or Number (any number can be considered as true) or nil.
select (columns, tabname, cond, extra)
Builds a string with a SELECT command. The existing arguments will be concatenated together to form the SQL statement. The string "select " is added as a prefix. If the tabname is given, the string " from " is added as a prefix. If the cond is given, the string " where " is added as a prefix.

Parameters:

  • columns String with columns list.
  • tabname String with table name (optional).
  • cond String with where-clause (optional).
  • extra String with extra SQL text (optional).

Returns:

    String with SELECT command.
subselect (columns, tabname, cond, extra)
Builds a string with a SELECT command to be inserted into another SQL query.

Parameters:

  • columns String with columns list.
  • tabname String with table name.
  • cond String with where-clause (and following SQL text).
  • extra String with extra SQL text.

Returns:

    String with SELECT command.
insert (tabname, contents)
Builds a string with an INSERT command.

Parameters:

  • tabname String with table name or with the SQL text that follows the "insert into" prefix.
  • contents Table of elements to be inserted (optional).

Returns:

    String with INSERT command.
update (tabname, contents, cond)
Builds a string with an UPDATE command.

Parameters:

  • tabname String with table name.
  • contents Table of elements to be updated.
  • cond String with where-clause (and following SQL text).

Returns:

    String with UPDATE command.
delete (tabname, cond)
Builds a string with a DELETE command.

Parameters:

  • tabname String with table name.
  • cond String with where-clause (and following SQL text).

Returns:

    String with DELETE command.
generated by LDoc 1.4.6 Last updated 2017-04-05 16:14:10