Contact: zeng  @      Last update: 20 January 2010

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 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) string Performs SQL query. Returns true if no error or false otherwise.
.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.
.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);