Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sqlite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export function Factory(Module) {
}
case 'string':
return sqlite3.bind_text(stmt, i, value);
case "boolean":
return sqlite3.bind_int(stmt, i, value ? 1 : 0);
default:
if (value instanceof Uint8Array || Array.isArray(value)) {
return sqlite3.bind_blob(stmt, i, value);
Expand Down
21 changes: 21 additions & 0 deletions test/api_statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,27 @@ export function api_statements(context) {
}
});

it('should bind boolean', async function() {
let rc;
const sql = 'SELECT ?';
const storeValue = true;
const expectedRetrievedValue = 1;

for await (const stmt of i(sqlite3.statements(db, sql))) {
// Comlink intercepts the 'bind' property so use an alias.
rc = await sqlite3.bind$(stmt, 1, storeValue);
expect(rc).toEqual(SQLite.SQLITE_OK);

while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
expect(rc).toEqual(SQLite.SQLITE_ROW);

expect(await sqlite3.column_count(stmt)).toEqual(1);
expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
expect(await sqlite3.column_int(stmt, 0)).toEqual(expectedRetrievedValue);
}
}
});
Comment on lines +241 to +260

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a test case with storeValue set to false to ensure that false boolean values are correctly bound as 0.

Suggested change
it('should bind boolean', async function() {
let rc;
const sql = 'SELECT ?';
const storeValue = true;
const expectedRetrievedValue = 1;
for await (const stmt of i(sqlite3.statements(db, sql))) {
// Comlink intercepts the 'bind' property so use an alias.
rc = await sqlite3.bind$(stmt, 1, storeValue);
expect(rc).toEqual(SQLite.SQLITE_OK);
while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
expect(rc).toEqual(SQLite.SQLITE_ROW);
expect(await sqlite3.column_count(stmt)).toEqual(1);
expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
expect(await sqlite3.column_int(stmt, 0)).toEqual(expectedRetrievedValue);
}
}
});
it('should bind boolean false', async function() {
let rc;
const sql = 'SELECT ?';
const storeValue = false;
const expectedRetrievedValue = 0;
for await (const stmt of i(sqlite3.statements(db, sql))) {
// Comlink intercepts the 'bind' property so use an alias.
rc = await sqlite3.bind$(stmt, 1, storeValue);
expect(rc).toEqual(SQLite.SQLITE_OK);
while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
expect(rc).toEqual(SQLite.SQLITE_ROW);
expect(await sqlite3.column_count(stmt)).toEqual(1);
expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
expect(await sqlite3.column_int(stmt, 0)).toEqual(expectedRetrievedValue);
}
}
});


it('should bind collection array', async function() {
let rc;
const sql = 'VALUES (?, ?, ?, ?, ?)';
Expand Down
Loading