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

node:sqlite StatementSync.run() fails if named parameters are provided out of order with the statement's SQL. #28183

Closed
james-Ballyhoo opened this issue Feb 19, 2025 · 0 comments · Fixed by #28197
Labels
node:sqlite Issues related to the `node:sqlite` module

Comments

@james-Ballyhoo
Copy link

Version: Deno 2.2.0

Deno throws the following error:

error: Uncaught (in promise) Error: Failed to step statement
  insert.run({ val:'hello', key: 1 });
         ^

for the following example using named parameters:

import { DatabaseSync } from 'node:sqlite';

const database = new DatabaseSync(':memory:');

// Execute SQL statements from strings.
database.exec(`
    CREATE TABLE data(
      key INTEGER PRIMARY KEY,
      value TEXT
    ) STRICT
  `);
  // Create a prepared statement to insert data into the database.
  const insert = database.prepare('INSERT INTO data (key, value) VALUES (:key, :val)');
  // Execute the prepared statement with bound values.
  insert.run({ key: 2, val:'world'});

  insert.run({ val:'hello', key: 1 }); // Problem occurs here

  // Create a prepared statement to read data from the database.
  const query = database.prepare('SELECT * FROM data ORDER BY key');
  // Execute the prepared statement and log the result set.
  console.log(query.all());

If the line in question is altered to insert.run({ key: 1, val:'hello', }); match the named parameter order of the query it functions as expected, showing the following in the terminal:

[
  [Object: null prototype] { key: 1, value: "hello" },
  [Object: null prototype] { key: 2, value: "world" }
]

Have tested the exact same code in Node 22.13, and it accepts the named parameters object having the keys out of order and returns as expected on the terminal.

@marvinhagemeister marvinhagemeister added the node:sqlite Issues related to the `node:sqlite` module label Feb 19, 2025
littledivy added a commit to littledivy/deno that referenced this issue Feb 20, 2025
Allow bare named params and handle invalid param name.

Fixes denoland#28183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node:sqlite Issues related to the `node:sqlite` module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants