mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Don't forget to load SQLite in Database.deserialize
Fixes https://github.com/oven-sh/bun/issues/1304
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user