Copy strings when binding to sqlite

This commit is contained in:
Jarred Sumner
2022-05-16 18:19:08 -07:00
parent e31f44c3d1
commit aba032e176
2 changed files with 4 additions and 4 deletions

View File

@@ -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";

View File

@@ -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;