mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Copy strings when binding to sqlite
This commit is contained in:
@@ -2003,7 +2003,7 @@ TLDR:
|
||||
- `get Statement.columnNames` get the returned column names
|
||||
- `get Statement.paramsCount` how many parameters are expected?
|
||||
|
||||
You can bind parameters on any call to a statement. Named parameters and positional parameters are supported.
|
||||
You can bind parameters on any call to a statement. Named parameters and positional parameters are supported. Bound parameters are remembered between calls and reset the next time you pass parameters to bind.
|
||||
|
||||
```ts
|
||||
import { Database } from "bun:sqlite";
|
||||
|
||||
@@ -206,15 +206,15 @@ static inline bool rebindValue(JSC::JSGlobalObject* lexicalGlobalObject, sqlite3
|
||||
}
|
||||
|
||||
if (roped.is8Bit()) {
|
||||
CHECK_BIND(sqlite3_bind_text(stmt, i, reinterpret_cast<const char*>(roped.characters8()), roped.length(), nullptr));
|
||||
CHECK_BIND(sqlite3_bind_text(stmt, i, reinterpret_cast<const char*>(roped.characters8()), roped.length(), SQLITE_TRANSIENT));
|
||||
} else {
|
||||
CHECK_BIND(sqlite3_bind_text16(stmt, i, roped.characters16(), roped.length() * 2, nullptr));
|
||||
CHECK_BIND(sqlite3_bind_text16(stmt, i, roped.characters16(), roped.length() * 2, SQLITE_TRANSIENT));
|
||||
}
|
||||
|
||||
} else if (UNLIKELY(value.isHeapBigInt())) {
|
||||
CHECK_BIND(sqlite3_bind_int64(stmt, i, JSBigInt::toBigInt64(value)));
|
||||
} else if (JSC::JSArrayBufferView* buffer = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(value)) {
|
||||
CHECK_BIND(sqlite3_bind_blob(stmt, i, buffer->vector(), buffer->byteLength(), nullptr));
|
||||
CHECK_BIND(sqlite3_bind_blob(stmt, i, buffer->vector(), buffer->byteLength(), SQLITE_TRANSIENT));
|
||||
} else {
|
||||
throwException(lexicalGlobalObject, scope, createTypeError(lexicalGlobalObject, "Binding expected string, TypedArray, boolean, number, bigint or null"_s));
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user