Comparing version
@@ -7,2 +7,24 @@ # Changes | ||
## v2.0.0-alpha8 (2013-04-30) | ||
* Switch to old mode for Streams 2 (Node.js v 0.10.x) | ||
* Add stream method to Query Wraps events from the query object into a node v0.10.x Readable stream | ||
* DECIMAL should also be treated as big number | ||
* Removed slow unnecessary stack access | ||
* Added charsets | ||
* Added bigNumberStrings option for forcing BIGINT columns as strings | ||
* Changes date parsing to return String if not a valid JS Date | ||
* Adds support for ?? escape sequence to escape identifiers | ||
* Changes Auth.token() to force password to be in binary, not utf8 (#378) | ||
* Restrict debugging by packet types | ||
* Add 'multipleStatements' option tracking to ConnectionConfig. Fixes GH-408 | ||
* Changes Pool to handle 'error' events and dispose connection | ||
* Allows db.query({ sql: "..." }, [ val1, ... ], cb); (#390) | ||
* Improved documentation | ||
* Bug fixes | ||
## v2.0.0-alpha7 (2013-02-03) | ||
* Add connection pooling (#351) | ||
## v2.0.0-alpha6 (2013-01-31) | ||
@@ -9,0 +31,0 @@ |
@@ -20,2 +20,3 @@ var Net = require('net'); | ||
this._connectCalled = false; | ||
this.state = "disconnected"; | ||
} | ||
@@ -33,3 +34,7 @@ | ||
options = sql; | ||
cb = values; | ||
if (typeof values === 'function') { | ||
cb = values; | ||
} else { | ||
options.values = values; | ||
} | ||
} else if (typeof values === 'function') { | ||
@@ -56,2 +61,5 @@ // query(sql, cb) | ||
// Node v0.10+ Switch socket into "old mode" (Streams2) | ||
this._socket.on("data",function() {}); | ||
this._socket.pipe(this._protocol); | ||
@@ -61,2 +69,4 @@ this._protocol.pipe(this._socket); | ||
this._socket.on('error', this._handleNetworkError.bind(this)); | ||
this._socket.on('connect', this._handleProtocolConnect.bind(this)); | ||
this._protocol.on('handshake', this._handleProtocolHandshake.bind(this)); | ||
this._protocol.on('unhandledError', this._handleProtocolError.bind(this)); | ||
@@ -95,2 +105,3 @@ this._protocol.on('drain', this._handleProtocolDrain.bind(this)); | ||
var query = Connection.createQuery(sql, values, cb); | ||
query._connection = this; | ||
@@ -123,2 +134,3 @@ if (!(typeof sql == 'object' && 'typeCast' in sql)) { | ||
Connection.prototype.destroy = function() { | ||
this.state = "disconnected"; | ||
this._implyConnect(); | ||
@@ -155,2 +167,3 @@ this._socket.destroy(); | ||
Connection.prototype._handleProtocolError = function(err) { | ||
this.state = "protocol_error"; | ||
this.emit('error', err); | ||
@@ -163,3 +176,12 @@ }; | ||
Connection.prototype._handleProtocolConnect = function() { | ||
this.state = "connected"; | ||
}; | ||
Connection.prototype._handleProtocolHandshake = function() { | ||
this.state = "authenticated"; | ||
}; | ||
Connection.prototype._handleProtocolEnd = function(err) { | ||
this.state = "disconnected"; | ||
this.emit('end', err); | ||
@@ -166,0 +188,0 @@ }; |
@@ -11,16 +11,18 @@ var urlParse = require('url').parse; | ||
this.host = options.host || 'localhost'; | ||
this.port = options.port || 3306; | ||
this.socketPath = options.socketPath; | ||
this.user = options.user || undefined; | ||
this.password = options.password || undefined; | ||
this.database = options.database; | ||
this.insecureAuth = options.insecureAuth || false; | ||
this.supportBigNumbers = options.supportBigNumbers || false; | ||
this.debug = options.debug; | ||
this.timezone = options.timezone || 'local'; | ||
this.flags = options.flags || ''; | ||
this.queryFormat = options.queryFormat; | ||
this.pool = options.pool || undefined; | ||
this.typeCast = (options.typeCast === undefined) | ||
this.host = options.host || 'localhost'; | ||
this.port = options.port || 3306; | ||
this.socketPath = options.socketPath; | ||
this.user = options.user || undefined; | ||
this.password = options.password || undefined; | ||
this.database = options.database; | ||
this.insecureAuth = options.insecureAuth || false; | ||
this.supportBigNumbers = options.supportBigNumbers || false; | ||
this.bigNumberStrings = options.bigNumberStrings || false; | ||
this.debug = options.debug; | ||
this.timezone = options.timezone || 'local'; | ||
this.flags = options.flags || ''; | ||
this.queryFormat = options.queryFormat; | ||
this.pool = options.pool || undefined; | ||
this.multipleStatements = options.multipleStatements || false; | ||
this.typeCast = (options.typeCast === undefined) | ||
? true | ||
@@ -39,3 +41,3 @@ : options.typeCast; | ||
? ConnectionConfig.getCharsetNumber(options.charset) | ||
: Charsets.UTF8_GENERAL_CI; | ||
: options.charsetNumber||Charsets.UTF8_GENERAL_CI; | ||
@@ -42,0 +44,0 @@ this.clientFlags = ConnectionConfig.mergeFlags(ConnectionConfig.getDefaultFlags(options), |
@@ -119,2 +119,3 @@ | ||
connection.on('end', this._handleConnectionEnd.bind(this, connection)); | ||
connection.on('error', this._handleConnectionError.bind(this, connection)); | ||
@@ -131,2 +132,9 @@ return connection; | ||
Pool.prototype._handleConnectionError = function(connection) { | ||
if (this._closed || connection._poolRemoved) { | ||
return; | ||
} | ||
this._removeConnection(connection); | ||
}; | ||
Pool.prototype._removeConnection = function(connection) { | ||
@@ -133,0 +141,0 @@ connection._poolRemoved = true; |
@@ -29,3 +29,4 @@ var Buffer = require('buffer').Buffer; | ||
var stage1 = sha1(password); | ||
// password must be in binary format, not utf8 | ||
var stage1 = sha1((new Buffer(password, "utf8")).toString("binary")); | ||
var stage2 = sha1(stage1); | ||
@@ -32,0 +33,0 @@ var stage3 = sha1(scramble.toString('binary') + stage2); |
@@ -1,128 +0,195 @@ | ||
// not sure where I got this from, will need to add a generation script for it | ||
exports.BIG5_CHINESE_CI = 1; | ||
exports.LATIN2_CZECH_CS = 2; | ||
exports.DEC8_SWEDISH_CI = 3; | ||
exports.CP850_GENERAL_CI = 4; | ||
exports.LATIN1_GERMAN1_CI = 5; | ||
exports.HP8_ENGLISH_CI = 6; | ||
exports.KOI8R_GENERAL_CI = 7; | ||
exports.LATIN1_SWEDISH_CI = 8; | ||
exports.LATIN2_GENERAL_CI = 9; | ||
exports.SWE7_SWEDISH_CI = 10; | ||
exports.ASCII_GENERAL_CI = 11; | ||
exports.UJIS_JAPANESE_CI = 12; | ||
exports.SJIS_JAPANESE_CI = 13; | ||
exports.CP1251_BULGARIAN_CI = 14; | ||
exports.LATIN1_DANISH_CI = 15; | ||
exports.HEBREW_GENERAL_CI = 16; | ||
exports.TIS620_THAI_CI = 18; | ||
exports.EUCKR_KOREAN_CI = 19; | ||
exports.LATIN7_ESTONIAN_CS = 20; | ||
exports.LATIN2_HUNGARIAN_CI = 21; | ||
exports.KOI8U_GENERAL_CI = 22; | ||
exports.CP1251_UKRAINIAN_CI = 23; | ||
exports.GB2312_CHINESE_CI = 24; | ||
exports.GREEK_GENERAL_CI = 25; | ||
exports.CP1250_GENERAL_CI = 26; | ||
exports.LATIN2_CROATIAN_CI = 27; | ||
exports.GBK_CHINESE_CI = 28; | ||
exports.CP1257_LITHUANIAN_CI = 29; | ||
exports.LATIN5_TURKISH_CI = 30; | ||
exports.LATIN1_GERMAN2_CI = 31; | ||
exports.ARMSCII8_GENERAL_CI = 32; | ||
exports.UTF8_GENERAL_CI = 33; | ||
exports.CP1250_CZECH_CS = 34; | ||
exports.UCS2_GENERAL_CI = 35; | ||
exports.CP866_GENERAL_CI = 36; | ||
exports.KEYBCS2_GENERAL_CI = 37; | ||
exports.MACCE_GENERAL_CI = 38; | ||
exports.MACROMAN_GENERAL_CI = 39; | ||
exports.CP852_GENERAL_CI = 40; | ||
exports.LATIN7_GENERAL_CI = 41; | ||
exports.LATIN7_GENERAL_CS = 42; | ||
exports.MACCE_BIN = 43; | ||
exports.CP1250_CROATIAN_CI = 44; | ||
exports.LATIN1_BIN = 47; | ||
exports.LATIN1_GENERAL_CI = 48; | ||
exports.LATIN1_GENERAL_CS = 49; | ||
exports.CP1251_BIN = 50; | ||
exports.CP1251_GENERAL_CI = 51; | ||
exports.CP1251_GENERAL_CS = 52; | ||
exports.MACROMAN_BIN = 53; | ||
exports.CP1256_GENERAL_CI = 57; | ||
exports.CP1257_BIN = 58; | ||
exports.CP1257_GENERAL_CI = 59; | ||
exports.BINARY = 63; | ||
exports.ARMSCII8_BIN = 64; | ||
exports.ASCII_BIN = 65; | ||
exports.CP1250_BIN = 66; | ||
exports.CP1256_BIN = 67; | ||
exports.CP866_BIN = 68; | ||
exports.DEC8_BIN = 69; | ||
exports.GREEK_BIN = 70; | ||
exports.HEBREW_BIN = 71; | ||
exports.HP8_BIN = 72; | ||
exports.KEYBCS2_BIN = 73; | ||
exports.KOI8R_BIN = 74; | ||
exports.KOI8U_BIN = 75; | ||
exports.LATIN2_BIN = 77; | ||
exports.LATIN5_BIN = 78; | ||
exports.LATIN7_BIN = 79; | ||
exports.CP850_BIN = 80; | ||
exports.CP852_BIN = 81; | ||
exports.SWE7_BIN = 82; | ||
exports.UTF8_BIN = 83; | ||
exports.BIG5_BIN = 84; | ||
exports.EUCKR_BIN = 85; | ||
exports.GB2312_BIN = 86; | ||
exports.GBK_BIN = 87; | ||
exports.SJIS_BIN = 88; | ||
exports.TIS620_BIN = 89; | ||
exports.UCS2_BIN = 90; | ||
exports.UJIS_BIN = 91; | ||
exports.GEOSTD8_GENERAL_CI = 92; | ||
exports.GEOSTD8_BIN = 93; | ||
exports.LATIN1_SPANISH_CI = 94; | ||
exports.CP932_JAPANESE_CI = 95; | ||
exports.CP932_BIN = 96; | ||
exports.EUCJPMS_JAPANESE_CI = 97; | ||
exports.EUCJPMS_BIN = 98; | ||
exports.CP1250_POLISH_CI = 99; | ||
exports.UCS2_UNICODE_CI = 128; | ||
exports.UCS2_ICELANDIC_CI = 129; | ||
exports.UCS2_LATVIAN_CI = 130; | ||
exports.UCS2_ROMANIAN_CI = 131; | ||
exports.UCS2_SLOVENIAN_CI = 132; | ||
exports.UCS2_POLISH_CI = 133; | ||
exports.UCS2_ESTONIAN_CI = 134; | ||
exports.UCS2_SPANISH_CI = 135; | ||
exports.UCS2_SWEDISH_CI = 136; | ||
exports.UCS2_TURKISH_CI = 137; | ||
exports.UCS2_CZECH_CI = 138; | ||
exports.UCS2_DANISH_CI = 139; | ||
exports.UCS2_LITHUANIAN_CI = 140; | ||
exports.UCS2_SLOVAK_CI = 141; | ||
exports.UCS2_SPANISH2_CI = 142; | ||
exports.UCS2_ROMAN_CI = 143; | ||
exports.UCS2_PERSIAN_CI = 144; | ||
exports.UCS2_ESPERANTO_CI = 145; | ||
exports.UCS2_HUNGARIAN_CI = 146; | ||
exports.UTF8_UNICODE_CI = 192; | ||
exports.UTF8_ICELANDIC_CI = 193; | ||
exports.UTF8_LATVIAN_CI = 194; | ||
exports.UTF8_ROMANIAN_CI = 195; | ||
exports.UTF8_SLOVENIAN_CI = 196; | ||
exports.UTF8_POLISH_CI = 197; | ||
exports.UTF8_ESTONIAN_CI = 198; | ||
exports.UTF8_SPANISH_CI = 199; | ||
exports.UTF8_SWEDISH_CI = 200; | ||
exports.UTF8_TURKISH_CI = 201; | ||
exports.UTF8_CZECH_CI = 202; | ||
exports.UTF8_DANISH_CI = 203; | ||
exports.UTF8_LITHUANIAN_CI = 204; | ||
exports.UTF8_SLOVAK_CI = 205; | ||
exports.UTF8_SPANISH2_CI = 206; | ||
exports.UTF8_ROMAN_CI = 207; | ||
exports.UTF8_PERSIAN_CI = 208; | ||
exports.UTF8_ESPERANTO_CI = 209; | ||
exports.UTF8_HUNGARIAN_CI = 210; | ||
exports.BIG5_CHINESE_CI = 1; | ||
exports.LATIN2_CZECH_CS = 2; | ||
exports.DEC8_SWEDISH_CI = 3; | ||
exports.CP850_GENERAL_CI = 4; | ||
exports.LATIN1_GERMAN1_CI = 5; | ||
exports.HP8_ENGLISH_CI = 6; | ||
exports.KOI8R_GENERAL_CI = 7; | ||
exports.LATIN1_SWEDISH_CI = 8; | ||
exports.LATIN2_GENERAL_CI = 9; | ||
exports.SWE7_SWEDISH_CI = 10; | ||
exports.ASCII_GENERAL_CI = 11; | ||
exports.UJIS_JAPANESE_CI = 12; | ||
exports.SJIS_JAPANESE_CI = 13; | ||
exports.CP1251_BULGARIAN_CI = 14; | ||
exports.LATIN1_DANISH_CI = 15; | ||
exports.HEBREW_GENERAL_CI = 16; | ||
exports.TIS620_THAI_CI = 18; | ||
exports.EUCKR_KOREAN_CI = 19; | ||
exports.LATIN7_ESTONIAN_CS = 20; | ||
exports.LATIN2_HUNGARIAN_CI = 21; | ||
exports.KOI8U_GENERAL_CI = 22; | ||
exports.CP1251_UKRAINIAN_CI = 23; | ||
exports.GB2312_CHINESE_CI = 24; | ||
exports.GREEK_GENERAL_CI = 25; | ||
exports.CP1250_GENERAL_CI = 26; | ||
exports.LATIN2_CROATIAN_CI = 27; | ||
exports.GBK_CHINESE_CI = 28; | ||
exports.CP1257_LITHUANIAN_CI = 29; | ||
exports.LATIN5_TURKISH_CI = 30; | ||
exports.LATIN1_GERMAN2_CI = 31; | ||
exports.ARMSCII8_GENERAL_CI = 32; | ||
exports.UTF8_GENERAL_CI = 33; | ||
exports.CP1250_CZECH_CS = 34; | ||
exports.UCS2_GENERAL_CI = 35; | ||
exports.CP866_GENERAL_CI = 36; | ||
exports.KEYBCS2_GENERAL_CI = 37; | ||
exports.MACCE_GENERAL_CI = 38; | ||
exports.MACROMAN_GENERAL_CI = 39; | ||
exports.CP852_GENERAL_CI = 40; | ||
exports.LATIN7_GENERAL_CI = 41; | ||
exports.LATIN7_GENERAL_CS = 42; | ||
exports.MACCE_BIN = 43; | ||
exports.CP1250_CROATIAN_CI = 44; | ||
exports.UTF8MB4_GENERAL_CI = 45; | ||
exports.UTF8MB4_BIN = 46; | ||
exports.LATIN1_BIN = 47; | ||
exports.LATIN1_GENERAL_CI = 48; | ||
exports.LATIN1_GENERAL_CS = 49; | ||
exports.CP1251_BIN = 50; | ||
exports.CP1251_GENERAL_CI = 51; | ||
exports.CP1251_GENERAL_CS = 52; | ||
exports.MACROMAN_BIN = 53; | ||
exports.UTF16_GENERAL_CI = 54; | ||
exports.UTF16_BIN = 55; | ||
exports.CP1256_GENERAL_CI = 57; | ||
exports.CP1257_BIN = 58; | ||
exports.CP1257_GENERAL_CI = 59; | ||
exports.UTF32_GENERAL_CI = 60; | ||
exports.UTF32_BIN = 61; | ||
exports.BINARY = 63; | ||
exports.ARMSCII8_BIN = 64; | ||
exports.ASCII_BIN = 65; | ||
exports.CP1250_BIN = 66; | ||
exports.CP1256_BIN = 67; | ||
exports.CP866_BIN = 68; | ||
exports.DEC8_BIN = 69; | ||
exports.GREEK_BIN = 70; | ||
exports.HEBREW_BIN = 71; | ||
exports.HP8_BIN = 72; | ||
exports.KEYBCS2_BIN = 73; | ||
exports.KOI8R_BIN = 74; | ||
exports.KOI8U_BIN = 75; | ||
exports.LATIN2_BIN = 77; | ||
exports.LATIN5_BIN = 78; | ||
exports.LATIN7_BIN = 79; | ||
exports.CP850_BIN = 80; | ||
exports.CP852_BIN = 81; | ||
exports.SWE7_BIN = 82; | ||
exports.UTF8_BIN = 83; | ||
exports.BIG5_BIN = 84; | ||
exports.EUCKR_BIN = 85; | ||
exports.GB2312_BIN = 86; | ||
exports.GBK_BIN = 87; | ||
exports.SJIS_BIN = 88; | ||
exports.TIS620_BIN = 89; | ||
exports.UCS2_BIN = 90; | ||
exports.UJIS_BIN = 91; | ||
exports.GEOSTD8_GENERAL_CI = 92; | ||
exports.GEOSTD8_BIN = 93; | ||
exports.LATIN1_SPANISH_CI = 94; | ||
exports.CP932_JAPANESE_CI = 95; | ||
exports.CP932_BIN = 96; | ||
exports.EUCJPMS_JAPANESE_CI = 97; | ||
exports.EUCJPMS_BIN = 98; | ||
exports.CP1250_POLISH_CI = 99; | ||
exports.UTF16_UNICODE_CI = 101; | ||
exports.UTF16_ICELANDIC_CI = 102; | ||
exports.UTF16_LATVIAN_CI = 103; | ||
exports.UTF16_ROMANIAN_CI = 104; | ||
exports.UTF16_SLOVENIAN_CI = 105; | ||
exports.UTF16_POLISH_CI = 106; | ||
exports.UTF16_ESTONIAN_CI = 107; | ||
exports.UTF16_SPANISH_CI = 108; | ||
exports.UTF16_SWEDISH_CI = 109; | ||
exports.UTF16_TURKISH_CI = 110; | ||
exports.UTF16_CZECH_CI = 111; | ||
exports.UTF16_DANISH_CI = 112; | ||
exports.UTF16_LITHUANIAN_CI = 113; | ||
exports.UTF16_SLOVAK_CI = 114; | ||
exports.UTF16_SPANISH2_CI = 115; | ||
exports.UTF16_ROMAN_CI = 116; | ||
exports.UTF16_PERSIAN_CI = 117; | ||
exports.UTF16_ESPERANTO_CI = 118; | ||
exports.UTF16_HUNGARIAN_CI = 119; | ||
exports.UTF16_SINHALA_CI = 120; | ||
exports.UCS2_UNICODE_CI = 128; | ||
exports.UCS2_ICELANDIC_CI = 129; | ||
exports.UCS2_LATVIAN_CI = 130; | ||
exports.UCS2_ROMANIAN_CI = 131; | ||
exports.UCS2_SLOVENIAN_CI = 132; | ||
exports.UCS2_POLISH_CI = 133; | ||
exports.UCS2_ESTONIAN_CI = 134; | ||
exports.UCS2_SPANISH_CI = 135; | ||
exports.UCS2_SWEDISH_CI = 136; | ||
exports.UCS2_TURKISH_CI = 137; | ||
exports.UCS2_CZECH_CI = 138; | ||
exports.UCS2_DANISH_CI = 139; | ||
exports.UCS2_LITHUANIAN_CI = 140; | ||
exports.UCS2_SLOVAK_CI = 141; | ||
exports.UCS2_SPANISH2_CI = 142; | ||
exports.UCS2_ROMAN_CI = 143; | ||
exports.UCS2_PERSIAN_CI = 144; | ||
exports.UCS2_ESPERANTO_CI = 145; | ||
exports.UCS2_HUNGARIAN_CI = 146; | ||
exports.UCS2_SINHALA_CI = 147; | ||
exports.UTF32_UNICODE_CI = 160; | ||
exports.UTF32_ICELANDIC_CI = 161; | ||
exports.UTF32_LATVIAN_CI = 162; | ||
exports.UTF32_ROMANIAN_CI = 163; | ||
exports.UTF32_SLOVENIAN_CI = 164; | ||
exports.UTF32_POLISH_CI = 165; | ||
exports.UTF32_ESTONIAN_CI = 166; | ||
exports.UTF32_SPANISH_CI = 167; | ||
exports.UTF32_SWEDISH_CI = 168; | ||
exports.UTF32_TURKISH_CI = 169; | ||
exports.UTF32_CZECH_CI = 170; | ||
exports.UTF32_DANISH_CI = 171; | ||
exports.UTF32_LITHUANIAN_CI = 172; | ||
exports.UTF32_SLOVAK_CI = 173; | ||
exports.UTF32_SPANISH2_CI = 174; | ||
exports.UTF32_ROMAN_CI = 175; | ||
exports.UTF32_PERSIAN_CI = 176; | ||
exports.UTF32_ESPERANTO_CI = 177; | ||
exports.UTF32_HUNGARIAN_CI = 178; | ||
exports.UTF32_SINHALA_CI = 179; | ||
exports.UTF8_UNICODE_CI = 192; | ||
exports.UTF8_ICELANDIC_CI = 193; | ||
exports.UTF8_LATVIAN_CI = 194; | ||
exports.UTF8_ROMANIAN_CI = 195; | ||
exports.UTF8_SLOVENIAN_CI = 196; | ||
exports.UTF8_POLISH_CI = 197; | ||
exports.UTF8_ESTONIAN_CI = 198; | ||
exports.UTF8_SPANISH_CI = 199; | ||
exports.UTF8_SWEDISH_CI = 200; | ||
exports.UTF8_TURKISH_CI = 201; | ||
exports.UTF8_CZECH_CI = 202; | ||
exports.UTF8_DANISH_CI = 203; | ||
exports.UTF8_LITHUANIAN_CI = 204; | ||
exports.UTF8_SLOVAK_CI = 205; | ||
exports.UTF8_SPANISH2_CI = 206; | ||
exports.UTF8_ROMAN_CI = 207; | ||
exports.UTF8_PERSIAN_CI = 208; | ||
exports.UTF8_ESPERANTO_CI = 209; | ||
exports.UTF8_HUNGARIAN_CI = 210; | ||
exports.UTF8_SINHALA_CI = 211; | ||
exports.UTF8MB4_UNICODE_CI = 224; | ||
exports.UTF8MB4_ICELANDIC_CI = 225; | ||
exports.UTF8MB4_LATVIAN_CI = 226; | ||
exports.UTF8MB4_ROMANIAN_CI = 227; | ||
exports.UTF8MB4_SLOVENIAN_CI = 228; | ||
exports.UTF8MB4_POLISH_CI = 229; | ||
exports.UTF8MB4_ESTONIAN_CI = 230; | ||
exports.UTF8MB4_SPANISH_CI = 231; | ||
exports.UTF8MB4_SWEDISH_CI = 232; | ||
exports.UTF8MB4_TURKISH_CI = 233; | ||
exports.UTF8MB4_CZECH_CI = 234; | ||
exports.UTF8MB4_DANISH_CI = 235; | ||
exports.UTF8MB4_LITHUANIAN_CI = 236; | ||
exports.UTF8MB4_SLOVAK_CI = 237; | ||
exports.UTF8MB4_SPANISH2_CI = 238; | ||
exports.UTF8MB4_ROMAN_CI = 239; | ||
exports.UTF8MB4_PERSIAN_CI = 240; | ||
exports.UTF8MB4_ESPERANTO_CI = 241; | ||
exports.UTF8MB4_HUNGARIAN_CI = 242; | ||
exports.UTF8MB4_SINHALA_CI = 243; |
@@ -12,22 +12,42 @@ module.exports = ClientAuthenticationPacket; | ||
this.database = options.database; | ||
this.protocol41 = options.protocol41; | ||
} | ||
ClientAuthenticationPacket.prototype.parse = function(parser) { | ||
this.clientFlags = parser.parseUnsignedNumber(4); | ||
this.maxPacketSize = parser.parseUnsignedNumber(4); | ||
this.charsetNumber = parser.parseUnsignedNumber(1); | ||
this.filler = parser.parseFiller(23); | ||
this.user = parser.parseNullTerminatedString(); | ||
this.scrambleBuff = parser.parseLengthCodedBuffer(); | ||
this.database = parser.parseNullTerminatedString(); | ||
if (this.protocol41) { | ||
this.clientFlags = parser.parseUnsignedNumber(4); | ||
this.maxPacketSize = parser.parseUnsignedNumber(4); | ||
this.charsetNumber = parser.parseUnsignedNumber(1); | ||
this.filler = parser.parseFiller(23); | ||
this.user = parser.parseNullTerminatedString(); | ||
this.scrambleBuff = parser.parseLengthCodedBuffer(); | ||
this.database = parser.parseNullTerminatedString(); | ||
} else { | ||
this.clientFlags = parser.parseUnsignedNumber(2); | ||
this.maxPacketSize = parser.parseUnsignedNumber(3); | ||
this.user = parser.parseNullTerminatedString(); | ||
this.scrambleBuff = parser.parseBuffer(8); | ||
this.database = parser.parseLengthCodedBuffer(); | ||
} | ||
}; | ||
ClientAuthenticationPacket.prototype.write = function(writer) { | ||
writer.writeUnsignedNumber(4, this.clientFlags); | ||
writer.writeUnsignedNumber(4, this.maxPacketSize); | ||
writer.writeUnsignedNumber(1, this.charsetNumber); | ||
writer.writeFiller(23); | ||
writer.writeNullTerminatedString(this.user); | ||
writer.writeLengthCodedBuffer(this.scrambleBuff); | ||
writer.writeNullTerminatedString(this.database); | ||
if (this.protocol41) { | ||
writer.writeUnsignedNumber(4, this.clientFlags); | ||
writer.writeUnsignedNumber(4, this.maxPacketSize); | ||
writer.writeUnsignedNumber(1, this.charsetNumber); | ||
writer.writeFiller(23); | ||
writer.writeNullTerminatedString(this.user); | ||
writer.writeLengthCodedBuffer(this.scrambleBuff); | ||
writer.writeNullTerminatedString(this.database); | ||
} else { | ||
writer.writeUnsignedNumber(2, this.clientFlags); | ||
writer.writeUnsignedNumber(3, this.maxPacketSize); | ||
writer.writeNullTerminatedString(this.user); | ||
writer.writeBuffer(this.scrambleBuff); | ||
if (this.database && this.database.length) { | ||
writer.writeFiller(1); | ||
writer.writeBuffer(new Buffer(this.database)); | ||
} | ||
} | ||
}; |
@@ -8,2 +8,3 @@ module.exports = EofPacket; | ||
this.serverStatus = options.serverStatus; | ||
this.protocol41 = options.protocol41; | ||
} | ||
@@ -13,4 +14,6 @@ | ||
this.fieldCount = parser.parseUnsignedNumber(1); | ||
this.warningCount = parser.parseUnsignedNumber(2); | ||
this.serverStatus = parser.parseUnsignedNumber(2); | ||
if (this.protocol41) { | ||
this.warningCount = parser.parseUnsignedNumber(2); | ||
this.serverStatus = parser.parseUnsignedNumber(2); | ||
} | ||
}; | ||
@@ -20,4 +23,6 @@ | ||
writer.writeUnsignedNumber(1, 0xfe); | ||
writer.writeUnsignedNumber(2, this.warningCount); | ||
writer.writeUnsignedNumber(2, this.serverStatus); | ||
if (this.protocol41) { | ||
writer.writeUnsignedNumber(2, this.warningCount); | ||
writer.writeUnsignedNumber(2, this.serverStatus); | ||
} | ||
}; |
@@ -5,62 +5,79 @@ module.exports = FieldPacket; | ||
this.catalog = options.catalog; | ||
this.db = options.db; | ||
this.table = options.table; | ||
this.orgTable = options.orgTable; | ||
this.name = options.name; | ||
this.orgName = options.orgName; | ||
this.filler1 = undefined; | ||
this.charsetNr = options.charsetNr; | ||
this.length = options.length; | ||
this.type = options.type; | ||
this.flags = options.flags; | ||
this.decimals = options.decimals; | ||
this.filler2 = undefined; | ||
this.default = options.default; | ||
this.zeroFill = options.zeroFill; | ||
this.catalog = options.catalog; | ||
this.db = options.db; | ||
this.table = options.table; | ||
this.orgTable = options.orgTable; | ||
this.name = options.name; | ||
this.orgName = options.orgName; | ||
this.filler1 = undefined; | ||
this.charsetNr = options.charsetNr; | ||
this.length = options.length; | ||
this.type = options.type; | ||
this.flags = options.flags; | ||
this.decimals = options.decimals; | ||
this.filler2 = undefined; | ||
this.default = options.default; | ||
this.zeroFill = options.zeroFill; | ||
this.protocol41 = options.protocol41 | ||
} | ||
FieldPacket.prototype.parse = function(parser) { | ||
this.catalog = parser.parseLengthCodedString(); | ||
this.db = parser.parseLengthCodedString(); | ||
this.table = parser.parseLengthCodedString(); | ||
this.orgTable = parser.parseLengthCodedString(); | ||
this.name = parser.parseLengthCodedString(); | ||
this.orgName = parser.parseLengthCodedString(); | ||
this.filler1 = parser.parseFiller(1); | ||
this.charsetNr = parser.parseUnsignedNumber(2); | ||
this.fieldLength = parser.parseUnsignedNumber(4); | ||
this.type = parser.parseUnsignedNumber(1); | ||
this.flags = parser.parseUnsignedNumber(2); | ||
this.decimals = parser.parseUnsignedNumber(1); | ||
this.filler2 = parser.parseFiller(2); | ||
if (this.protocol41) { | ||
this.catalog = parser.parseLengthCodedString(); | ||
this.db = parser.parseLengthCodedString(); | ||
this.table = parser.parseLengthCodedString(); | ||
this.orgTable = parser.parseLengthCodedString(); | ||
this.name = parser.parseLengthCodedString(); | ||
this.orgName = parser.parseLengthCodedString(); | ||
this.filler1 = parser.parseFiller(1); | ||
this.charsetNr = parser.parseUnsignedNumber(2); | ||
this.fieldLength = parser.parseUnsignedNumber(4); | ||
this.type = parser.parseUnsignedNumber(1); | ||
this.flags = parser.parseUnsignedNumber(2); | ||
this.decimals = parser.parseUnsignedNumber(1); | ||
this.filler2 = parser.parseFiller(2); | ||
// parsed flags | ||
this.zeroFill = (this.flags & 0x0040 ? true : false); | ||
// parsed flags | ||
this.zeroFill = (this.flags & 0x0040 ? true : false); | ||
if (parser.reachedPacketEnd()) { | ||
return; | ||
if (parser.reachedPacketEnd()) { | ||
return; | ||
} | ||
this.default = parser.parseLengthCodedNumber(); | ||
} else { | ||
this.table = parser.parseLengthCodedString(); | ||
this.name = parser.parseLengthCodedString(); | ||
this.fieldLength = parser.parseUnsignedNumber(parser.parseUnsignedNumber(1)); | ||
this.type = parser.parseUnsignedNumber(parser.parseUnsignedNumber(1)); | ||
} | ||
this.default = parser.parseLengthCodedNumber(); | ||
}; | ||
FieldPacket.prototype.write = function(writer) { | ||
writer.writeLengthCodedString(this.catalog); | ||
writer.writeLengthCodedString(this.db); | ||
writer.writeLengthCodedString(this.table); | ||
writer.writeLengthCodedString(this.orgTable); | ||
writer.writeLengthCodedString(this.name); | ||
writer.writeLengthCodedString(this.orgName); | ||
writer.writeFiller(1); | ||
writer.writeUnsignedNumber(2, this.charsetNr || 0); | ||
writer.writeUnsignedNumber(4, this.fieldLength || 0); | ||
writer.writeUnsignedNumber(1, this.type) || 0; | ||
writer.writeUnsignedNumber(2, this.flags || 0); | ||
writer.writeUnsignedNumber(1, this.decimals || 0); | ||
writer.writeFiller(2); | ||
if (this.protocol41) { | ||
writer.writeLengthCodedString(this.catalog); | ||
writer.writeLengthCodedString(this.db); | ||
writer.writeLengthCodedString(this.table); | ||
writer.writeLengthCodedString(this.orgTable); | ||
writer.writeLengthCodedString(this.name); | ||
writer.writeLengthCodedString(this.orgName); | ||
writer.writeFiller(1); | ||
writer.writeUnsignedNumber(2, this.charsetNr || 0); | ||
writer.writeUnsignedNumber(4, this.fieldLength || 0); | ||
writer.writeUnsignedNumber(1, this.type || 0); | ||
writer.writeUnsignedNumber(2, this.flags || 0); | ||
writer.writeUnsignedNumber(1, this.decimals || 0); | ||
writer.writeFiller(2); | ||
if (this.default !== undefined) { | ||
writer.writeLengthCodedString(this.default); | ||
if (this.default !== undefined) { | ||
writer.writeLengthCodedString(this.default); | ||
} | ||
} else { | ||
writer.writeLengthCodedString(this.table); | ||
writer.writeLengthCodedString(this.name); | ||
writer.writeUnsignedNumber(1, 0x01); | ||
writer.writeUnsignedNumber(1, this.fieldLength); | ||
writer.writeUnsignedNumber(1, 0x01); | ||
writer.writeUnsignedNumber(1, this.type); | ||
} | ||
}; |
@@ -19,2 +19,3 @@ module.exports = HandshakeInitializationPacket; | ||
this.pluginData = options.pluginData; | ||
this.protocol41 = options.protocol41; | ||
} | ||
@@ -31,12 +32,18 @@ | ||
this.serverStatus = parser.parseUnsignedNumber(2); | ||
this.serverCapabilities2 = parser.parseUnsignedNumber(2); | ||
this.scrambleLength = parser.parseUnsignedNumber(1); | ||
this.filler2 = parser.parseFiller(10); | ||
// scrambleBuff2 should be 0x00 terminated, but sphinx does not do this | ||
// so we assume scrambleBuff2 to be 12 byte and treat the next byte as a | ||
// filler byte. | ||
this.scrambleBuff2 = parser.parseBuffer(12); | ||
this.filler3 = parser.parseFiller(1); | ||
this.protocol41 = (this.serverCapabilities1 & (1 << 9)) > 0; | ||
if (this.protocol41) { | ||
this.serverCapabilities2 = parser.parseUnsignedNumber(2); | ||
this.scrambleLength = parser.parseUnsignedNumber(1); | ||
this.filler2 = parser.parseFiller(10); | ||
// scrambleBuff2 should be 0x00 terminated, but sphinx does not do this | ||
// so we assume scrambleBuff2 to be 12 byte and treat the next byte as a | ||
// filler byte. | ||
this.scrambleBuff2 = parser.parseBuffer(12); | ||
this.filler3 = parser.parseFiller(1); | ||
} else { | ||
this.filler2 = parser.parseFiller(13); | ||
} | ||
if (parser.reachedPacketEnd()) { | ||
@@ -66,5 +73,7 @@ return; | ||
writer.writeUnsignedNumber(2, this.serverStatus); | ||
writer.writeUnsignedNumber(2, this.serverCapabilities2); | ||
writer.writeUnsignedNumber(1, this.scrambleLength); | ||
writer.writeFiller(10); | ||
if (this.protocol41) { | ||
writer.writeUnsignedNumber(2, this.serverCapabilities2); | ||
writer.writeUnsignedNumber(1, this.scrambleLength); | ||
writer.writeFiller(10); | ||
} | ||
writer.writeNullTerminatedBuffer(this.scrambleBuff2); | ||
@@ -78,8 +87,11 @@ | ||
HandshakeInitializationPacket.prototype.scrambleBuff = function() { | ||
var buffer = new Buffer(this.scrambleBuff1.length + this.scrambleBuff2.length); | ||
var buffer = new Buffer(this.scrambleBuff1.length + | ||
(typeof this.scrambleBuff2 != "undefined" ? this.scrambleBuff2.length : 0)); | ||
this.scrambleBuff1.copy(buffer); | ||
this.scrambleBuff2.copy(buffer, this.scrambleBuff1.length); | ||
if (typeof this.scrambleBuff2 != "undefined") { | ||
this.scrambleBuff2.copy(buffer, this.scrambleBuff1.length); | ||
} | ||
return buffer; | ||
}; |
module.exports = OkPacket; | ||
function OkPacket() { | ||
function OkPacket(options) { | ||
options = options || {}; | ||
this.fieldCount = undefined; | ||
@@ -9,2 +11,3 @@ this.affectedRows = undefined; | ||
this.message = undefined; | ||
this.protocol41 = options.protocol41; | ||
} | ||
@@ -16,4 +19,6 @@ | ||
this.insertId = parser.parseLengthCodedNumber(); | ||
this.serverStatus = parser.parseUnsignedNumber(2); | ||
this.warningCount = parser.parseUnsignedNumber(2); | ||
if (this.protocol41) { | ||
this.serverStatus = parser.parseUnsignedNumber(2); | ||
this.warningCount = parser.parseUnsignedNumber(2); | ||
} | ||
this.message = parser.parsePacketTerminatedString(); | ||
@@ -33,5 +38,7 @@ this.changedRows = 0; | ||
writer.writeLengthCodedNumber(this.insertId || 0); | ||
writer.writeUnsignedNumber(2, this.serverStatus || 0); | ||
writer.writeUnsignedNumber(2, this.warningCount || 0); | ||
if (this.protocol41) { | ||
writer.writeUnsignedNumber(2, this.serverStatus || 0); | ||
writer.writeUnsignedNumber(2, this.warningCount || 0); | ||
} | ||
writer.writeString(this.message); | ||
}; |
@@ -13,3 +13,3 @@ var Types = require('../constants/types'); | ||
var next = function () { | ||
return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers); | ||
return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings); | ||
}; | ||
@@ -25,3 +25,3 @@ | ||
value = (typeCast) | ||
? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers) | ||
? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings) | ||
: ( (fieldPacket.charsetNr === Charsets.BINARY) | ||
@@ -43,3 +43,5 @@ ? parser.parseLengthCodedBuffer() | ||
RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBigNumbers) { | ||
RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBigNumbers, bigNumberStrings) { | ||
var numberString; | ||
switch (field.type) { | ||
@@ -51,2 +53,4 @@ case Types.TIMESTAMP: | ||
var dateString = parser.parseLengthCodedString(); | ||
var dt; | ||
if (dateString === null) { | ||
@@ -64,3 +68,8 @@ return null; | ||
return new Date(dateString); | ||
dt = new Date(dateString); | ||
if (isNaN(dt.getTime())) { | ||
return dateString; | ||
} | ||
return dt; | ||
case Types.TINY: | ||
@@ -73,8 +82,11 @@ case Types.SHORT: | ||
case Types.DOUBLE: | ||
numberString = parser.parseLengthCodedString(); | ||
return (numberString === null || (field.zeroFill && numberString[0] == "0")) | ||
? numberString : Number(numberString); | ||
case Types.NEWDECIMAL: | ||
case Types.LONGLONG: | ||
case Types.NEWDECIMAL: | ||
var numberString = parser.parseLengthCodedString(); | ||
numberString = parser.parseLengthCodedString(); | ||
return (numberString === null || (field.zeroFill && numberString[0] == "0")) | ||
? numberString | ||
: ((supportBigNumbers && Number(numberString) > IEEE_754_BINARY_64_PRECISION) | ||
: ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > IEEE_754_BINARY_64_PRECISION))) | ||
? numberString | ||
@@ -81,0 +93,0 @@ : Number(numberString)); |
@@ -314,3 +314,3 @@ var IEEE_754_BINARY_64_PRECISION = Math.pow(2, 53); | ||
return parseGeometry(); | ||
} | ||
}; | ||
@@ -317,0 +317,0 @@ Parser.prototype.reachedPacketEnd = function() { |
@@ -25,2 +25,3 @@ var Parser = require('./Parser'); | ||
this._handshakeSequence = null; | ||
this._handshaked = false; | ||
this._destroyed = false; | ||
@@ -147,3 +148,5 @@ this._queue = []; | ||
var Packet = this._determinePacket(sequence); | ||
var packet = new Packet(); | ||
var packet = new Packet({ | ||
protocol41: this._config.protocol41 | ||
}); | ||
@@ -180,3 +183,3 @@ // Special case: Faster dispatch, and parsing done inside sequence | ||
if (this._config.debug) { | ||
this._debugPacket(false, packet) | ||
this._debugPacket(false, packet); | ||
} | ||
@@ -196,3 +199,8 @@ }; | ||
switch (firstByte) { | ||
case 0x00: return Packets.OkPacket; | ||
case 0x00: | ||
if (!this._handshaked) { | ||
this._handshaked = true; | ||
this.emit('handshake'); | ||
} | ||
return Packets.OkPacket; | ||
case 0xfe: return Packets.EofPacket; | ||
@@ -234,3 +242,3 @@ case 0xff: return Packets.ErrorPacket; | ||
if (sequence) { | ||
sequence.end(err) | ||
sequence.end(err); | ||
} else { | ||
@@ -298,2 +306,7 @@ this._delegateError(err); | ||
// check for debug packet restriction | ||
if (Array.isArray(this._config.debug) && this._config.debug.indexOf(packet.constructor.name) === -1) { | ||
return; | ||
} | ||
console.log(headline); | ||
@@ -300,0 +313,0 @@ console.log(packet); |
@@ -32,2 +32,4 @@ var Sequence = require('./Sequence'); | ||
this._config.protocol41 = packet.protocol41; | ||
this.emit('packet', new Packets.ClientAuthenticationPacket({ | ||
@@ -38,4 +40,7 @@ clientFlags : this._config.clientFlags, | ||
user : this._config.user, | ||
scrambleBuff : Auth.token(this._config.password, packet.scrambleBuff()), | ||
scrambleBuff : (packet.protocol41) | ||
? Auth.token(this._config.password, packet.scrambleBuff()) | ||
: Auth.scramble323(packet.scrambleBuff(), this._config.password), | ||
database : this._config.database, | ||
protocol41 : packet.protocol41 | ||
})); | ||
@@ -42,0 +47,0 @@ }; |
@@ -7,2 +7,3 @@ var Sequence = require('./Sequence'); | ||
var fs = require('fs'); | ||
var Readable = require('stream').Readable; | ||
@@ -38,2 +39,5 @@ module.exports = Query; | ||
// See: https://github.com/felixge/node-mysql/issues/222 | ||
} else if (this._resultSet && this._resultSet.resultSetHeaderPacket | ||
&& this._resultSet.resultSetHeaderPacket.fieldCount !== null) { | ||
return Packets.FieldPacket; | ||
} else { | ||
@@ -166,1 +170,33 @@ return; | ||
}; | ||
Query.prototype.stream = function(options) { | ||
var self = this, | ||
stream; | ||
options = options || {}; | ||
options.objectMode = true; | ||
stream = new Readable(options), | ||
stream._read = function() { | ||
self._connection.resume(); | ||
}; | ||
this.on('result',function(row,i) { | ||
if (!stream.push(row)) self._connection.pause(); | ||
stream.emit('result',row,i); // replicate old emitter | ||
}); | ||
this.on('error',function(err) { | ||
stream.emit('error',err); // Pass on any errors | ||
}); | ||
this.on('end', function() { | ||
stream.push(null); // pushing null, indicating EOF | ||
}); | ||
this.on('fields',function(fields,i) { | ||
stream.emit('fields',fields,i); // replicate old emitter | ||
}); | ||
return stream; | ||
}; |
@@ -15,3 +15,3 @@ var Util = require('util'); | ||
// Experimental: Long stack trace support | ||
this._callSite = (new Error).stack.replace(/.+\n/, ''); | ||
this._callSite = new Error; | ||
} | ||
@@ -45,3 +45,3 @@ | ||
err.stack += delimiter + this._callSite; | ||
err.stack += delimiter + this._callSite.stack.replace(/.+\n/, ''); | ||
}; | ||
@@ -48,0 +48,0 @@ |
@@ -64,3 +64,3 @@ var SqlString = exports; | ||
return sql.replace(/\?/g, function(match) { | ||
return sql.replace(/\?\??/g, function(match) { | ||
if (!values.length) { | ||
@@ -70,2 +70,5 @@ return match; | ||
if (match == "??") { | ||
return SqlString.escapeId(values.shift()); | ||
} | ||
return SqlString.escape(values.shift(), false, timeZone); | ||
@@ -72,0 +75,0 @@ }); |
@@ -5,5 +5,6 @@ { | ||
"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-alpha7", | ||
"version": "2.0.0-alpha8", | ||
"repository": { | ||
"url": "" | ||
"type": "git", | ||
"url": "https://github.com/felixge/node-mysql" | ||
}, | ||
@@ -10,0 +11,0 @@ "main": "./index", |
@@ -8,3 +8,3 @@ # node-mysql | ||
```bash | ||
npm install mysql@2.0.0-alpha7 | ||
npm install mysql@2.0.0-alpha8 | ||
``` | ||
@@ -19,3 +19,3 @@ | ||
``` | ||
npm install git://github.com/felixge/node-mysql.git | ||
npm install felixge/node-mysql | ||
``` | ||
@@ -81,3 +81,3 @@ | ||
* [pinkbike.com](http://pinkbike.com/) | ||
* [Holiday Extras](http://www.holidayextras.co.uk/) (they are [hiring](http://join.holidayextras.co.uk/vacancy/senior-web-technologist/)) | ||
* [Holiday Extras](http://www.holidayextras.co.uk/) (they are [hiring](http://join.holidayextras.co.uk/vacancy/software-engineer/)) | ||
* [Newscope](http://newscope.com/) (they are [hiring](http://www.newscope.com/stellenangebote)) | ||
@@ -88,3 +88,3 @@ | ||
[get in touch]: http://felixge.de/consulting | ||
[get in touch]: http://felixge.de/#consulting | ||
@@ -152,3 +152,10 @@ ## Community | ||
* `queryFormat`: A custom query format function. See [Custom format](#custom-format). | ||
* `supportBigNumbers`: When dealing with big numbers in the database, you should enable this option. | ||
* `supportBigNumbers`: When dealing with big numbers (BIGINT and DECIMAL columns) in the database, | ||
you should enable this option (Default: `false`). | ||
* `bigNumberStrings`: Enabling both `supportBigNumbers` and `bigNumberStrings` forces big numbers | ||
(BIGINT and DECIMAL columns) to be always returned as JavaScript String objects (Default: `false`). | ||
Enabling `supportBigNumbers` but leaving `bigNumberStrings` disabled will return big numbers as String | ||
objects only when they cannot be accurately represented with [JavaScript Number objects] (http://ecma262-5.com/ELS5_HTML.htm#Section_8.5) | ||
(which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as | ||
Number objects. This option is ignored if `supportBigNumbers` is disabled. | ||
* `debug`: Prints protocol details to stdout. (Default: `false`) | ||
@@ -405,5 +412,14 @@ * `multipleStatements`: Allow multiple mysql statements per query. Be careful | ||
When you pass an Object to `.escape()` or `.query()`, `.escapeId()` is used to avoid SQL | ||
injection in object keys. | ||
Alternatively, you can use `??` characters as placeholders for identifiers you would | ||
like to have escaped like this: | ||
```js | ||
connection.query('SELECT * FROM ?? WHERE id = ?', ['users', userId], function(err, results) { | ||
// ... | ||
}); | ||
``` | ||
**Please note that this last character sequence is experimental and syntax might change** | ||
When you pass an Object to `.escape()` or `.query()`, `.escapeId()` is used to avoid SQL injection in object keys. | ||
### Custom format | ||
@@ -498,2 +514,20 @@ | ||
### Piping results with [Streams2](http://blog.nodejs.org/2012/12/20/streams2/) (Node v0.10+) | ||
The query object provides a convenience method `.stream([options])` that wraps | ||
query events into a [Readable](http://nodejs.org/api/stream.html#stream_class_stream_readable) | ||
Streams2 object. This stream can easily be piped downstream and provides | ||
automatic pause/resume, based on downstream congestion and the optional | ||
`highWaterMark`. The `objectMode` parameter of the stream is set to `true` by | ||
default. | ||
For example, piping query results into another stream (with a max buffer of 5 | ||
objects) is simply: | ||
```js | ||
connection.query('SELECT * FROM posts') | ||
.stream({highWaterMark: 5}) | ||
.pipe(...); | ||
``` | ||
## Multiple statement queries | ||
@@ -815,4 +849,11 @@ | ||
This will print all incoming and outgoing packets on stdout. | ||
This will print all incoming and outgoing packets on stdout. You can also restrict debugging to | ||
packet types by passing an array of types to debug: | ||
```js | ||
var connection = mysql.createConnection({debug: ['ComQueryPacket', 'RowDataPacket']}); | ||
``` | ||
to restrict debugging to the query and data packets. | ||
If that does not help, feel free to open a GitHub issue. A good GitHub issue | ||
@@ -819,0 +860,0 @@ will have: |
@@ -58,4 +58,6 @@ // An experimental fake MySQL server for tricky integration tests. Expanded | ||
this._handshakeInitializationPacket = new Packets.HandshakeInitializationPacket({ | ||
scrambleBuff1: new Buffer(8), | ||
scrambleBuff2: new Buffer(12), | ||
scrambleBuff1 : new Buffer(8), | ||
scrambleBuff2 : new Buffer(12), | ||
serverCapabilities1 : 512, // only 1 flag, PROTOCOL_41 | ||
protocol41 : true | ||
}); | ||
@@ -62,0 +64,0 @@ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
236098
5.88%127
1.6%5559
5.07%864
4.98%24
-4%3
-25%