NullLogic

This script demonstrates the basics of how to work with an SQLite database.

function sql_tests(db) { db.open(); db.query("CREATE TABLE test_table ( id integer, col1 varchar(8), col2 varchar(8) );", false); printf("db.changes = %d;\r\n", db.changes); db.begin(); db.query(sprintf("INSERT INTO test_table (id, col1, col2) VALUES (1, 'a', '%s');", db.escape("abc")), false); printf("db.changes = %d;\r\n", db.changes); db.query(sprintf("INSERT INTO test_table (id, col1, col2) VALUES (2, 'b', '%s');", db.escape("a'b'c")), false); printf("db.changes = %d;\r\n", db.changes); db.query(sprintf("INSERT INTO test_table (id, col1, col2) VALUES (3, 'c', '%s');", db.escape('a"b"c')), false); printf("db.changes = %d;\r\n", db.changes); db.commit(); //db.rollback(); db.query("SELECT * FROM test_table;"); printf("db.last_query = \"%s\";\r\n", db.last_query); while ((row=db.getnext())!=null) { printf("row = %s;\r\n", serialize(row).replace('\r', '').replace('\n', ' ').replace('\t', '')); } db.endquery(); printf("db.changes = %d;\r\n", db.changes); db.close(); }; function sqlite() { ci = { database="/tmp/nstest.db" }; file.unlink(ci.database); try { dl.load("data"); dl.load("sqlite"); db=new data.sqlite.client(ci); sql_tests(db); } catch (ex) { printf("Exception: %s\r\n", ex.description); } file.unlink(ci.database); }; sqlite();