Home Contents | # Introduction | Sql | Core4 Lua Commands

## DESCRIPTION

The Core4 Lua implementation provides support for SQLite3 databases.

To open a database file, use sql.open(). The returned handle can be used directly to run SQL statements on it.

To work with multiple statements on the same database, e.g. for copying data between tables, further query handles may be obtained on that database with sql:newquery().

A lightweight settings API for storing key/value pairs is provided by calling sql:setValue() and sql:getValue().

## USAGE

Simple SQL statements that don't need any additional values are executed by calling sql:exec(…).

SQL statements that need external values must be prepared with sql:prepare(), followed by zero or more sql:bind() calls. Finally, a prepared statement is executed with a plain sql:exec() with no arguments.

To run the same SQL statement again, a query can be "rewound" by calling sql:reset(). After a successful reset, the query can be executed again. If necessary, new values can be attached with new calls to sql:bind() before the query is repeated. Repeating a query in that way saves the time needed to parse the SQL statement.

Results of a SELECT statement are retrieved by repeatedly calling sql:next() until it returns false. Each call will make the next row of the result set available. The values are retrieved with sql:value().

## NOTES

Due to lack of a hardware floating point unit, the floating point support has been disabled in the SQLite library.

The following SQLite features have been omitted:

- OMIT_LOAD_EXTENSION
- OMIT_FLOATING_POINT
- OMIT_DEPRECATED
- OMIT_AUTHORIZATION
- OMIT_EXPLAIN
- OMIT_AUTOINIT
- OMIT_BUILTIN_TEST
- OMIT_AUTOVACUUM
- OMIT_TRACE
- OMIT_SHARED_CACHE
- OMIT_TCL_VARIABLE

SQLite3 has no API calls that provides the number of rows returned to a SELECT statement. The only way to get that number is by iterating over the result set.

## SEE ALSO

SQLite Homepage, Introduction to SQL