adoublef
adoublef2y ago

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();
});
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
1 Reply
adoublef
adoublefOP2y ago
From the above its clear that the ? is overidden and therefore only one of them get's returned. I am not sure if this is something that could be tackled or if it's even necessary as it isn't exactly a meanigful statement Solved, found there is a method called values that returns the results in array list form