Skip to content
Browse files

Tweak Database#execute binding

  • Loading branch information...
1 parent 569ffde commit 4811a4145c62bcfa39715b9c7d7cd23a4b66d2a5 @orlandov committed Sep 29, 2010
Showing with 12 additions and 8 deletions.
  1. +12 −8 sqlite.js
View
20 sqlite.js
@@ -101,20 +101,24 @@ Database.prototype.execute = function (sql /* , bindings, callback */) {
}
self.prepare(sql, function (error, statement) {
+ function next (error) {
+ if (error) return callback(new Error("Error binding: " + error.toString()));
+ fetchAll(statement);
+ }
+
if (error) {
return callback(error);
}
if (bindings) {
- statement.bind(bindings, function (error) {
- if (error) {
- return callback(
- new Error("Binding error: " + error.toString()));
- }
- fetchAll(statement);
- });
+ if (Array.isArray(bindings)) {
+ statement.bindArray(bindings, next);
+ }
+ else if (typeof(bindings) === 'object') {
+ statement.bindObject(bindings, next);
+ }
}
else {
- fetchAll(statement);
+ next();
}
function fetchAll(statement) {

0 comments on commit 4811a41

Please sign in to comment.
Something went wrong with that request. Please try again.