Skip to content

Commit

Permalink
Fix booleans not being casted properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Sep 19, 2024
1 parent e175660 commit 19691a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cpp/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ inline void opsqlite_bind_statement(sqlite3_stmt *statement,
int sqIndex = ii + 1;
JSVariant value = values->at(ii);

if (std::holds_alternative<bool>(value) ||
std::holds_alternative<int>(value)) {
if (std::holds_alternative<bool>(value)) {
sqlite3_bind_int(statement, sqIndex,
static_cast<int>(std::get<bool>(value)));
} else if (std::holds_alternative<int>(value)) {
sqlite3_bind_int(statement, sqIndex, std::get<int>(value));
} else if (std::holds_alternative<long long>(value)) {
sqlite3_bind_double(statement, sqIndex,
Expand Down
7 changes: 6 additions & 1 deletion example/src/tests/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function queriesTests() {
await db.execute('DROP TABLE IF EXISTS T1;');
await db.execute('DROP TABLE IF EXISTS T2;');
await db.execute(
'CREATE TABLE User ( id INT PRIMARY KEY, name TEXT NOT NULL, age INT, networth REAL, nickname TEXT) STRICT;',
'CREATE TABLE User (id INT PRIMARY KEY, name TEXT NOT NULL, age INT, networth REAL, nickname TEXT) STRICT;',
);
} catch (e) {
console.error('error on before each', e);
Expand Down Expand Up @@ -85,6 +85,11 @@ export function queriesTests() {
expect(res.rows?.item).to.be.a('function');
});

it('Casts booleans to ints correctly', async () => {
await db.execute(`SELECT ?`, [1]);
await db.execute(`SELECT ?`, [true]);
});

it('Insert and query with host objects', async () => {
const id = chance.integer();
const name = chance.name();
Expand Down

0 comments on commit 19691a1

Please sign in to comment.