mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 20:25:12 -05:00
fix(ext/node): sqlite bind support bigint values (#27890)
This commit is contained in:
parent
b8a878cfc2
commit
1cbaee9f52
2 changed files with 23 additions and 0 deletions
|
@ -261,6 +261,20 @@ impl StatementSync {
|
|||
ffi::SQLITE_TRANSIENT(),
|
||||
);
|
||||
}
|
||||
} else if value.is_big_int() {
|
||||
let value: v8::Local<v8::BigInt> = value.try_into().unwrap();
|
||||
let (as_int, lossless) = value.i64_value();
|
||||
if !lossless {
|
||||
return Err(SqliteError::FailedBind(
|
||||
"BigInt value is too large to bind",
|
||||
));
|
||||
}
|
||||
|
||||
// SAFETY: `self.inner` is a valid pointer to a sqlite3_stmt
|
||||
// as it lives as long as the StatementSync instance.
|
||||
unsafe {
|
||||
ffi::sqlite3_bind_int64(raw, i + 1, as_int);
|
||||
}
|
||||
} else {
|
||||
return Err(SqliteError::FailedBind("Unsupported type"));
|
||||
}
|
||||
|
|
|
@ -52,6 +52,15 @@ Deno.test(
|
|||
},
|
||||
);
|
||||
|
||||
Deno.test("[node/sqlite] StatementSync bind bigints", () => {
|
||||
const db = new DatabaseSync(":memory:");
|
||||
db.exec("CREATE TABLE data(key INTEGER PRIMARY KEY);");
|
||||
|
||||
const stmt = db.prepare("INSERT INTO data (key) VALUES (?)");
|
||||
assertEquals(stmt.run(100n), { lastInsertRowid: 100, changes: 1 });
|
||||
db.close();
|
||||
});
|
||||
|
||||
Deno.test("[node/sqlite] StatementSync read bigints are supported", () => {
|
||||
const db = new DatabaseSync(":memory:");
|
||||
db.exec("CREATE TABLE data(key INTEGER PRIMARY KEY);");
|
||||
|
|
Loading…
Add table
Reference in a new issue