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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: "D1_ERROR: Wrong number of parameter bindings" for queries with mixed ordered and anonymous parameters #5815

Open
Tao-VanJS opened this issue May 13, 2024 · 0 comments
Labels
bug Something that isn't working

Comments

@Tao-VanJS
Copy link

Which Cloudflare product(s) does this pertain to?

D1

What version(s) of the tool(s) are you using?

3.55.0 [wrangler]

What version of Node are you using?

No response

What operating system and version are you using?

Mac Sonoma 14.1.1

Describe the Bug

Observed behavior

This the the minimal code to demonstrate the issue:

const stmt = env.DB.prepare(`UPDATE table SET column1 = ?, column2 = ? WHERE id = ?1`)
await stmt.bind(id, value1, value2).run()

The code above will get the following error:

D1_ERROR: Wrong number of parameter bindings for SQL

If we change the code above to this way:

const stmt = env.DB.prepare(`UPDATE table SET column1 = ?, column2 = ? WHERE id = ?`)
await stmt.bind(value1, value2, id).run()

Then the statement can be executed.

Also, we noticed ordered parameters can be mixed with anonymous parameters as long as anonymous parameters are after all the ordered parameters. For instance, this query can be executed successfully:

const query = env.DB.prepare(`SELECT * FROM table WHERE id = ?1 AND column1 = ? AND column2 = ?`)
await query.bind(id, value1, value2).all()

Expected behavior

We expect queries with mixed ordered and anonymous parameters should be able to execute without any problems. In the bindings, we can bind ordered parameters first, and then anonymous parameters, regardless of how they appear in the query.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

@Tao-VanJS Tao-VanJS added the bug Something that isn't working label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Untriaged
Development

No branches or pull requests

1 participant