Browse files

Better conformance to HTML5 for transaction()

  • Loading branch information...
1 parent 0b8aece commit e2cdbf1ec74576f3a3dd88149050871a66b1d8f4 @grumdrig committed with Eric Fredricksen Dec 7, 2009
Showing with 21 additions and 4 deletions.
  1. +4 −2 sqlite.js
  2. +17 −2 test.js
View
6 sqlite.js
@@ -57,8 +57,10 @@ DatabaseSync.prototype.query = function (sql, bindings, callback) {
function SQLTransactionSync(db, txCallback, errCallback, successCallback) {
this.database = db;
this.executeSql = function(sqlStatement, arguments, callback) {
- // TODO: Somehow SQL errors are being eaten
- return db.query(sqlStatement, arguments, callback)[0];
+ var result = db.query(sqlStatement, arguments, callback)[0];
+ result.rows = {item: function (index) { return result[index]; },
+ length: result.length};
+ return result;
}
db.query("BEGIN TRANSACTION");
View
19 test.js
@@ -6,6 +6,14 @@ var sqlite = require("./sqlite");
posix.unlink('test.db');
+function asserteq(v1, v2) {
+ if (v1 != v2) {
+ sys.puts(sys.inspect(v1));
+ sys.puts(sys.inspect(v2));
+ }
+ process.assert(v1 == v2);
+}
+
var db = sqlite.openDatabaseSync('test.db');
db.query("CREATE TABLE egg (a,y,e)");
@@ -37,13 +45,20 @@ db.query("SELECT e FROM egg WHERE a = ?", [5], function (rows) {
});
+
db.transaction(function(tx) {
tx.executeSql("CREATE TABLE tex (t,e,x)");
- tx.executeSql("INSERT INTO tex (t,e,x) VALUES (?,?,?)", ["this","is","SQL"]);
+ var i = tx.executeSql("INSERT INTO tex (t,e,x) VALUES (?,?,?)",
+ ["this","is","Sparta"]);
+ asserteq(i.rowsAffected, 1);
+ var s = tx.executeSql("SELECT * FROM tex");
+ asserteq(s.rows.length, 1);
+ asserteq(s.rows.item(0).t, "this");
+ asserteq(s.rows.item(0).e, "is");
+ asserteq(s.rows.item(0).x, "Sparta");
});
-
db.query("CREATE TABLE test (x,y,z)", function () {
db.query("INSERT INTO test (x,y) VALUES (?,?)", [5,10]);
db.query("INSERT INTO test (x,y,z) VALUES ($x, $y, $z)", {$x:1, $y:2, $z:3});

0 comments on commit e2cdbf1

Please sign in to comment.