var Utils = require("../../utils") , AbstractQuery = require('../abstract/query') , QueryTypes = require('../../query-types') module.exports = (function() { var Query = function(database, sequelize, callee, options) { this.database = database this.sequelize = sequelize this.callee = callee this.options = Utils._.extend({ logging: console.log, plain: false, raw: false }, options || {}) this.checkLoggingOption() } Utils.inherit(Query, AbstractQuery) Query.prototype.getInsertIdField = function() { return 'lastID' } Query.prototype.run = function(sql) { var self = this this.sql = sql if (this.options.logging !== false) { this.options.logging('Executing (' + this.options.uuid + '): ' + this.sql) } var columnTypes = {} this.database.serialize(function() { var executeSql = function() { if (self.sql.indexOf('-- ') === 0) { // the sql query starts with a comment. don't bother the server with that ... Utils.tick(function() { self.emit('sql', self.sql) self.emit('success', null) }) } else { self.database[getDatabaseMethod.call(self)](self.sql, function(err, results) { // allow clients to listen to sql to do their own logging or whatnot self.emit('sql', self.sql) if (err) { err.sql = self.sql onFailure.call(self, err) } else { this.columnTypes = columnTypes onSuccess.call(self, results, this) } }) } } if ((getDatabaseMethod.call(self) === 'all')) { var tableNames = [] if (self.options && self.options.tableNames) { tableNames = self.options.tableNames } else if (/FROM `(.*?)`/i.exec(self.sql)) { tableNames.push(/FROM `(.*?)`/i.exec(self.sql)[1]) } if (!tableNames.length) { executeSql() } else { var execute = Utils._.after(tableNames.length, executeSql) tableNames.forEach(function (tableName) { if (tableName !== 'sqlite_master') { // get the column types self.database.all("PRAGMA table_info(" + tableName + ")", function(err, results) { if (!err) { for (var i=0, l=results.length; i