Skip to content

Commit

Permalink
Report an error upon attempt to close database multiple times.
Browse files Browse the repository at this point in the history
Discovered this while working on a solution for #184 & #209.

Minor cleanup of comments.
  • Loading branch information
Chris Brody committed Mar 17, 2015
1 parent 0ddc599 commit 2e31d46
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
31 changes: 12 additions & 19 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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'
Expand All @@ -163,6 +161,9 @@

cordova.exec success, error, "SQLitePlugin", "close", [ { path: @dbname } ]

else
nextTick -> error()

return

SQLitePlugin::executeSql = (statement, params, success, error) ->
Expand All @@ -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"
###
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -254,7 +250,6 @@
qid: qid

sql: sql
#params: values || []
params: params

return
Expand Down Expand Up @@ -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()
Expand Down
24 changes: 24 additions & 0 deletions test-www/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
19 changes: 4 additions & 15 deletions www/SQLitePlugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e31d46

Please sign in to comment.