Skip to content

Error "Too many parameter values were provided" when using bind parameter syntax ?1, ?2 #576

@DanielSWolf

Description

@DanielSWolf

According to the SQLite documentation, there are five different ways of referencing bind parameters in an SQL statement:

  1. ?, ?
  2. ?1, ?2
  3. :first, :second
  4. @first, @second
  5. $first, $second

It seems that better-sqlite3 supports the 1st and 5th syntax, but not the 2nd one:

const Database = require('better-sqlite3');

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

// This works:
const statement1 = database.prepare('select ? + ?');
console.log(statement1.get(10, 20));

// This works, too:
const statement2 = database.prepare('select $first + $second');
console.log(statement2.get({ first: 10, second: 20 }));

// This throws an error:
const statement3 = database.prepare('select ?1 + ?2');
console.log(statement3.get(10, 20));

The last statement throws the following error:

RangeError: Too many parameter values were provided

Is there any chance of getting this syntax to work?

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