Home  Contents

sql:bind

Sql Core4 Lua Commands

SYNOPSIS

  1. query:bind(index, value [, type])
  2. query:bind(name, value [, type])

DESCRIPTION

If a SQL statement contains placeholders, the database engine needs to know which values to put in their place. A placeholder can either be a single question mark ? or a named placeholder with an initial colon, e.g. :name.

To bind values to a question mark, use the first form. The value of index indicates the number of the placeholder in the statement, starting at one. Therefore, the first ? gets number 1, the second ? gets number 2 and so on.

To bind named values, use the second form. The parameter name must contain the name of the placeholder, including the leading colon.

Normally the data type of value is automatically detected. Any numeric value is passed to SQLite as an integer (SQLITE_INTEGER), everything else as text (SQLITE_TEXT). In order to store arbitrary binary data, pass the string "blob" as type. This sets the datatype to SQLITE_BLOB.

RETURN VALUE

On success, returns true. On failure, returns nil. In case of an error, the error can be retrieved by calling sql:lastError() on the parent database handle.

SEE ALSO