diff --git a/README.md b/README.md index 7a3c3ce..d16dc9f 100644 --- a/README.md +++ b/README.md @@ -79,22 +79,23 @@ General Usage ## Plain Javascript - var db; - db = new SQLitePlugin("test_native.sqlite3"); - db.executeSql('DROP TABLE IF EXISTS test_table'); - db.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)'); - db.transaction(function(tx) { - return tx.executeSql(["INSERT INTO test_table (data, data_num) VALUES (?,?)", "test", 100], function(res) { - console.log("insertId: " + res.insertId + " -- probably 1"); - console.log("rowsAffected: " + res.rowsAffected + " -- should be 1"); - return db.executeSql("select count(id) as cnt from test_table;", function(res) { - console.log("rows.length: " + res.rows.length + " -- should be 1"); - return console.log("rows[0].cnt: " + res.rows[0].cnt + " -- should be 1"); - }); - }, function(e) { - return console.log("ERROR: " + e.message); - }); - }); + var db; + db = new SQLitePlugin("my_sqlite_database.sqlite3"); + + db.executeSql('DROP TABLE IF EXISTS test_table'); + db.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)'); + db.transaction(function(tx) { + return tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)",[ "test", 100], function(res) { + console.log("insertId: " + res.insertId + " -- probably 1"); + console.log("rowsAffected: " + res.rowsAffected + " -- should be 1"); + return db.executeSql("select count(id) as cnt from test_table;", [], function(res) { + console.log("rows.length: " + res.rows.length + " -- should be 1"); + return console.log("rows[0].cnt: " + res.rows[0].cnt + " -- should be 1"); + }); + }, function(e) { + return console.log("ERROR: " + e.message); + }); + }); Lawnchair Adapter Usage diff --git a/build/lawnchair_sqlite_plugin_adapter.js b/build/lawnchair_sqlite_plugin_adapter.js index 38bfca8..c1640f8 100644 --- a/build/lawnchair_sqlite_plugin_adapter.js +++ b/build/lawnchair_sqlite_plugin_adapter.js @@ -32,7 +32,7 @@ }; db = options.db || this.name; this.db = new SQLitePlugin("" + db + ".sqlite3"); - this.db.executeSql(sql, success, fail); + this.db.executeSql(sql, [], success, fail); }, keys: function(callback) { var cb, sql, success, that; @@ -42,7 +42,7 @@ success = function(res) { cb.call(that, res.rows); }; - this.db.executeSql(sql, success, fail); + this.db.executeSql(sql, [], success, fail); return this; }, save: function(obj, callback) { @@ -62,7 +62,7 @@ delete obj.key; val.unshift(JSON.stringify(obj)); sql = exists ? up : ins; - db.executeSql([sql].concat(val), success, fail); + db.executeSql(sql, val, success, fail); }); return this; }, @@ -117,7 +117,7 @@ sql = obj.key in ids_hash ? up : ins; delete obj.key; val.unshift(JSON.stringify(obj)); - t.executeSql([sql].concat(val), success, fail); + t.executeSql(sql, val, success, fail); }; for (_k = 0, _len3 = objs.length; _k < _len3; _k++) { obj = objs[_k]; @@ -132,7 +132,7 @@ }; if (keys.length > 0) { exists_sql = ["SELECT id FROM " + this.name + " WHERE id IN (" + marks + ")"].concat(keys); - db.executeSql(exists_sql, exists_success); + db.executeSql(exists_sql, [], exists_success); } else { exists_success({ rows: [] @@ -180,7 +180,7 @@ if (!is_array) r = r[0]; if (cb) that.lambda(cb).call(that, r); }; - this.db.executeSql(sql, success, fail); + this.db.executeSql(sql, [], success, fail); return this; }, exists: function(key, cb) { @@ -190,7 +190,7 @@ success = function(res) { if (cb) that.fn("exists", cb).call(that, res.rows.length > 0); }; - this.db.executeSql(sql, success, fail); + this.db.executeSql(sql, [], success, fail); return this; }, all: function(callback) { @@ -218,7 +218,7 @@ })(); cb.call(that, r); }; - this.db.executeSql(sql, success, fail); + this.db.executeSql(sql, [], success, fail); return this; }, remove: function(keyOrObj, cb) { @@ -231,7 +231,7 @@ success = function() { if (cb) that.lambda(cb).call(that); }; - this.db.executeSql(sql, success, fail); + this.db.executeSql(sql, [], success, fail); return this; }, nuke: function(cb) { @@ -243,7 +243,7 @@ if (cb) that.lambda(cb).call(that); db.executeSql("VACUUM"); }; - this.db.executeSql(sql, success, fail); + this.db.executeSql(sql, [], success, fail); return this; } }; diff --git a/build/sqlite_plugin.js b/build/sqlite_plugin.js index 1a8a379..d7c741b 100644 --- a/build/sqlite_plugin.js +++ b/build/sqlite_plugin.js @@ -53,13 +53,13 @@ var SQLitePlugin = function() { callbacks[ref] = null; delete callbacks[ref]; }; - SQLitePlugin.prototype.executeSql = function(sql, success, error) { + SQLitePlugin.prototype.executeSql = function(sql, params, success, error) { var opts; if (!sql) { throw new Error("Cannot executeSql without a query"); } opts = getOptions({ - query: [].concat(sql || []), + query: [sql].concat(params || []), path: this.dbPath }, success, error); Cordova.exec("SQLitePlugin.backgroundExecuteSql", opts); @@ -97,9 +97,9 @@ var SQLitePlugin = function() { this.dbPath = dbPath; this.executes = []; } - SQLitePluginTransaction.prototype.executeSql = function(sql, success, error) { + SQLitePluginTransaction.prototype.executeSql = function(sql, params, success, error) { this.executes.push(getOptions({ - query: [].concat(sql || []), + query: [sql].concat(params || []), path: this.dbPath }, success, error)); };