Skip to content

MySQL2 returns empty buffer for null binary value, MySQL returns null #668

Closed

Description

@MikeEmery

The behavior of MySQL2 differs from MySQL in how it deals with binary columns. If you have a nullable binary column and select it with MySQL, then it will return the value as null. MySQL2 will return the value as an empty buffer.

/**
 * CREATE DATABASE buffer_issue;
 * CREATE TABLE binary_table (stuff BINARY(16));
 * INSERT INTO binary_table VALUES(null);
 */

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

const connectionOptions = {
  host: 'localhost',
  user: 'root',
  database: 'buffer_issue'
};

const conn1 = mysql.createConnection(connectionOptions);
const conn2 = mysql2.createConnection(connectionOptions);

conn1.query('select * from binary_table', function(err, result, fields) {
  console.log('conn1 result:', err, result);
});

conn2.query('select * from binary_table', function(err, result, fields) {
  console.log('conn2 result:', err, result);
});
npm start
> node index.js

conn1 result: null [ RowDataPacket { stuff: null } ]
conn2 result: null [ TextRow { stuff: <Buffer > } ]

Activity

  1. sidorares commented on Nov 3, 2017

    @sidorares
    Owner

    Thanks for detail report @MikeEmery ! I think I know what causes that

  2. added a commit that references this issue on Nov 19, 2017
    0059e66
  3. added a commit that references this issue on Nov 19, 2017
    a43e8da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions