aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-09 00:51:55 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-09 02:02:47 -0700
commit9fd00727406b0170fa2d3bb43973ff8d78e7bb76 (patch)
treed41deec7dfbb358ee59aa7a99a5bee54caebc47c /src/bun.js/bindings/sqlite/JSSQLStatement.cpp
parent4dbbdb1671d44eae553b4d8a2e352c03c0050fa6 (diff)
downloadbun-9fd00727406b0170fa2d3bb43973ff8d78e7bb76.tar.gz
bun-9fd00727406b0170fa2d3bb43973ff8d78e7bb76.tar.zst
bun-9fd00727406b0170fa2d3bb43973ff8d78e7bb76.zip
Don't forget to load SQLite in Database.deserialize
Fixes https://github.com/oven-sh/bun/issues/1304
Diffstat (limited to 'src/bun.js/bindings/sqlite/JSSQLStatement.cpp')
-rw-r--r--src/bun.js/bindings/sqlite/JSSQLStatement.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
index c1c57e38c..8fc6ac77a 100644
--- a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
+++ b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
@@ -437,6 +437,14 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementDeserialize, (JSC::JSGlobalObject * lexic
JSValue thisValue = callFrame->thisValue();
JSSQLStatementConstructor* thisObject = jsDynamicCast<JSSQLStatementConstructor*>(thisValue.getObject());
+ JSC::JSArrayBufferView* array = jsDynamicCast<JSC::JSArrayBufferView*>(callFrame->argument(0));
+ unsigned int flags = SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_RESIZEABLE;
+ JSC::EnsureStillAliveScope ensureAliveArray(array);
+
+ if (callFrame->argumentCount() > 1 and callFrame->argument(1).toBoolean(lexicalGlobalObject)) {
+ flags |= SQLITE_DESERIALIZE_READONLY;
+ }
+
if (UNLIKELY(!thisObject)) {
throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected SQL"_s));
return JSValue::encode(JSC::jsUndefined());
@@ -447,7 +455,6 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementDeserialize, (JSC::JSGlobalObject * lexic
return JSValue::encode(JSC::jsUndefined());
}
- JSC::JSArrayBufferView* array = jsDynamicCast<JSC::JSArrayBufferView*>(callFrame->argument(0));
if (UNLIKELY(!array)) {
throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Expected Uint8Array or Buffer"_s));
return JSValue::encode(JSC::jsUndefined());
@@ -458,6 +465,14 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementDeserialize, (JSC::JSGlobalObject * lexic
return JSValue::encode(JSC::jsUndefined());
}
+#if LAZY_LOAD_SQLITE
+ if (UNLIKELY(lazyLoadSQLite() < 0)) {
+ WTF::String msg = WTF::String::fromUTF8(dlerror());
+ throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, msg));
+ return JSValue::encode(JSC::jsUndefined());
+ }
+#endif
+
size_t byteLength = array->byteLength();
void* ptr = array->vector();
if (UNLIKELY(ptr == nullptr || byteLength == 0)) {
@@ -473,12 +488,6 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementDeserialize, (JSC::JSGlobalObject * lexic
memcpy(data, ptr, byteLength);
}
- unsigned int flags = SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_RESIZEABLE;
-
- if (callFrame->argumentCount() > 1 and callFrame->argument(1).toBoolean(lexicalGlobalObject)) {
- flags |= SQLITE_DESERIALIZE_READONLY;
- }
-
sqlite3* db = nullptr;
if (sqlite3_open_v2(":memory:", &db, DEFAULT_SQLITE_FLAGS, nullptr) != SQLITE_OK) {
throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Failed to open SQLite"_s));