adoublefA
Denoβ€’3y agoβ€’
2 replies
adoublef

denodrivers/sqlite and deno-sqlit behave different with multiple `?` args

I wanted to understand why these return different results

Deno.test("DB()", (_) => {
    // deno-sqlite
    const db = new DB(":memory:");

    const stmt = db.prepareQuery("SELECT ?, ?");

    const rs = stmt.all(["one", "two"]);
    //    ^? [ [ "one", "two" ] ]

    stmt.finalize();

    db.close();
});

Deno.test("Database() ? arguments", (_) => {
    // denodrivers/sqlite
    const db = new Database(":memory:");

    const stmt = db.prepare("SELECT ?, ?");

    const rs = stmt.all("one", "two");
    //    ^? [ { "?": "two" } ]

    stmt.finalize();
    db.close();
});

Deno.test("Database() : arguments", (_) => {
    // denodrivers/sqlite
    const db = new Database(":memory:");

    const stmt = db.prepare("SELECT :one, :two");

    const rs = stmt.all({ one: "one", two: "two" });
    //    ^? [ { ":one": "one", ":two": "two" } ]
    console.log(rs);

    stmt.finalize();
    db.close();
});


If I replace the denodrivers prepare statement to use named args I get correctly two values so unsure which method is needed to be called to get both to behave consistently
Was this page helpful?