mysql
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -7,4 +7,21 @@ # Changes | ||
## HEAD | ||
## v2.0.1 | ||
* internal parser speed improvement #702 | ||
* domains support | ||
* 'trace' connection option to control if long stack traces are generated #713 #710 #439 | ||
## v2.0.0 (2014-01-09) | ||
* stream improvements: | ||
- node 0.8 support #692 | ||
- Emit 'close' events from query streams #688 | ||
* encoding fix in streaming LOAD DATA LOCAL INFILE #670 | ||
* Doc improvements | ||
## v2.0.0-rc2 (2013-12-07) | ||
* Streaming LOAD DATA LOCAL INFILE | ||
* Streaming LOAD DATA LOCAL INFILE #668 | ||
* Doc improvements | ||
@@ -11,0 +28,0 @@ |
@@ -22,2 +22,10 @@ var Net = require('net'); | ||
function bindToCurrentDomain(cb) { | ||
var domain = process.domain; | ||
if (!domain || !cb) | ||
return cb; | ||
else | ||
return domain.bind(cb); | ||
} | ||
Connection.createQuery = function(sql, values, cb) { | ||
@@ -48,3 +56,3 @@ if (sql instanceof Query) { | ||
} | ||
return new Query(options, cb); | ||
return new Query(options, bindToCurrentDomain(cb)); | ||
}; | ||
@@ -100,3 +108,3 @@ | ||
currentConfig : this.config | ||
}, cb); | ||
}, bindToCurrentDomain(cb)); | ||
}; | ||
@@ -148,3 +156,3 @@ | ||
this._implyConnect(); | ||
this._protocol.ping(cb); | ||
this._protocol.ping(bindToCurrentDomain(cb)); | ||
}; | ||
@@ -154,3 +162,3 @@ | ||
this._implyConnect(); | ||
this._protocol.stats(cb); | ||
this._protocol.stats(bindToCurrentDomain(cb)); | ||
}; | ||
@@ -160,3 +168,3 @@ | ||
this._implyConnect(); | ||
this._protocol.quit(cb); | ||
this._protocol.quit(bindToCurrentDomain(cb)); | ||
}; | ||
@@ -163,0 +171,0 @@ |
@@ -23,2 +23,3 @@ var urlParse = require('url').parse; | ||
this.debug = options.debug; | ||
this.trace = options.trace !== false; | ||
this.stringifyObjects = options.stringifyObjects || false; | ||
@@ -25,0 +26,0 @@ this.timezone = options.timezone || 'local'; |
@@ -22,2 +22,3 @@ var mysql = require('../'); | ||
Pool.prototype.getConnection = function (cb) { | ||
if (this._closed) { | ||
@@ -35,3 +36,3 @@ return process.nextTick(function(){ | ||
return process.nextTick(function(){ | ||
return cb(null, connection); | ||
cb(null, connection); | ||
}); | ||
@@ -68,2 +69,4 @@ } | ||
if (cb && process.domain) | ||
cb = process.domain.bind(cb); | ||
this._connectionQueue.push(cb); | ||
@@ -116,3 +119,3 @@ }; | ||
if (this._allConnections.length === 0) { | ||
return endCB(); | ||
return process.nextTick(endCB); | ||
} | ||
@@ -131,7 +134,7 @@ | ||
} | ||
this.getConnection(function (err, conn) { | ||
if (err) return cb(err); | ||
conn.query(sql, values, function () { | ||
conn.query(sql, values, function (err, rows, fields) { | ||
conn.release(); | ||
@@ -138,0 +141,0 @@ cb.apply(this, arguments); |
@@ -1,5 +0,5 @@ | ||
var IEEE_754_BINARY_64_PRECISION = Math.pow(2, 53); | ||
var MAX_PACKET_LENGTH = Math.pow(2, 24) - 1; | ||
var PacketHeader = require('./PacketHeader'); | ||
var BigNumber = require("bignumber.js"); | ||
var MAX_PACKET_LENGTH = Math.pow(2, 24) - 1; | ||
var MUL_32BIT = Math.pow(2, 32); | ||
var PacketHeader = require('./PacketHeader'); | ||
var BigNumber = require('bignumber.js'); | ||
@@ -115,13 +115,21 @@ module.exports = Parser; | ||
Parser.prototype.parseUnsignedNumber = function(bytes) { | ||
var bytesRead = 0; | ||
var value = 0; | ||
if (bytes === 1) { | ||
return this._buffer[this._offset++]; | ||
} | ||
while (bytesRead < bytes) { | ||
var byte = this._buffer[this._offset++]; | ||
var buffer = this._buffer; | ||
var offset = this._offset + bytes - 1; | ||
var value = 0; | ||
value += byte * Math.pow(256, bytesRead); | ||
if (bytes > 4) { | ||
throw new Error('parseUnsignedNumber: Supports only up to 4 bytes'); | ||
} | ||
bytesRead++; | ||
while (offset >= this._offset) { | ||
value = ((value << 8) | buffer[offset]) >>> 0; | ||
offset--; | ||
} | ||
this._offset += bytes; | ||
return value; | ||
@@ -153,44 +161,30 @@ }; | ||
if (bits <= 251) { | ||
return (bits === 251) | ||
? null | ||
: bits; | ||
if (bits <= 250) { | ||
return bits; | ||
} | ||
var length; | ||
var bigNumber = false; | ||
var value = 0; | ||
switch (bits) { | ||
case 251: | ||
return null; | ||
case 252: | ||
return this.parseUnsignedNumber(2); | ||
case 253: | ||
return this.parseUnsignedNumber(3); | ||
case 254: | ||
break; | ||
default: | ||
throw new Error('parseLengthCodedNumber: Unexpected first byte: 0x' + bits.toString(16)); | ||
} | ||
if (bits === 252) { | ||
length = 2; | ||
} else if (bits === 253) { | ||
length = 3; | ||
} else if (bits === 254) { | ||
length = 8; | ||
var low = this.parseUnsignedNumber(4); | ||
var high = this.parseUnsignedNumber(4); | ||
var value; | ||
if (high >>> 21) { | ||
value = (new BigNumber(low)).plus((new BigNumber(MUL_32BIT)).times(high)).toString(); | ||
if (this._supportBigNumbers) { | ||
if (this._buffer[this._offset + 6] > 31 || this._buffer[this._offset + 7]) { | ||
value = new BigNumber(0); | ||
bigNumber = true; | ||
} | ||
return value; | ||
} | ||
} else { | ||
throw new Error('parseLengthCodedNumber: Unexpected first byte: ' + bits); | ||
} | ||
for (var bytesRead = 0; bytesRead < length; bytesRead++) { | ||
bits = this._buffer[this._offset++]; | ||
if (bigNumber) { | ||
value = value.plus((new BigNumber(256)).pow(bytesRead).times(bits)); | ||
} else { | ||
value += Math.pow(256, bytesRead) * bits; | ||
} | ||
} | ||
if (bigNumber) { | ||
return value.toString(); | ||
} | ||
if (value >= IEEE_754_BINARY_64_PRECISION) { | ||
throw new Error( | ||
@@ -202,2 +196,4 @@ 'parseLengthCodedNumber: JS precision range exceeded, ' + | ||
value = low + (MUL_32BIT * high); | ||
return value; | ||
@@ -204,0 +200,0 @@ }; |
@@ -108,2 +108,7 @@ var Parser = require('./Parser'); | ||
if (this._config.trace) { | ||
// Long stack trace support | ||
sequence._callSite = new Error; | ||
} | ||
this._queue.push(sequence); | ||
@@ -110,0 +115,0 @@ |
@@ -196,3 +196,3 @@ var Sequence = require('./Sequence'); | ||
stream._read = function() { | ||
self._connection.resume(); | ||
self._connection && self._connection.resume(); | ||
}; | ||
@@ -199,0 +199,0 @@ |
@@ -12,6 +12,4 @@ var Util = require('util'); | ||
this._callback = callback; | ||
this._callSite = null; | ||
this._ended = false; | ||
// Experimental: Long stack trace support | ||
this._callSite = new Error; | ||
} | ||
@@ -42,3 +40,8 @@ | ||
Sequence.prototype._addLongStackTrace = function(err) { | ||
if (!this._callSite) { | ||
return; | ||
} | ||
var delimiter = '\n --------------------\n' ; | ||
if (err.stack.indexOf(delimiter) > -1) { | ||
@@ -67,3 +70,3 @@ return; | ||
// challenge for somebody interested in difficult problems : )! | ||
delete this._callSite; | ||
this._callSite = null; | ||
@@ -70,0 +73,0 @@ // try...finally for exception safety |
@@ -5,3 +5,3 @@ { | ||
"description": "A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"homepage": "https://github.com/felixge/node-mysql", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -8,6 +8,5 @@ # node-mysql | ||
```bash | ||
npm install mysql@2.0.0-rc1 | ||
npm install mysql | ||
``` | ||
Despite the `rc` tag, this is the recommended version for new applications. | ||
For information about the previous 0.9.x releases, visit the [v0.9 branch][]. | ||
@@ -163,2 +162,5 @@ | ||
* `debug`: Prints protocol details to stdout. (Default: `false`) | ||
* `trace`: Generates stack traces on `Error` to include call site of library | ||
entrance ("long stack traces"). Slight performance penalty for most calls. | ||
(Default: `true`) | ||
* `multipleStatements`: Allow multiple mysql statements per query. Be careful | ||
@@ -165,0 +167,0 @@ with this, it exposes you to SQL injection attacks. (Default: `false`) |
181484
3657
1036