|
| 1 | +import type { RowDataPacket } from '../../../index.js'; |
| 2 | +import { describe, it, strict } from 'poku'; |
| 3 | +import { createConnection } from '../../common.test.mjs'; |
| 4 | + |
| 5 | +await describe('dateStrings: binary protocol keeps the zero date of DATE/DATETIME/TIMESTAMP', async () => { |
| 6 | + const connection = createConnection({ dateStrings: true }).promise(); |
| 7 | + |
| 8 | + const [modes] = await connection.query<RowDataPacket[]>( |
| 9 | + 'SELECT @@sql_mode AS value' |
| 10 | + ); |
| 11 | + const relaxedMode = String(modes[0].value) |
| 12 | + .split(',') |
| 13 | + .filter((mode) => mode !== 'NO_ZERO_DATE' && mode !== 'NO_ZERO_IN_DATE') |
| 14 | + .join(','); |
| 15 | + |
| 16 | + await connection.query('SET sql_mode=?', [relaxedMode]); |
| 17 | + await connection.query( |
| 18 | + 'CREATE TEMPORARY TABLE zero_dates (d DATE, dt DATETIME, ts TIMESTAMP NULL)' |
| 19 | + ); |
| 20 | + await connection.query( |
| 21 | + "INSERT INTO zero_dates VALUES ('0000-00-00', '0000-00-00 00:00:00', '0000-00-00 00:00:00')" |
| 22 | + ); |
| 23 | + |
| 24 | + const [rows] = await connection.execute<RowDataPacket[]>( |
| 25 | + 'SELECT * FROM zero_dates' |
| 26 | + ); |
| 27 | + |
| 28 | + await it('returns the zero DATETIME and TIMESTAMP as strings', () => { |
| 29 | + strict.equal(rows[0].dt, '0000-00-00 00:00:00'); |
| 30 | + strict.equal(rows[0].ts, '0000-00-00 00:00:00'); |
| 31 | + }); |
| 32 | + |
| 33 | + await it('returns the zero DATE as a string', () => { |
| 34 | + strict.equal(rows[0].d, '0000-00-00'); |
| 35 | + }); |
| 36 | + |
| 37 | + await connection.end(); |
| 38 | +}); |
0 commit comments