Commit 81c64d08 by Konstantin Käfer

don't create a new object but use the binding's objects directly instead

parent fb3cf5f7
/*
Copyright (c) 2009, Eric Fredricksen <e@fredricksen.net>
Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
// Copyright (c) 2009, Eric Fredricksen <e@fredricksen.net>
// Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
var sqlite3 = module.exports = exports = require('./sqlite3_bindings');
var sys = require("sys");
var sqlite = require("./sqlite3_bindings");
var Database = exports.Database = function () {
var self = this;
var db = new sqlite.Database();
db.__proto__ = Database.prototype;
return db;
};
Database.prototype = {
__proto__: sqlite.Database.prototype,
constructor: Database,
};
Database.prototype.query = function(sql, bindings, rowCallback) {
sqlite3.Database.prototype.query = function(sql, bindings, rowCallback) {
var self = this;
if (typeof(bindings) == "function") {
......@@ -84,7 +68,7 @@ function _doStep(db, statement, rowCallback) {
// Execute a single SQL query with the given optional parameters. Calls
// `callback` with all rows or an error on query completion.
Database.prototype.execute = function (sql /* , bindings, callback */) {
sqlite3.Database.prototype.execute = function (sql /* , bindings, callback */) {
var self = this;
var bindings, callback;
var n = arguments.length;
......@@ -136,7 +120,7 @@ Database.prototype.execute = function (sql /* , bindings, callback */) {
// Execute SQL statements separated by semi-colons.
// SQL must contain no placeholders. Results are discarded.
Database.prototype.executeScript = function (script, callback) {
sqlite3.Database.prototype.executeScript = function (script, callback) {
var self = this;
(function stepOverSQL(sql) {
......@@ -170,7 +154,7 @@ Database.prototype.executeScript = function (script, callback) {
})(script);
}
Database.prototype.insertMany = function (table, columns, rows, callback) {
sqlite3.Database.prototype.insertMany = function (table, columns, rows, callback) {
var columnsFragment = columns.join(",");
var placeholdersFragment = [];
var i = columns.length;
......@@ -226,7 +210,7 @@ Database.prototype.insertMany = function (table, columns, rows, callback) {
}
exports.fromErrorCode = function(code) {
sqlite3.fromErrorCode = function(code) {
switch (code) {
case 0: return "SQLITE_OK";
case 1: return "SQLITE_ERROR";
......@@ -258,7 +242,7 @@ exports.fromErrorCode = function(code) {
}
};
exports.sanitizeError = function(err, data) {
sqlite3.sanitizeError = function(err, data) {
err.message = exports.fromErrorCode(err.errno) + ', ' + err.message +
' in query "' + err.query +
'" with values ' + JSON.stringify(data, false, 4);
......
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