mysqljs/mysql

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

dragonfire2018 opened this issue · 2 comments

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'

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.

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