object-layer / cordova-sqlite-plugin

Cordova SQLite plugin with a straightforward low-level API
Other
5 stars 15 forks source link

android BUG #1

Closed mamingxuan closed 8 years ago

mamingxuan commented 8 years ago
platforms/android/platform_www/plugins/cordova-sqlite-plugin/www/sqlite.js

replace

LINE 28
var query = {
    qid: 1111,
    sql: sql,
    params: values
};

LINE 51
exec(success, error, 'SQLitePlugin', 'backgroundExecuteSql', [{

with

LINE 28
var query = []
query.push({
    qid: 1111,
    sql: sql,
    params: values
});

LINE 51
exec(success, error, 'SQLitePlugin', 'backgroundExecuteSqlBatch', [{

error is

PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION);
mvila commented 8 years ago

Thanks @mamingxuan for your feedback! Actually, I tested this plugin only on iOS so it is great that you want to use it on Android. I replaced backgroundExecuteSql with backgroundExecuteSqlBatch and made some other adjustments to extract the result correctly and make it works on iOS.

Since I don't currently have an Android dev environment set up, could you test the last version of the plugin please? If you run the example app, you should be able to see the following result: {"rows":[{"solution":5}],"affectedRows":0}.

mamingxuan commented 8 years ago

Hello,@mvila. At first, I found that your plugin could not run at Android dev. Fortunately, I have fixed the error. After fixing it, the plugin is able to run on Android now. The following codes will help you understand more clearly.

src/android/io/liteglue/SQLitePlugin.java from line 137-155

JSONArray txargs = allargs.getJSONArray("executes");

                if (txargs.isNull(0)) {
                    queries = new String[0];
                } else {
                    int len = txargs.length();
                    queries = new String[len];
                    queryIDs = new String[len];
                    jsonparams = new JSONArray[len];

                    for (int i = 0; i < len; i++) {
                        JSONObject a = txargs.getJSONObject(i);
                        queries[i] = a.getString("sql");
                        queryIDs[i] = a.getString("qid");
                        jsonArr = a.getJSONArray("params");
                        paramLen = jsonArr.length();
                        jsonparams[i] = jsonArr;
                    }
                }

Absolutely, "executes" is an array, not an object.

mvila commented 8 years ago

So, everything is good now?

mamingxuan commented 8 years ago

Yes, everything is OK

mvila commented 8 years ago

OK @mamingxuan, thanks for your help.