From 67cd416c709db02cf7cfa37d9b212e39c4c59a59 Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Sat, 5 May 2012 21:22:39 +0200 Subject: [PATCH] Original DroidGap version in Simple-DroidGap-test to work on issue #18 --- .../assets/www/SQLitePlugin.js | 342 ++++++++++++++++++ .../plugin/sqlitePlugin/SQLitePlugin.java | 248 +++++++++++++ 2 files changed, 590 insertions(+) create mode 100644 Simple-DroidGap-test/assets/www/SQLitePlugin.js create mode 100644 Simple-DroidGap-test/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java diff --git a/Simple-DroidGap-test/assets/www/SQLitePlugin.js b/Simple-DroidGap-test/assets/www/SQLitePlugin.js new file mode 100644 index 0000000..4ca0f06 --- /dev/null +++ b/Simple-DroidGap-test/assets/www/SQLitePlugin.js @@ -0,0 +1,342 @@ +/* + * PhoneGap is available under *either* the terms of the modified BSD license *or* the + * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. + * + * Copyright (c) 2005-2010, Nitobi Software Inc. + * Copyright (c) 2010-2011, IBM Corporation + */ + +/* + * This is purely for the Android 1.5/1.6 HTML 5 Storage + * I was hoping that Android 2.0 would deprecate this, but given the fact that + * most manufacturers ship with Android 1.5 and do not do OTA Updates, this is required + */ + + +// XXX TODO: use function() { ... } () to encapsulate these declarations (except for Java callback) + +/** + * SQL result set object + * PRIVATE METHOD + * @constructor + */ +var DDB_Rows = function() { + this.resultSet = []; // results array + this.length = 0; // number of rows +}; + +/** + * Get item from SQL result set + * + * @param row The row number to return + * @return The row object + */ +DDB_Rows.prototype.item = function(row) { + return this.resultSet[row]; +}; + +/** + * SQL result set that is returned to user. + * PRIVATE METHOD + * @constructor + */ +var DDB_Result = function() { + this.rows = new DDB_Rows(); +}; + +/** + * Storage object that is called by native code when performing queries. + * PRIVATE METHOD + * @constructor + */ +var DDB = function() { + this.queryQueue = {}; +}; + +/** + * Callback from native code when query is complete. + * PRIVATE METHOD + * + * @param id Query id + */ +DDB.prototype.completeQuery = function(id, data) { + var query = this.queryQueue[id]; + if (query) { + try { + delete this.queryQueue[id]; + + // Get transaction + var tx = query.tx; + + // If transaction hasn't failed + // Note: We ignore all query results if previous query + // in the same transaction failed. + if (tx && tx.queryList[id]) { + + // Save query results + var r = new DDB_Result(); + r.rows.resultSet = data; + r.rows.length = data.length; + try { + if (typeof query.successCallback === 'function') { + query.successCallback(query.tx, r); + } + } catch (ex) { + console.log("executeSql error calling user success callback: "+ex); + } + + tx.queryComplete(id); + } + } catch (e) { + console.log("executeSql error: "+e); + } + } +}; + +/** + * Callback from native code when query fails + * PRIVATE METHOD + * + * @param reason Error message + * @param id Query id + */ +DDB.prototype.fail = function(reason, id) { + var query = this.queryQueue[id]; + if (query) { + try { + delete this.queryQueue[id]; + + // Get transaction + var tx = query.tx; + + // If transaction hasn't failed + // Note: We ignore all query results if previous query + // in the same transaction failed. + if (tx && tx.queryList[id]) { + tx.queryList = {}; + + try { + if (typeof query.errorCallback === 'function') { + query.errorCallback(query.tx, reason); + } + } catch (ex) { + console.log("executeSql error calling user error callback: "+ex); + } + + tx.queryFailed(id, reason); + } + + } catch (e) { + console.log("executeSql error: "+e); + } + } +}; + +var mycreateUUID = function() { + return myUUIDcreatePart(4) + '-' + + myUUIDcreatePart(2) + '-' + + myUUIDcreatePart(2) + '-' + + myUUIDcreatePart(2) + '-' + + myUUIDcreatePart(6); +}; + +myUUIDcreatePart = function(length) { + var uuidpart = ""; + var i, uuidchar; + for (i=0; i