diff --git a/SQLitePlugin.coffee.md b/SQLitePlugin.coffee.md index 5dbe3cb51..cec9d100d 100644 --- a/SQLitePlugin.coffee.md +++ b/SQLitePlugin.coffee.md @@ -1,10 +1,10 @@ -# SQLitePlugin in Markdown (litcoffee) +# SQLite plugin in Markdown (litcoffee) #### Use coffee compiler to compile this directly into Javascript #### License for common script: MIT or Apache -# Top-level SQLitePlugin objects +# Top-level SQLite plugin objects ## root window object: @@ -63,12 +63,12 @@ else return fun.call this, [] -## SQLitePlugin db-connection +## SQLite plugin db-connection handle -#### SQLitePlugin object is defined by a constructor function and prototype member functions: +#### SQLite plugin db connection handle object is defined by a constructor function and prototype member functions: SQLitePlugin = (openargs, openSuccess, openError) -> - console.log "SQLitePlugin openargs: #{JSON.stringify openargs}" + # console.log "SQLitePlugin openargs: #{JSON.stringify openargs}" if !(openargs and openargs['name']) throw newSQLError "Cannot create a SQLitePlugin db instance without a db name" @@ -152,8 +152,6 @@ return SQLitePlugin::close = (success, error) -> - #console.log "SQLitePlugin.prototype.close" - if @dbname of @openDBs if txLocks[@dbname] && txLocks[@dbname].inProgress error newSQLError 'database cannot be closed while a transaction is in progress' @@ -163,6 +161,9 @@ cordova.exec success, error, "SQLitePlugin", "close", [ { path: @dbname } ] + else + nextTick -> error() + return SQLitePlugin::executeSql = (statement, params, success, error) -> @@ -176,11 +177,8 @@ @addTransaction new SQLitePluginTransaction(this, myfn, null, null, false, false) return -## SQLitePluginTransaction object for batching: +## SQLite plugin transaction object for batching: - ### - Transaction batching object: - ### SQLitePluginTransaction = (db, fn, error, success, txlock, readOnly) -> if typeof(fn) != "function" ### @@ -210,9 +208,7 @@ @fn this @run() catch err - ### - If "fn" throws, we must report the whole transaction as failed. - ### + # If "fn" throws, we must report the whole transaction as failed. txLocks[@db.dbname].inProgress = false @db.startNextTransaction() if @error @@ -254,7 +250,6 @@ qid: qid sql: sql - #params: values || [] params: params return @@ -309,10 +304,8 @@ if txFailure tx.abort txFailure else if tx.executes.length > 0 - ### - new requests have been issued by the callback - handlers, so run another batch. - ### + # new requests have been issued by the callback + # handlers, so run another batch. tx.run() else tx.finish() diff --git a/test-www/www/index.html b/test-www/www/index.html index e61c7b8a6..b3a866285 100755 --- a/test-www/www/index.html +++ b/test-www/www/index.html @@ -1672,6 +1672,30 @@ }); }); + if (!isWebSql) test (suiteName + ' attempt db.close() twice', function () { + var dbName = "Database-close-twice.db"; + + stop(1); + + openDatabase({name: dbName}, function(db) { + ok(!!db, 'valid db object'); + db.close(function () { + ok(true, 'db.close() success callback (first time)'); + //start(1); + db.close(function () { + ok(false, 'db.close() second time should not have succeeded'); + start(1); + }, function (error) { + ok(true, 'db.close() second time reported error ok'); + start(1); + }); + }, function (error) { + ok(false, 'expected close error callback not to be called after database is closed'); + start(1); + }); + }); + }); + // XXX TODO same db name, different location [BROKEN] if (!isWebSql) test(suiteName + ' open same database twice [same location] works', function () { diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index b851f7ef2..6450634c3 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -60,7 +60,6 @@ SQLitePlugin = function(openargs, openSuccess, openError) { var dbname; - console.log("SQLitePlugin openargs: " + (JSON.stringify(openargs))); if (!(openargs && openargs['name'])) { throw newSQLError("Cannot create a SQLitePlugin db instance without a db name"); } @@ -159,6 +158,10 @@ path: this.dbname } ]); + } else { + nextTick(function() { + return error(); + }); } }; @@ -180,11 +183,6 @@ this.addTransaction(new SQLitePluginTransaction(this, myfn, null, null, false, false)); }; - - /* - Transaction batching object: - */ - SQLitePluginTransaction = function(db, fn, error, success, txlock, readOnly) { if (typeof fn !== "function") { @@ -217,10 +215,6 @@ this.run(); } catch (_error) { err = _error; - - /* - If "fn" throws, we must report the whole transaction as failed. - */ txLocks[this.db.dbname].inProgress = false; this.db.startNextTransaction(); if (this.error) { @@ -321,11 +315,6 @@ if (txFailure) { tx.abort(txFailure); } else if (tx.executes.length > 0) { - - /* - new requests have been issued by the callback - handlers, so run another batch. - */ tx.run(); } else { tx.finish();