Skip to content

Off-by-one error with supportBigNumbers #3597

@joanniclaborde

Description

@joanniclaborde

Hello,

I think I found an issue with the supportBigNumbers connection option. Running this quick test:

const mysql = require('mysql2/promise');

async function test() {
  const connection = await mysql.createConnection({uri: 'mysql://...', supportBigNumbers: true});
  const [results] = await connection.query(`
    SELECT
      -9007199254740993 AS 'MIN_SAFE_INTEGER - 2',
      -9007199254740992 AS 'MIN_SAFE_INTEGER - 1',
      -9007199254740991 AS 'MIN_SAFE_INTEGER',
      -9007199254740990 AS 'MIN_SAFE_INTEGER + 1',
      -9007199254740989 AS 'MIN_SAFE_INTEGER + 2',
       9007199254740989 AS 'MAX_SAFE_INTEGER - 2',
       9007199254740990 AS 'MAX_SAFE_INTEGER - 1',
       9007199254740991 AS 'MAX_SAFE_INTEGER',
       9007199254740992 AS 'MAX_SAFE_INTEGER + 1',
       9007199254740993 AS 'MAX_SAFE_INTEGER + 2'
  `);
  console.log(results[0]);
  connection.end();
}

test();

Results in the following:

{
  'MIN_SAFE_INTEGER - 2': '-9007199254740993',
  'MIN_SAFE_INTEGER - 1':  -9007199254740992, // Expecting this to be a string
  'MIN_SAFE_INTEGER':      -9007199254740991,
  'MIN_SAFE_INTEGER + 1':  -9007199254740990,
  'MIN_SAFE_INTEGER + 2':  -9007199254740989,
  'MAX_SAFE_INTEGER - 2':   9007199254740989,
  'MAX_SAFE_INTEGER - 1':   9007199254740990,
  'MAX_SAFE_INTEGER':       9007199254740991,
  'MAX_SAFE_INTEGER + 1':   9007199254740992, // Expecting this to be a string
  'MAX_SAFE_INTEGER + 2':  '9007199254740993'
}

Given the values of Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER, shouldn't the values highlighted above be strings?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions