Skip to content

Commit

Permalink
fix(sqlite): delete unused ConnectionHandleRaw type (#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander authored Mar 23, 2024
1 parent 0b91ea6 commit 59d5ba6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
12 changes: 0 additions & 12 deletions sqlx-sqlite/src/connection/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ use crate::{statement::unlock_notify, SqliteError};
#[derive(Debug)]
pub(crate) struct ConnectionHandle(NonNull<sqlite3>);

/// A wrapper around `ConnectionHandle` which *does not* finalize the handle on-drop.
#[derive(Clone, Debug)]
pub(crate) struct ConnectionHandleRaw(NonNull<sqlite3>);

// A SQLite3 handle is safe to send between threads, provided not more than
// one is accessing it at the same time. This is upheld as long as [SQLITE_CONFIG_MULTITHREAD] is
// enabled and [SQLITE_THREADSAFE] was enabled when sqlite was compiled. We refuse to work
Expand All @@ -30,9 +26,6 @@ pub(crate) struct ConnectionHandleRaw(NonNull<sqlite3>);

unsafe impl Send for ConnectionHandle {}

// SAFETY: this type does nothing but provide access to the DB handle pointer.
unsafe impl Send for ConnectionHandleRaw {}

impl ConnectionHandle {
#[inline]
pub(super) unsafe fn new(ptr: *mut sqlite3) -> Self {
Expand All @@ -48,11 +41,6 @@ impl ConnectionHandle {
self.0
}

#[inline]
pub(crate) fn to_raw(&self) -> ConnectionHandleRaw {
ConnectionHandleRaw(self.0)
}

pub(crate) fn last_insert_rowid(&mut self) -> i64 {
// SAFETY: we have exclusive access to the database handle
unsafe { sqlite3_last_insert_rowid(self.as_ptr()) }
Expand Down
22 changes: 11 additions & 11 deletions sqlx-sqlite/src/connection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
use std::cmp::Ordering;
use std::fmt::Write;
use std::fmt::{self, Debug, Formatter};
use std::os::raw::{c_int, c_void};
use std::panic::catch_unwind;
use std::ptr::NonNull;

use futures_core::future::BoxFuture;
use futures_intrusive::sync::MutexGuard;
use futures_util::future;
use libsqlite3_sys::{sqlite3, sqlite3_progress_handler};

pub(crate) use handle::ConnectionHandle;
use sqlx_core::common::StatementCache;
pub(crate) use sqlx_core::connection::*;
use sqlx_core::error::Error;
use sqlx_core::executor::Executor;
use sqlx_core::transaction::Transaction;
use std::cmp::Ordering;
use std::fmt::{self, Debug, Formatter};
use std::os::raw::{c_int, c_void};
use std::panic::catch_unwind;
use std::ptr::NonNull;

use crate::connection::establish::EstablishParams;
use crate::connection::worker::ConnectionWorker;
use crate::options::OptimizeOnClose;
use crate::statement::VirtualStatement;
use crate::{Sqlite, SqliteConnectOptions};
use sqlx_core::executor::Executor;
use std::fmt::Write;

pub(crate) use sqlx_core::connection::*;

pub(crate) use handle::{ConnectionHandle, ConnectionHandleRaw};

pub(crate) mod collation;
pub(crate) mod describe;
Expand Down
9 changes: 3 additions & 6 deletions sqlx-sqlite/src/connection/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread;

use futures_channel::oneshot;
use futures_intrusive::sync::{Mutex, MutexGuard};
use tracing::span::Span;

use futures_channel::oneshot;
use sqlx_core::describe::Describe;
use sqlx_core::error::Error;
use sqlx_core::transaction::{
begin_ansi_transaction_sql, commit_ansi_transaction_sql, rollback_ansi_transaction_sql,
};
use sqlx_core::Either;
use tracing::span::Span;

use crate::connection::describe::describe;
use crate::connection::establish::EstablishParams;
use crate::connection::execute;
use crate::connection::ConnectionState;
use crate::connection::{execute, ConnectionHandleRaw};
use crate::{Sqlite, SqliteArguments, SqliteQueryResult, SqliteRow, SqliteStatement};

// Each SQLite connection has a dedicated thread.
Expand All @@ -29,8 +29,6 @@ use crate::{Sqlite, SqliteArguments, SqliteQueryResult, SqliteRow, SqliteStateme

pub(crate) struct ConnectionWorker {
command_tx: flume::Sender<(Command, tracing::Span)>,
/// The `sqlite3` pointer. NOTE: access is unsynchronized!
pub(crate) _handle_raw: ConnectionHandleRaw,
/// Mutex for locking access to the database.
pub(crate) shared: Arc<WorkerSharedState>,
}
Expand Down Expand Up @@ -105,7 +103,6 @@ impl ConnectionWorker {
if establish_tx
.send(Ok(Self {
command_tx,
_handle_raw: conn.handle.to_raw(),
shared: Arc::clone(&shared),
}))
.is_err()
Expand Down

0 comments on commit 59d5ba6

Please sign in to comment.