Skip to content

Column escaping is broken when using MySQL version 8.0.21  #1283

Closed
@dovidgef

Description

@dovidgef

As mentioned in the MySQL changelogs

It is possible to define a column named * (single asterisk character), but SELECT * was treated identically to SELECT *,
making it impossible to select only this column in a query; in other words, the asterisk character was expanded to a list
of all table columns even when it was surrounded by backticks. (Bug #30528450)

Now that its possible to quote the * character and use it as a column name,
automatic column name escaping is broken when using * as one of the columns being escaped.

Example

const mysql = require('mysql2');

// create the connection to database
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: 'test',
  database: 'test'
});

// simple query
connection.query(
  'SELECT ?? FROM ??',
  [['*'], 'testTable'],
  function(err, results, fields) {
    console.log(err);
    console.log(results); // results contains rows returned by server
  }
);

In version MySQL 8.0.21 this code throws the following error: Error: Unknown column '*' in 'field list'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions