/* * 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 */ /** * 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