davibe/Phonegap-SQLitePlugin

The plugin API is not the same as the HTML5 WebSQL API

orbitaloop opened this issue · 4 comments

It could be great to have the same API, in order to be able to use the app in a WebKit navigator.
Waiting for that, I wrote an adapter :

    _executeSqlBridge: function(tx, sql, params, dataHandler, errorHandler) {
    var self = this;
    if (typeof self.db.dbPath !== 'undefined') {
        //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);
    }
},

Here is an info, Introducing Web SQL Databases

http://html5doctor.com/introducing-web-sql-databases/

I think this is useful for us who is trying to use this plugin.

I am going to use PhoneGap again because this plugin (I am using QuickConnect with Sqlite/Spatialite).

Yes it would be nice if the db object returned by new PGSQLitePlugin(db_name) would follow almost the same API as the HTML5 WebSQL API. Nice link from @ns-1m!

I just issued pull request #24 to propose a change to the API. I think it should wait for the Cordova version.

Please take a look at https://github.com/chbrody/Cordova-SQLitePlugin/ I have made both an Android (DroidGap) version and made a number of API improvements. For example, instead of new SQLitePlugin() use sqlitePlugin.openDatabase() (both iOS and Android versions). There is a common Lawnchair adapter for both Android and iOS versions, along with a working Lawnchair test suite. I want to do some cleanups and then issue an official pull request.