不要怂,就是干,撸起袖子干!

Commit 1cd73a5e by reedog117

resolved error trying to retrieve insertId

1 parent 95df903a
......@@ -208,14 +208,12 @@ module.exports = (function() {
var disconnect = function(client) {
var self = this;
client.on('close', function() {
self.client = null
self.isConnecting = false
})
if(client.connected)
client.end()
self.client = null
self.isConnecting = false
/* if (!this.useQueue) {
this.client = null;
......@@ -253,7 +251,10 @@ module.exports = (function() {
var connect = function(done, config) {
config = config || this.config
var connection = new mariasql();
var connection = new mariasql()
, self = this
this.isConnecting = true
connection.connect({
host: config.host,
......@@ -271,6 +272,10 @@ module.exports = (function() {
this.isConnecting = false
done(null, connection)
}).on('error', function() {
disconnect.call(self, connection)
}).on('close', function() {
disconnect.call(self, connection)
})
}
......
......@@ -23,14 +23,12 @@ module.exports = (function() {
this.options.logging('Executing: ' + this.sql)
}
var query = this.client.query(this.sql),
resultSet = [],
var resultSet = [],
errorDetected = false,
temp = 1
self = this
query.on('result', function(results) {
var resultStream = results;
this.client.query(this.sql)
.on('result', function(results) {
results.on('row', function(row) {
resultSet.push(row);
......@@ -38,37 +36,52 @@ module.exports = (function() {
.on('error', function(err) {
//console.log('error in result-loop for: ' + self.sql)
errorDetected = true
this.emit('sql', this.sql)
self.emit('sql', this.sql)
console.log('Failed query : ' + this.sql)
console.log(err)
resultStream.abort()
this.emit('error', err, this.callee)
self.emit('error', err, this.callee)
}.bind(this))
.on('end', function(info) {
//console.log(info)
if(errorDetected)
// nothing needs to be done at this point
if(errorDetected) {
return
//this.emit('sql', this.sql)
//this.emit('success', this.formatResults(resultSet))
}
self.emit('sql', this.sql)
console.log('Successful query : ' + this.sql)
// we need to figure out whether to send the result set
// or info depending upon the type of query
if( /^show/.test(this.sql.toLowerCase()) ||
/^select/.test(this.sql.toLowerCase()) ||
/^describe/.test(this.sql.toLowerCase()) ) {
console.log('results : ')
console.log(resultSet)
//console.log('formatted resultset: ' + JSON.stringify(this.formatResults(resultSet)))
self.emit('success', this.formatResults(resultSet))
} else {
console.log('results : ')
info = JSON.parse(JSON.stringify(info))
console.log(info)
//console.log('formatted resultset: ' + JSON.stringify(this.formatResults(info)))
self.emit('success', this.formatResults(info))
}
}.bind(this));
}.bind(this))
.on('error', function(err) {
//console.log( err )
//console.log('error in query: ' + this.sql)
// if(errorDetected)
// return
// errorDetected = true
// this.emit('sql', this.sql)
// this.emit('error', err, this.callee)
if(errorDetected) {
return
}
errorDetected = true
self.emit('sql', this.sql)
self.emit('error', err, this.callee)
console.log('query error')
}.bind(this))
.on('end', function() {
if(errorDetected)
return
this.emit('sql', this.sql)
console.log('Successful query : ' + this.sql)
console.log(resultSet)
this.emit('success', this.formatResults(resultSet))
.on('end', function(info) {
// nothing here yet
}.bind(this)).setMaxListeners(100)
return this
......
......@@ -29,6 +29,9 @@ module.exports = (function() {
if (err) {
this.emit('error', err, this.callee)
} else {
console.log('sql : ' + this.sql)
console.log('resultset : ' + JSON.stringify(results))
console.log('formatted resultset: ' + JSON.stringify(this.formatResults(results)))
this.emit('success', this.formatResults(results))
}
}.bind(this)).setMaxListeners(100)
......
......@@ -25,7 +25,7 @@ module.exports = {
database: 'sequelize_test',
host: '127.0.0.1',
port: 3306,
pool: { maxConnections: 1, maxIdleTime: 30}
pool: { maxConnections: 5, maxIdleTime: 30}
},
sqlite: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!