Forked from orbitaloop/executeSqlBridgeForPhonegapSQLitePlugin.js
Last active
January 4, 2018 15:44
-
-
Save brodybits/1b7a875c9e38f38e642d8efbe3e643ff to your computer and use it in GitHub Desktop.
executeSql Bridge For ORIGINAL @davibe PhonegapSQLitePlugin ONLY (because there are some differences between the WebSQL API and the ORIGINAL @davibe plugin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* to use WebSQL or the SQLite plugin (https://github.com/davibe/Phonegap-SQLitePlugin) with the same function) */ | |
executeSqlBridge: function(tx, sql, params, dataHandler, errorHandler) { | |
var self = this; | |
if (typeof self.db.dbPath !== 'undefined') { | |
//Native SQLite DB with phonegap : https://github.com/davibe/Phonegap-SQLitePlugin/ | |
//this is a native DB, the method signature is different: | |
var sqlAndParams = [sql].concat(params); | |
var cb = function(res) { | |
//in WebSQL : result.rows.item(0) | |
//in the phonegap plugin : res.rows[0] | |
res.rows.item = function(i) { | |
return this[i]; | |
}; | |
//the result callback hasn't the tx param | |
dataHandler(tx, res); | |
}; | |
tx.executeSql(sqlAndParams, cb, errorHandler); | |
} else { | |
//Standard WebSQL | |
tx.executeSql(sql, params, dataHandler, errorHandler); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment