There was an error while loading. Please reload this page.
1 parent 09d0da9 commit 49fb028Copy full SHA for 49fb028
2 files changed
src/node_sqlite.cc
@@ -2780,10 +2780,11 @@ bool StatementSync::BindParams(const FunctionCallbackInfo<Value>& args) {
2780
2781
bool StatementSync::BindValue(const Local<Value>& value, const int index) {
2782
// SQLite only supports a subset of JavaScript types. Some JS types such as
2783
- // functions don't make sense to support. Other JS types such as booleans and
+ // functions don't make sense to support. Other JS types such as
2784
// Dates could be supported by converting them to numbers. However, there
2785
// would not be a good way to read the values back from SQLite with the
2786
- // original type.
+ // original type. JS Boolean binds to 1 and 0 because SQLite maps true and
2787
+ // false keywords to 1 and 0.
2788
Isolate* isolate = env()->isolate();
2789
int r;
2790
if (value->IsNumber()) {
@@ -2817,6 +2818,8 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
2817
2818
buf.data(),
2819
static_cast<sqlite3_uint64>(buf.length()),
2820
SQLITE_TRANSIENT);
2821
+ } else if (value->IsBoolean()) {
2822
+ r = sqlite3_bind_int(statement_, index, value->IsTrue() ? 1 : 0);
2823
} else if (value->IsBigInt()) {
2824
bool lossless;
2825
int64_t as_int = value.As<BigInt>()->Int64Value(&lossless);
test/parallel/test-sqlite-data-types.js
@@ -71,6 +71,15 @@ suite('data binding and mapping', () => {
71
text: '',
72
buf: new Uint8Array(),
73
});
74
+
75
+ t.assert.deepStrictEqual(
76
+ stmt.run(5, true, false, true, null),
77
+ { changes: 1, lastInsertRowid: 5 }
78
+ );
79
80
+ query.get(5),
81
+ { __proto__: null, key: 5, int: 1, double: 0, text: '1', buf: null }
82
83
84
85
test('large strings are bound correctly', (t) => {
0 commit comments