Skip to content

Commit

Permalink
misc - 2.5.6 correction merge
Browse files Browse the repository at this point in the history
  • Loading branch information
diego Dupin committed Jan 24, 2022
1 parent c7e12e1 commit 3cd34b8
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 53 deletions.
16 changes: 8 additions & 8 deletions lib/cmd/column-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ColumnDef {
case FieldType.JSON:
//for mysql only => parse string as JSON object
return (packet, index, nullBitmap, opts) =>
isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLength());
isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLengthEncoded());

case FieldType.BIT:
if (this.columnLength === 1 && opts.bitOneIsBoolean) {
Expand All @@ -164,7 +164,7 @@ class ColumnDef {
default:
if (this.dataTypeFormat && this.dataTypeFormat === 'json' && opts.autoJsonMap) {
return (packet, index, nullBitmap, opts) =>
isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLength());
isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLengthEncoded());
}

if (this.collation.index === 63) {
Expand All @@ -175,12 +175,12 @@ class ColumnDef {
if (this.isSet()) {
return (packet, index, nullBitmap, opts) => {
if (isNullBitmap(index, nullBitmap)) return null;
const string = packet.readStringLength();
const string = packet.readStringLengthEncoded();
return string == null ? null : string === '' ? [] : string.split(',');
};
}
return (packet, index, nullBitmap, opts) =>
isNullBitmap(index, nullBitmap) ? null : packet.readStringLength();
isNullBitmap(index, nullBitmap) ? null : packet.readStringLengthEncoded();
}
} else {
switch (this.columnType) {
Expand Down Expand Up @@ -246,7 +246,7 @@ class ColumnDef {

case FieldType.JSON:
//for mysql only => parse string as JSON object
return (packet, index, nullBitmap, opts) => JSON.parse(packet.readStringLength());
return (packet, index, nullBitmap, opts) => JSON.parse(packet.readStringLengthEncoded());

case FieldType.BIT:
if (this.columnLength === 1 && opts.bitOneIsBoolean) {
Expand All @@ -259,7 +259,7 @@ class ColumnDef {

default:
if (this.dataTypeFormat && this.dataTypeFormat === 'json' && opts.autoJsonMap) {
return (packet, index, nullBitmap, opts) => JSON.parse(packet.readStringLength());
return (packet, index, nullBitmap, opts) => JSON.parse(packet.readStringLengthEncoded());
}

if (this.collation.index === 63) {
Expand All @@ -268,11 +268,11 @@ class ColumnDef {

if (this.isSet()) {
return (packet, index, nullBitmap, opts) => {
const string = packet.readStringLength();
const string = packet.readStringLengthEncoded();
return string == null ? null : string === '' ? [] : string.split(',');
};
}
return (packet, index, nullBitmap, opts) => packet.readStringLength();
return (packet, index, nullBitmap, opts) => packet.readStringLengthEncoded();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/cmd/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class Command extends EventEmitter {
switch (type) {
case StateChange.SESSION_TRACK_SYSTEM_VARIABLES:
const subSubPacket = subPacket.subPacketLengthEncoded();
const variable = subSubPacket.readStringLength();
const value = subSubPacket.readStringLength();
const variable = subSubPacket.readStringLengthEncoded();
const value = subSubPacket.readStringLengthEncoded();

switch (variable) {
case 'character_set_client':
Expand All @@ -149,7 +149,7 @@ class Command extends EventEmitter {

case StateChange.SESSION_TRACK_SCHEMA:
const subSubPacket2 = subPacket.subPacketLengthEncoded();
info.database = subSubPacket2.readStringLength();
info.database = subSubPacket2.readStringLengthEncoded();
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/decoder/binary-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BinaryDecoder {
}

static castWrapper(column, packet, index, nullBitmap, opts) {
column.string = () => (isNullBitmap(index, nullBitmap) ? null : packet.readStringLength());
column.string = () => (isNullBitmap(index, nullBitmap) ? null : packet.readStringLengthEncoded());
column.buffer = () => (isNullBitmap(index, nullBitmap) ? null : packet.readBufferLengthEncoded());
column.float = () => (isNullBitmap(index, nullBitmap) ? null : packet.readFloat());
column.tiny = () =>
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/decoder/text-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class TextDecoder {
static castWrapper(column, packet, index, nullBitmap, opts) {
column.string = () => packet.readStringLength();
column.string = () => packet.readStringLengthEncoded();
column.buffer = () => packet.readBufferLengthEncoded();
column.float = () => packet.readFloatLengthCoded();
column.tiny = () => packet.readIntLengthEncoded();
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Parser extends Command {
* @returns {*} null or {Resultset.readResponsePacket} in case of multi-result-set
*/
readOKPacket(packet, out, opts, info) {
const okPacket = Command.parseOkPacket(packet, out, this.opts, info);
const okPacket = this.parseOkPacket(packet, out, this.opts, info);
this._rows.push(okPacket);

if (info.status & ServerStatus.MORE_RESULTS_EXISTS) {
Expand Down
2 changes: 1 addition & 1 deletion lib/io/packet-node-encoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PacketNodeEncoded extends Packet {
return new PacketNodeEncoded(this.encoding).update(this.buf, this.pos, this.end);
}

readStringLength() {
readStringLengthEncoded() {
const len = this.readUnsignedLength();
if (len === null) return null;

Expand Down
2 changes: 1 addition & 1 deletion lib/io/packet-node-iconv.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PacketIconvEncoded extends Packet {
return new PacketIconvEncoded(this.encoding).update(this.buf, this.pos, this.end);
}

readStringLength() {
readStringLengthEncoded() {
const len = this.readUnsignedLength();
if (len === null) return null;

Expand Down
17 changes: 2 additions & 15 deletions lib/io/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,8 @@ class Packet {
return this.buf.toString('ascii', this.pos - len, this.pos);
}

readStringLength() {
throw new Error(
'code is normally superseded by Node encoder or Iconv depending on charset used'
);
}

readStringLengthEncoded(encoding) {
const len = this.readUnsignedLength();
if (len === null) return null;

this.pos += len;
if (Buffer.isEncoding(encoding)) {
return this.buf.toString(encoding, this.pos - len, this.pos);
}
return Iconv.decode(this.buf.slice(this.pos - len, this.pos), encoding);
readStringLengthEncoded() {
throw new Error('code is normally superseded by Node encoder or Iconv depending on charset used');
}

readBigIntLengthEncoded() {
Expand Down
1 change: 1 addition & 0 deletions test/integration/test-call.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('stored procedure', () => {
done();
});
});
});

const testRes = async function (res) {
assert.equal(res.length, 2);
Expand Down
7 changes: 3 additions & 4 deletions test/integration/test-local-infile.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ describe('local-infile', () => {
"LOAD DATA LOCAL INFILE ? INTO TABLE smallLocalInfile FIELDS TERMINATED BY ',' (id, test)",
smallFileName
);
await conn.query(
"LOAD DATA LOCAL INFILE ? INTO TABLE smallLocalInfile FIELDS TERMINATED BY ',' (id, test)",
[smallFileName]
);
await conn.query("LOAD DATA LOCAL INFILE ? INTO TABLE smallLocalInfile FIELDS TERMINATED BY ',' (id, test)", [
smallFileName
]);

const rows2 = await conn.query('SELECT * FROM smallLocalInfile');
assert.deepEqual(rows2, [
Expand Down
10 changes: 2 additions & 8 deletions test/integration/test-pool-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,7 @@ describe('Pool callback', () => {
assert.equal(err.errno, 45028);
assert.equal(err.code, 'ER_GET_CONNECTION_TIMEOUT');
const elapse = Date.now() - initTime;
assert.isOk(
elapse >= 499 && elapse < 550,
'elapse time was ' + elapse + ' but must be just after 500'
);
assert.isOk(elapse >= 499 && elapse < 550, 'elapse time was ' + elapse + ' but must be just after 500');
errorNo += 1;
});
setTimeout(() => {
Expand All @@ -257,10 +254,7 @@ describe('Pool callback', () => {
assert.equal(err.errno, 45028);
assert.equal(err.code, 'ER_GET_CONNECTION_TIMEOUT');
const elapse = Date.now() - initTime;
assert.isOk(
elapse >= 698 && elapse < 750,
'elapse time was ' + elapse + ' but must be just after 700'
);
assert.isOk(elapse >= 698 && elapse < 750, 'elapse time was ' + elapse + ' but must be just after 700');
errorNo += 1;
});
}, 200);
Expand Down
12 changes: 2 additions & 10 deletions test/integration/test-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ describe('Pool', () => {
throw new Error('must have thrown error');
} catch (err) {
assert.isTrue(
err.errno === 1524 ||
err.errno === 1045 ||
err.errno === 1698 ||
err.errno === 45025 ||
err.errno === 45044,
err.errno === 1524 || err.errno === 1045 || err.errno === 1698 || err.errno === 45025 || err.errno === 45044,
err.message
);
}
Expand All @@ -269,11 +265,7 @@ describe('Pool', () => {
throw new Error('must have thrown error');
} catch (err) {
assert.isTrue(
err.errno === 1524 ||
err.errno === 1045 ||
err.errno === 1698 ||
err.errno === 45025 ||
err.errno === 45044,
err.errno === 1524 || err.errno === 1045 || err.errno === 1698 || err.errno === 45025 || err.errno === 45044,
err.message
);
} finally {
Expand Down

0 comments on commit 3cd34b8

Please sign in to comment.