mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.22k stars 2.53k forks source link

Incompatibility with Node MySQL, mysql2 nodejs pass table name as variable / right syntax to use near '??' #2530

Closed dragonfire2018 closed 2 years ago

dragonfire2018 commented 2 years ago

Please see here https://stackoverflow.com/questions/69716876/mysql2-nodejs-pass-table-name-as-variable-right-syntax-to-use-near?noredirect=1#comment123231095_69716876

The use of variable for table name is not working

tableName = "some_table"
id = "some_id";

const readForwardedMessageDetails = pool.execute('SELECT * FROM ?? WHERE `id` = ? LIMIT 1',
        [tableName, id],
        function(err, row) {
            if (err) {
                console.log(err)
                return
            } else {

            }

            code: 'ER_PARSE_ERROR',
                errno: 1064,
                sqlState: '42000',
                sqlMessage: "You have an error in your SQL syntax; check the manual 
            that corresponds to your MariaDB server version
            for the right syntax to use
            near '?? WHERE `id` = ? LIMIT 1'
            at line 1 ",
            sql: 'SELECT * FROM ?? WHERE `id` = ? LIMIT 1'
dougwilson commented 2 years ago

Hello, sorry for your issue, but you issue is unrelated to this module. You are using a module named mysql2, which is different from this one.

dragonfire2018 commented 2 years ago

sorry posted accidentally... have reposted to mysql2....