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
7 changes: 6 additions & 1 deletion .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ env:
PYTHON_VERSION: '3.14'
XCODE_VERSION: '16.4'
FLAKY_TESTS: keep_retrying
RUSTC_VERSION: '1.82'

permissions:
contents: read
Expand Down Expand Up @@ -95,6 +96,10 @@ jobs:
allow-prereleases: true
- name: Set up Xcode ${{ env.XCODE_VERSION }}
run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app
- name: Install Rust ${{ env.RUSTC_VERSION }}
run: |
rustup override set "$RUSTC_VERSION"
rustup --version
- name: Set up sccache
uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
with:
Expand Down Expand Up @@ -124,7 +129,7 @@ jobs:
df -h
echo "::endgroup::"
- name: Build
run: make -C node build-ci -j$(getconf _NPROCESSORS_ONLN) V=1 CONFIG_FLAGS="--error-on-warn"
run: make -C node build-ci -j$(getconf _NPROCESSORS_ONLN) V=1 CONFIG_FLAGS="--error-on-warn --v8-enable-temporal-support"
- name: Free Space After Build
run: df -h
- name: Test
Expand Down
1 change: 1 addition & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,7 @@ changes:
* `env` {Object} Specify environment variables to be passed along to the test process.
This options is not compatible with `isolation='none'`. These variables will override
those from the main process, and are not merged with `process.env`.
**Default:** `process.env`.
* Returns: {TestsStream}

**Note:** `shard` is used to horizontally parallelize test running across
Expand Down
34 changes: 26 additions & 8 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2261,20 +2261,38 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
// Dates could be supported by converting them to numbers. However, there
// would not be a good way to read the values back from SQLite with the
// original type.
Isolate* isolate = env()->isolate();
int r;
if (value->IsNumber()) {
double val = value.As<Number>()->Value();
const double val = value.As<Number>()->Value();
r = sqlite3_bind_double(statement_, index, val);
} else if (value->IsString()) {
Utf8Value val(env()->isolate(), value.As<String>());
r = sqlite3_bind_text(
statement_, index, *val, val.length(), SQLITE_TRANSIENT);
Utf8Value val(isolate, value.As<String>());
if (val.IsAllocated()) {
// Avoid an extra SQLite copy for large strings by transferring ownership
// of the malloc()'d buffer to SQLite.
char* data = *val;
const sqlite3_uint64 length = static_cast<sqlite3_uint64>(val.length());
val.Release();
r = sqlite3_bind_text64(
statement_, index, data, length, std::free, SQLITE_UTF8);
} else {
r = sqlite3_bind_text64(statement_,
index,
*val,
static_cast<sqlite3_uint64>(val.length()),
SQLITE_TRANSIENT,
SQLITE_UTF8);
}
} else if (value->IsNull()) {
r = sqlite3_bind_null(statement_, index);
} else if (value->IsArrayBufferView()) {
ArrayBufferViewContents<uint8_t> buf(value);
r = sqlite3_bind_blob(
statement_, index, buf.data(), buf.length(), SQLITE_TRANSIENT);
r = sqlite3_bind_blob64(statement_,
index,
buf.data(),
static_cast<sqlite3_uint64>(buf.length()),
SQLITE_TRANSIENT);
} else if (value->IsBigInt()) {
bool lossless;
int64_t as_int = value.As<BigInt>()->Int64Value(&lossless);
Expand All @@ -2285,13 +2303,13 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
r = sqlite3_bind_int64(statement_, index, as_int);
} else {
THROW_ERR_INVALID_ARG_TYPE(
env()->isolate(),
isolate,
"Provided value cannot be bound to SQLite parameter %d.",
index);
return false;
}

CHECK_ERROR_OR_THROW(env()->isolate(), db_.get(), r, SQLITE_OK, false);
CHECK_ERROR_OR_THROW(isolate, db_.get(), r, SQLITE_OK, false);
return true;
}

Expand Down
13 changes: 11 additions & 2 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,17 @@ size_t StringBytes::Write(Isolate* isolate,

case BUFFER:
case UTF8:
nbytes = str->WriteUtf8V2(
isolate, buf, buflen, String::WriteFlags::kReplaceInvalidUtf8);
if (input_view.is_one_byte()) {
// Use simdutf for one-byte strings instead of V8's WriteUtf8V2.
nbytes = simdutf::convert_latin1_to_utf8_safe(
reinterpret_cast<const char*>(input_view.data8()),
input_view.length(),
buf,
buflen);
} else {
nbytes = str->WriteUtf8V2(
isolate, buf, buflen, String::WriteFlags::kReplaceInvalidUtf8);
}
break;

case UCS2: {
Expand Down
35 changes: 35 additions & 0 deletions test/parallel/test-sqlite-data-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,41 @@ suite('data binding and mapping', () => {
});
});

test('large strings are bound correctly', (t) => {
const db = new DatabaseSync(nextDb());
t.after(() => { db.close(); });
const setup = db.exec(
'CREATE TABLE data(key INTEGER PRIMARY KEY, text TEXT) STRICT;'
);
t.assert.strictEqual(setup, undefined);

t.assert.deepStrictEqual(
db.prepare('INSERT INTO data (key, text) VALUES (?, ?)').run(1, ''),
{ changes: 1, lastInsertRowid: 1 },
);

const update = db.prepare('UPDATE data SET text = ? WHERE key = 1');

// > 1024 bytes so `Utf8Value` uses heap storage internally.
const largeAscii = 'a'.repeat(8 * 1024);
// Force a non-one-byte string path through UTF-8 conversion.
const largeUnicode = '\u2603'.repeat(2048);

const res = update.run(largeAscii);
t.assert.strictEqual(res.changes, 1);

t.assert.strictEqual(
db.prepare('SELECT text FROM data WHERE key = 1').get().text,
largeAscii,
);

t.assert.strictEqual(update.run(largeUnicode).changes, 1);
t.assert.strictEqual(
db.prepare('SELECT text FROM data WHERE key = 1').get().text,
largeUnicode,
);
});

test('unsupported data types', (t) => {
const db = new DatabaseSync(nextDb());
t.after(() => { db.close(); });
Expand Down
Loading