Skip to content

How to use a literal ? in a formatted query? #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JonathanHolvey opened this issue Jul 23, 2021 · 1 comment
Closed

How to use a literal ? in a formatted query? #63

JonathanHolvey opened this issue Jul 23, 2021 · 1 comment
Labels

Comments

@JonathanHolvey
Copy link

If I use the format function on a query that contains a literal ? this gets replaced, as per the documentation. How can I escape the ? character so it doesn't get replaced?

const { format }  = require('sqlstring')

format(`select * from mytable where foo = 'https://example.com?a=b' and bar = ?`, ['xyz'])

The resulting output from this would be

select * from mytable where foo = 'https://example.com'xyz'a=b' and bar = ?

whereas I want

select * from mytable where foo = 'https://example.com?a=b' and bar = 'xyz'
@dougwilson
Copy link
Member

You need to just put it as an argument. The ? Syntax is a copy from mysql placeholder syntax, which also has no way to escape it. Example:

const { format }  = require('sqlstring')

format(`select * from mytable where foo = ? and bar = ?`, ['https://example.com?a=b', 'xyz'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants