File dado/init.lua

Dado is a set of facilities implemented over LuaSQL connection objects. This module's goal is to simplify the most used database operations.

Release: $Id: init.lua,v 1.5 2008/04/20 21:27:42 tomas Exp $

Functions

assertexec (self, stmt) Executes a SQL statement raising an error if something goes wrong.
close (self) Closes the connection and invalidates the object.
commit (self) Commits the current transaction.
connect (dbname, dbuser, dbpass, driver, ...) Tries to use a connection in the cache or opens a new one.
delete (self, tabname, cond) Deletes a row.
insert (self, tabname, contents) Inserts a new row.
nextval (self, seq, field) Obtains next value from a sequence.
rollback (self) Rolls back the current transaction.
select (self, columns, tabname, cond, extra, mode) Retrieves rows.
selectall (self, columns, tabname, cond, extra) Retrieves all rows.
setautocommit (self, bool) Turn autocommit mode on or off.
update (self, tabname, contents, cond) Updates existing rows.


Functions

assertexec (self, stmt)
Executes a SQL statement raising an error if something goes wrong.

Parameters

  • self:
  • stmt: String with SQL statement.

Return value:

Cursor or number of rows affected by the command (it never returns nil,errmsg).
close (self)
Closes the connection and invalidates the object.

Parameters

  • self:
commit (self)
Commits the current transaction.

Parameters

  • self:
connect (dbname, dbuser, dbpass, driver, ...)
Tries to use a connection in the cache or opens a new one.

Parameters

  • dbname: String with database name.
  • dbuser: String with database username (optional).
  • dbpass: String with database user password (optional).
  • driver: String with LuaSQL's driver (default = "postgres").
  • ...:

Return value:

Connection.
delete (self, tabname, cond)
Deletes a row.

Parameters

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

Return value:

Number of rows affected.

See also:

insert (self, tabname, contents)
Inserts a new row.

Parameters

  • self:
  • tabname: String with table name.
  • contents: Table with field-value pairs.

Return value:

Number of rows affected.

See also:

nextval (self, seq, field)
Obtains next value from a sequence.

Parameters

  • self:
  • seq: String with sequence name.
  • field: String (optional) with the name of the field associated with the sequence.

Return value:

String with next sequence value.
rollback (self)
Rolls back the current transaction.

Parameters

  • self:
select (self, columns, tabname, cond, extra, mode)
Retrieves rows. Creates an iterator over the result of a query. This iterator could be used in for-loops.

Parameters

  • self:
  • columns: String with fields list.
  • tabname: String with table name.
  • cond: String with where-clause (and following SQL text).
  • extra: String with extra SQL text (to be used when there is no where-clause).
  • mode: String indicating fetch mode (this argument also indicates whether the function should return a table or the values directly).

Return value:

Iterator over the result set.

See also:

selectall (self, columns, tabname, cond, extra)
Retrieves all rows.

Parameters

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

Return value:

Table with the entire result set.

See also:

setautocommit (self, bool)
Turn autocommit mode on or off.

Parameters

  • self:
  • bool:
update (self, tabname, contents, cond)
Updates existing rows.

Parameters

  • self:
  • tabname: String with table name.
  • contents: Table with field-value pairs.
  • cond: String with where-clause (and following SQL text).

Return value:

Number of rows affected.

See also:

Valid XHTML 1.0!