Skip to content

Commit 7ee4323

Browse files
authored
Merge pull request #1420 from sidorares/typecast-json-regression
Typecast json regression fix
2 parents 6c29e36 + aeae38e commit 7ee4323

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/parsers/text_parser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ function compile(fields, options, config) {
119119
return _this.packet.parseGeometryValue();
120120
},
121121
readNext: function() {
122-
return _this.${readCode};
122+
const packet = _this.packet;
123+
return ${readCode};
123124
}
124125
};`);
125126
}

test/integration/connection/test-typecast.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const common = require('../../common');
44
const connection = common.createConnection();
55
const assert = require('assert');
66

7+
connection.query('CREATE TEMPORARY TABLE json_test (json_test JSON)');
8+
connection.query('INSERT INTO json_test VALUES (?)', JSON.stringify({ test: 42 }));
9+
710
connection.query(
811
{
912
sql: 'select "foo uppercase" as foo',
@@ -46,4 +49,31 @@ connection.query(
4649
}
4750
);
4851

52+
53+
connection.query(
54+
{
55+
sql: 'SELECT * from json_test',
56+
typeCast: function(_field, next) {
57+
return next();
58+
}
59+
},
60+
(err, _rows) => {
61+
assert.ifError(err);
62+
assert.equal(_rows[0].json_test.test, 42);
63+
}
64+
);
65+
66+
connection.execute(
67+
{
68+
sql: 'SELECT * from json_test',
69+
typeCast: function(_field, next) {
70+
return next();
71+
}
72+
},
73+
(err, _rows) => {
74+
assert.ifError(err);
75+
assert.equal(_rows[0].json_test.test, 42);
76+
}
77+
);
78+
4979
connection.end();

0 commit comments

Comments
 (0)