我已经开始使用池连接到 mysql,而不是使用与Node.js的普通连接。因为我需要在进程完成后释放连接。当连接保持打开时,由于mysql超时问题, Node.js进入异常。
我已经编辑了我的代码,但它没有在第 94 行给我这样的错误:
TypeError: Object #<Connection> has no method 'release'
at Query._callback (/usr/local/src/conn.js:94:28)
在那条线之上:
socket.on('getUnreadPM', function (msg) {
var userSocket = clients[msg.userDestID];
if (msg.lastGotMessage == 'none') {
post = 'Select * from messages where (destUserID=\'' + msg.userDestID + '\' AND srcUserID=\'' + msg.userSrcID + '\') OR (destUserID=\'' + msg.userSrcID + '\' AND srcUserID=\'' + msg.userDestID + '\')';
} else {
post = 'Select * from messages where destUserID=\'' + msg.userDestID + '\' AND srcUserID= \'' + msg.userSrcID + '\' AND messageSendDate between \'' + msg.lastGotMessage + '\' and \'' + msg.deviceCurrentTime + '\' AND messageSendDate > \'' + msg.lastGotMessage + '\' order by messageSendDate';
}
pool.getConnection(function (err, connection) {
// Use the connection
connection.query(post, function (error, results, fields) {
// And done with the connection.
if (results.length > 0) {
if (typeof userSocket !== 'undefined') {
var boolData = results[0];
//console.log('bool data lenght : ',results.length);
var messageID = new Array();
var srcUserID = new Array();
var destUserID = new Array();
var messageContent = new Array();
var messageDate = new Array();
var didRead = new Array();
for (var i = 0; i < results.length; i++)
{
messageID.push(results[i].messageID);
srcUserID.push(results[i].srcUserID);
destUserID.push(results[i].destUserID);
messageContent.push(results[i].messageContent);
messageDate.push(dateFormat(results[i].messageSendDate, "yyyy-mm-dd HH:MM:ss"));
didRead.push(results[i].didRead);
}
userSocket.emit('history :', {
'dataMode': 'history',
'srcUserID': srcUserID,
'destUserID': destUserID,
'messageContent': messageContent,
'messageSendDate': messageDate,
'didread': didRead
});
} else {
userSocket.emit('history :', {
'dataMode': 'none',
});
}
} else {
userSocket.emit('history :', {
'dataMode': 'none',
});
}
connection.release();
});
});
});