| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2780,10 +2780,11 @@ bool StatementSync::BindParams(const FunctionCallbackInfo<Value>& args) { | |||
| 2780 | 2780 | ||
| 2781 | 2781 | bool StatementSync::BindValue(const Local<Value>& value, const int index) { | |
| 2782 | 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 | ||
| 2783 | + // functions don't make sense to support. Other JS types such as | ||
| 2784 | 2784 | // Dates could be supported by converting them to numbers. However, there | |
| 2785 | 2785 | // would not be a good way to read the values back from SQLite with the | |
| 2786 | - // original type. | ||
| 2786 | + // original type. JS Boolean binds to 1 and 0 because SQLite maps true and | ||
| 2787 | + // false keywords to 1 and 0. | ||
| 2787 | 2788 | Isolate* isolate = env()->isolate(); | |
| 2788 | 2789 | int r; | |
| 2789 | 2790 | if (value->IsNumber()) { | |
@@ -2817,6 +2818,8 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) { | |||
| 2817 | 2818 | buf.data(), | |
| 2818 | 2819 | static_cast<sqlite3_uint64>(buf.length()), | |
| 2819 | 2820 | SQLITE_TRANSIENT); | |
| 2821 | + } else if (value->IsBoolean()) { | ||
| 2822 | + r = sqlite3_bind_int(statement_, index, value->IsTrue() ? 1 : 0); | ||
| 2820 | 2823 | } else if (value->IsBigInt()) { | |
| 2821 | 2824 | bool lossless; | |
| 2822 | 2825 | int64_t as_int = value.As<BigInt>()->Int64Value(&lossless); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,6 +71,15 @@ suite('data binding and mapping', () => { | |||
| 71 | 71 | text: '', | |
| 72 | 72 | buf: new Uint8Array(), | |
| 73 | 73 | }); | |
| 74 | + | ||
| 75 | + t.assert.deepStrictEqual( | ||
| 76 | + stmt.run(5, true, false, true, null), | ||
| 77 | + { changes: 1, lastInsertRowid: 5 } | ||
| 78 | + ); | ||
| 79 | + t.assert.deepStrictEqual( | ||
| 80 | + query.get(5), | ||
| 81 | + { __proto__: null, key: 5, int: 1, double: 0, text: '1', buf: null } | ||
| 82 | + ); | ||
| 74 | 83 | }); | |
| 75 | 84 | ||
| 76 | 85 | test('large strings are bound correctly', (t) => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments