Skip to content

Commit 1ee48cc

Browse files
authored
fix: pass columnType to readDateTimeString (#3700)
* fix: pass columnType to readDateTimeString See issue: #3699 * fix: pass columnType to readDateTimeString re-ran lint * fix: pass columnType to readDateTimeString New test added for DATETIME parsing * fix: pass columnType to readDateTimeString Also fix static_binary_parser.js
1 parent 59d60c2 commit 1ee48cc

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

lib/parsers/binary_parser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ function compile(fields, options, config) {
111111
field.columnType
112112
)
113113
) {
114-
return packet.readDateTimeString(parseInt(field.decimals, 10));
114+
return packet.readDateTimeString(
115+
parseInt(field.decimals, 10),
116+
' ',
117+
field.columnType
118+
);
115119
}
116120

117121
if (field.columnType === Types.TINY) {

lib/parsers/static_binary_parser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ function getBinaryParser(fields, _options, config) {
146146
].includes(field.columnType)
147147
) {
148148
return packet.readDateTimeString(
149-
parseInt(field.decimals, 10)
149+
parseInt(field.decimals, 10),
150+
' ',
151+
field.columnType
150152
);
151153
}
152154

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, assert } from 'poku';
2+
import { createRequire } from 'node:module';
3+
4+
const require = createRequire(import.meta.url);
5+
const {
6+
createConnection,
7+
describeOptions,
8+
} = require('../../../common.test.cjs');
9+
10+
const conn = createConnection({
11+
typeCast: (field) => field.string(),
12+
}).promise();
13+
14+
describe('typeCast field.datetime', describeOptions);
15+
16+
const query = {};
17+
const execute = {};
18+
19+
await conn.query('CREATE TEMPORARY TABLE `tmp_date` (`datetime` DATETIME)');
20+
21+
await conn.query('INSERT INTO `tmp_date` (`datetime`) VALUES (CURRENT_DATE())');
22+
23+
{
24+
const [date] = await conn.execute('SELECT datetime from tmp_date');
25+
26+
execute.date = date[0].datetime;
27+
}
28+
29+
{
30+
const [date] = await conn.query('SELECT datetime from tmp_date');
31+
32+
query.date = date[0].datetime;
33+
}
34+
35+
await conn.end();
36+
37+
assert.equal(execute.date, query.date, 'DATETIME');

0 commit comments

Comments
 (0)