NullLogic

This script demonstrates the basics of how to work with a Firebird SQL 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 fbsql() { ci = { host="localhost", port=3050, username="SYSDBA", password="masterkey", database="/tmp/nstest.fdb" }; file.unlink(ci.database); file.writeall("/tmp/nstest.sql", sprintf("SET SQL DIALECT 3;\r\nCREATE DATABASE '%s'\r\nUSER '%s' PASSWORD '%s'\r\nPAGE_SIZE 16384;\r\n", ci.database, ci.username, ci.password)); system("isql-fb -input /tmp/nstest.sql 2> /dev/null"); file.unlink("/tmp/nstest.sql"); try { dl.load("data"); dl.load("fbsql"); db=new data.fbsql.client(ci); sql_tests(db); } catch (ex) { printf("Exception: %s\r\n", ex.description); } file.unlink(ci.database); return; }; fbsql();