mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00: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(),
|
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 {
|
} else {
|
||||||
return Err(SqliteError::FailedBind("Unsupported type"));
|
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", () => {
|
Deno.test("[node/sqlite] StatementSync read bigints are supported", () => {
|
||||||
const db = new DatabaseSync(":memory:");
|
const db = new DatabaseSync(":memory:");
|
||||||
db.exec("CREATE TABLE data(key INTEGER PRIMARY KEY);");
|
db.exec("CREATE TABLE data(key INTEGER PRIMARY KEY);");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue