Skip to content
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

Escaped "?" (i.e. "\\?") not replaced with "?" when using raw #6011

Open
jvnlwn opened this issue Jan 5, 2024 · 0 comments · May be fixed by #5784
Open

Escaped "?" (i.e. "\\?") not replaced with "?" when using raw #6011

jvnlwn opened this issue Jan 5, 2024 · 0 comments · May be fixed by #5784
Labels

Comments

@jvnlwn
Copy link

jvnlwn commented Jan 5, 2024

Under Raw Parameter Binding, the docs say:

To prevent replacement of ? one can use the escape sequence \\?

The docs give this example:

knex.select('*')
  .from('users')
  .where('id', '=', 1)
  .whereRaw('?? \\? ?', ['jsonColumn', 'jsonKey'])

Expected behavior

The knex raw function should replace all escaped "\\?" with "?".

Actual behavior

But if you debug the result of that example, you'll see:

{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 1, 'jsonKey' ],
  __knexQueryUid: 'G2s8qdeLVgEWhFUNJwjgP',
  sql: 'select * from "users" where "id" = ? and "jsonColumn" \\? ?'
}

Notice that the escaped "\\?" left intact in the generated sql which will produce a syntax error.

Solution

Change this line to return "?".

@jvnlwn jvnlwn changed the title Escaped "?" (i.e. "\\\\?") not replaced with "?" when using raw Escaped "?" (i.e. "\\?") not replaced with "?" when using raw Jan 5, 2024
jvnlwn referenced this issue in jvnlwn/knex Jan 5, 2024
#knex/documentation/issues/566
@jvnlwn jvnlwn linked a pull request Jan 5, 2024 that will close this issue
@rluvaton rluvaton added website and removed website labels Jan 31, 2024
@rluvaton rluvaton transferred this issue from knex/documentation Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants