Skip to content

Question mark params not being replaced in runSql #19

@cullylarson

Description

@cullylarson

I have some code like this:

db.runSql('INSERT INTO authGroups (id, isActive, isLocked, name, description, created) VALUES(?, TRUE, TRUE, ?, ?, NOW())', [id, name, description])

I expect that the question marks in sql will be replaced with the values from params (as the documentation describes). But the sql is being run with the question marks still there. I'm getting this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, TRUE, TRUE, ?, ?, NOW())'

These are the values of id, name, description:

id: '4dfad450-7c17-11e9-8808-0242ac170002'
name: 'Users'
description: 'Test.'

Btw, I'm using promises, not the callback function.

What's strange is if I add a callback function as the third parameter, the placeholders are replaced. This seems like a bug.

If I use this function instead of db.runSql, it works fine:

const runSql = (db, query, params) => new Promise((resolve, reject) => {
    db.runSql(query, params, (err, data) => {
        if(err) reject(err)
        else resolve(data)
    })
})

For example:

runSql(db, 'INSERT INTO authGroups (id, isActive, isLocked, name, description, created) VALUES(?, TRUE, TRUE, ?, ?, NOW())', [id, name, description])

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

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