mirror of
https://github.com/denoland/deno.git
synced 2025-02-18 19:33:00 -05:00
fix(ext/node): throw Session methods when database is closed (#27968)
This commit is contained in:
parent
ece384c094
commit
28faaee772
3 changed files with 15 additions and 2 deletions
|
@ -376,7 +376,7 @@ impl DatabaseSync {
|
|||
Ok(Session {
|
||||
inner: raw_session,
|
||||
freed: Cell::new(false),
|
||||
_db: self.conn.clone(),
|
||||
db: self.conn.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ pub struct Session {
|
|||
pub(crate) freed: Cell<bool>,
|
||||
|
||||
// Hold a strong reference to the database.
|
||||
pub(crate) _db: Rc<RefCell<Option<rusqlite::Connection>>>,
|
||||
pub(crate) db: Rc<RefCell<Option<rusqlite::Connection>>>,
|
||||
}
|
||||
|
||||
impl GarbageCollected for Session {}
|
||||
|
@ -57,6 +57,10 @@ impl Session {
|
|||
// Closes the session.
|
||||
#[fast]
|
||||
fn close(&self) -> Result<(), SqliteError> {
|
||||
if self.db.borrow().is_none() {
|
||||
return Err(SqliteError::AlreadyClosed);
|
||||
}
|
||||
|
||||
self.delete()
|
||||
}
|
||||
|
||||
|
@ -66,6 +70,9 @@ impl Session {
|
|||
// This method is a wrapper around `sqlite3session_changeset()`.
|
||||
#[buffer]
|
||||
fn changeset(&self) -> Result<Box<[u8]>, SqliteError> {
|
||||
if self.db.borrow().is_none() {
|
||||
return Err(SqliteError::AlreadyClosed);
|
||||
}
|
||||
if self.freed.get() {
|
||||
return Err(SqliteError::SessionClosed);
|
||||
}
|
||||
|
@ -78,6 +85,9 @@ impl Session {
|
|||
// This method is a wrapper around `sqlite3session_patchset()`.
|
||||
#[buffer]
|
||||
fn patchset(&self) -> Result<Box<[u8]>, SqliteError> {
|
||||
if self.db.borrow().is_none() {
|
||||
return Err(SqliteError::AlreadyClosed);
|
||||
}
|
||||
if self.freed.get() {
|
||||
return Err(SqliteError::SessionClosed);
|
||||
}
|
||||
|
|
|
@ -96,6 +96,9 @@ Deno.test("[node/sqlite] createSession and changesets", () => {
|
|||
assertThrows(() => session.changeset(), Error, "Session is already closed");
|
||||
// Close after close should throw.
|
||||
assertThrows(() => session.close(), Error, "Session is already closed");
|
||||
|
||||
db.close();
|
||||
assertThrows(() => session.close(), Error, "Database is already closed");
|
||||
});
|
||||
|
||||
Deno.test("[node/sqlite] StatementSync integer too large", () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue