Commit 38af2eda by Orlando Vazquez

Add an insertMany method

parent 4811a414
...@@ -169,3 +169,54 @@ Database.prototype.executeScript = function (script, callback) { ...@@ -169,3 +169,54 @@ Database.prototype.executeScript = function (script, callback) {
}); });
})(script); })(script);
} }
Database.prototype.insertMany = function (table, columns, rows, callback) {
var columnsFragment = columns.join(",");
var placeholdersFragment = [];
var i = columns.length;
while (i--) {
placeholdersFragment.push('?');
}
placeholdersFragment = placeholdersFragment.join(", ");
var sql = [ 'INSERT INTO'
, table
, '('
, columnsFragment
, ')'
, 'VALUES'
, '('
, placeholdersFragment
, ')'
]
.join(" ");
var i = rows.length;
var statement;
function doStep(i) {
statement.bindArray(rows[i], function () {
statement.step(function (error, row) {
if (error) return callback(error);
statement.reset();
if (i) {
doStep(--i);
}
else {
statement.finalize(function () {
callback();
});
}
});
});
}
this.prepare(sql, function (error, stmt) {
if (error) return callback(error);
statement = stmt;
doStep(--i);
});
}
...@@ -668,6 +668,7 @@ int Statement::EIO_Step(eio_req *req) { ...@@ -668,6 +668,7 @@ int Statement::EIO_Step(eio_req *req) {
} }
else { else {
sto->error_ = true; sto->error_ = true;
sto->cells = NULL;
} }
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment