Contact: zeng  @      Last update: 10 May 2011

SQLITE Library

The SQLITE has a distinguished feature: it works directly on database files. This makes it very simple to manage SQL database by a stand-alone computer and convenient to distribute database. Although the library includes only a few functions, they are enough to perform nearly all SQL operations supported by SQLITE.

Function Parameter Type Remark
sqlite(filename) string Opens the database file and returns a SQLITE object. If the file does not exist, the function tries to create the file.
.version()   Returns the SQLITE version as string.
.query(str[, flag]) string, boolean
Performs SQL query. Returns true if no error or false otherwise. If the optional flag is set to true, the results will be saved in a double-floating matrix.
.callback(func) string Sets a ZeScript function to handle SQL output. The callback function must handle the first argument as the count of output; the second as the column number of items, and the third as the content string. If the count is 0, the content string is the column names.
.nrow()   Returns the number of rows of the query results.
.ptr()   Returns an array containing the pointer to the matrix that holds the query results, the number of elements in the matrix, and the number of bytes of an element.
.missing()   Returns the missing value used to fill the matrix for missing values.
.error()   Returns the last error message as string.



sql = sqlite("test.sql");

sql.query("create table mytable(first_name, last_name, address);");

// strings must be qouted
sql.query("insert into mytable values(\"Jiye\", \"Zeng\", \"123 ABC street\");");
sql.query("insert into mytable values(\"Georgy\", \"Bush\", \"123 USA street\");");

// numbers can be inserted directly
sql.query("insert into mytable values(123, 456, \"numerical street\");");

// output to diaplay by default
sql.query("select * from mytable;");

// control output by callback function
sql.query("select * from mytable;");

function callback(row, col, val)
csv(row, col, val);