Skip to content

Commit

Permalink
Added changes as per @chbrody pull 24 for Cordova
Browse files Browse the repository at this point in the history
davibe/Phonegap-SQLitePlugin#24

Added changes as per @chbrody
  • Loading branch information
Iain Campion authored and Iain Campion committed Mar 28, 2012
1 parent 76b0256 commit bfe6382
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions build/lawnchair_sqlite_plugin_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
},
Expand Down Expand Up @@ -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];
Expand All @@ -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: []
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}
};
Expand Down
8 changes: 4 additions & 4 deletions build/sqlite_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
};
Expand Down

0 comments on commit bfe6382

Please sign in to comment.