Skip to content

Commit 675ab6e

Browse files
authored
Merge pull request #1423 from testn/fix-coldef-db
ColumnDefinition.db is broken when encoding is not utf-8
2 parents a3a34fb + 9496e71 commit 675ab6e

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/packets/column_definition.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ class ColumnDefinition {
103103

104104
// node-mysql compatibility: alias "db" to "schema"
105105
get db() {
106-
const start = this._schemaStart;
107-
const end = start._shemaLength;
108-
return this._buf.utf8Slice(start, end);
106+
return this.schema;
109107
}
110108
}
111109

test/unit/packets/test-column-definition.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,28 @@ assert.equal(
5252
);
5353

5454
// Spec (from example: https://dev.mysql.com/doc/internals/en/protocoltext-resultset.html)
55-
packet = ColumnDefinition.toPacket(
56-
{
57-
catalog: 'def',
58-
schema: '',
59-
name: '@@version_comment',
60-
orgName: '',
61-
table: '',
62-
orgTable: '',
55+
const inputColDef = {
56+
catalog: 'def',
57+
schema: '',
58+
name: '@@version_comment',
59+
orgName: '',
60+
table: '',
61+
orgTable: '',
6362

64-
characterSet: 0x08, // latin1_swedish_ci
65-
columnLength: 0x1c,
66-
flags: 0,
67-
columnType: 0xfd,
68-
decimals: 0x1f
69-
},
70-
sequenceId
71-
);
63+
characterSet: 0x08, // latin1_swedish_ci
64+
columnLength: 0x1c,
65+
flags: 0,
66+
columnType: 0xfd,
67+
decimals: 0x1f
68+
}
69+
packet = ColumnDefinition.toPacket(inputColDef, sequenceId);
7270
assert.equal(
7371
packet.buffer.toString('hex', 4),
7472
'0364656600000011404076657273696f6e5f636f6d6d656e74000c08001c000000fd00001f0000'
7573
);
74+
75+
packet.offset = 4;
76+
const colDef = new ColumnDefinition(packet, "utf8");
77+
const inspect = colDef.inspect();
78+
assert.deepEqual(inspect, inputColDef);
79+
assert.equal(colDef.db, inputColDef.schema);

0 commit comments

Comments
 (0)