diff --git a/sqlx-core/src/mysql/row.rs b/sqlx-core/src/mysql/row.rs index 09126f3f9..33fafc13f 100644 --- a/sqlx-core/src/mysql/row.rs +++ b/sqlx-core/src/mysql/row.rs @@ -37,9 +37,8 @@ impl<'c> Row<'c> for MySqlRow<'c> { self.row.len() } - fn try_get_raw<'r, I>(&'r self, index: I) -> crate::Result>> + fn try_get_raw(&self, index: I) -> crate::Result>> where - 'c: 'r, I: ColumnIndex, { let index = index.resolve(self)?; diff --git a/sqlx-core/src/postgres/row.rs b/sqlx-core/src/postgres/row.rs index 4a46ab6ef..c53387db3 100644 --- a/sqlx-core/src/postgres/row.rs +++ b/sqlx-core/src/postgres/row.rs @@ -42,9 +42,8 @@ impl<'c> Row<'c> for PgRow<'c> { self.data.len() } - fn try_get_raw<'r, I>(&'r self, index: I) -> crate::Result>> + fn try_get_raw(&self, index: I) -> crate::Result>> where - 'c: 'r, I: ColumnIndex, { let index = index.resolve(self)?; diff --git a/sqlx-core/src/row.rs b/sqlx-core/src/row.rs index 85424fcd8..b80c90d9f 100644 --- a/sqlx-core/src/row.rs +++ b/sqlx-core/src/row.rs @@ -24,32 +24,29 @@ pub trait Row<'c>: Unpin + Send { /// Returns the number of values in the row. fn len(&self) -> usize; - fn get<'r, T, I>(&'r self, index: I) -> T + fn get(&self, index: I) -> T where - 'c: 'r, T: Type, I: ColumnIndex, - T: Decode<'r, Self::Database>, + T: Decode<'c, Self::Database>, { self.try_get::(index).unwrap() } - fn try_get<'r, T, I>(&'r self, index: I) -> crate::Result + fn try_get(&self, index: I) -> crate::Result where - 'c: 'r, T: Type, I: ColumnIndex, - T: Decode<'r, Self::Database>, + T: Decode<'c, Self::Database>, { Ok(Decode::decode(self.try_get_raw(index)?)?) } - fn try_get_raw<'r, I>( - &'r self, + fn try_get_raw( + &self, index: I, - ) -> crate::Result>::RawValue> + ) -> crate::Result>::RawValue> where - 'c: 'r, I: ColumnIndex; } @@ -72,7 +69,7 @@ macro_rules! impl_from_row_for_tuple { where $($T: 'c,)+ $($T: crate::types::Type<$db>,)+ - $($T: for<'r> crate::decode::Decode<'r, $db>,)+ + $($T: crate::decode::Decode<'c, $db>,)+ { #[inline] fn from_row(row: $r<'c>) -> crate::Result<$db, Self> { diff --git a/sqlx-core/src/sqlite/row.rs b/sqlx-core/src/sqlite/row.rs index 3c46bf224..ef55d60ea 100644 --- a/sqlx-core/src/sqlite/row.rs +++ b/sqlx-core/src/sqlite/row.rs @@ -7,11 +7,19 @@ use crate::sqlite::{Sqlite, SqliteConnection}; pub struct SqliteRow<'c> { pub(super) values: usize, pub(super) statement: Option, - pub(super) connection: &'c mut SqliteConnection, + pub(super) connection: &'c SqliteConnection, } +// Accessing values from the statement object is +// safe across threads as long as we don't call [sqlite3_step] +// That should not be possible as long as an immutable borrow is held on the connection + +#[allow(unsafe_code)] +unsafe impl Send for SqliteRow<'_> {} + impl<'c> SqliteRow<'c> { - fn statement(&'c self) -> &'c Statement { + #[inline] + fn statement(&self) -> &'c Statement { self.connection.statement(self.statement) } } @@ -24,15 +32,14 @@ impl<'c> Row<'c> for SqliteRow<'c> { self.values } - fn try_get_raw<'r, I>(&'r self, index: I) -> crate::Result> + fn try_get_raw(&self, index: I) -> crate::Result> where - 'c: 'r, I: ColumnIndex, { - let index = index.resolve(self)?; - let value = SqliteValue::new(self.statement(), index); - - Ok(value) + Ok(SqliteValue { + statement: self.statement(), + index: index.resolve(self)? as i32, + }) } } diff --git a/sqlx-core/src/sqlite/value.rs b/sqlx-core/src/sqlite/value.rs index bfceb369c..09be2618e 100644 --- a/sqlx-core/src/sqlite/value.rs +++ b/sqlx-core/src/sqlite/value.rs @@ -11,18 +11,8 @@ use libsqlite3_sys::{ use crate::sqlite::statement::Statement; pub struct SqliteValue<'c> { - index: i32, - statement: &'c Statement, -} - -impl<'c> SqliteValue<'c> { - #[inline] - pub(super) fn new(statement: &'c Statement, index: usize) -> Self { - Self { - statement, - index: index as i32, - } - } + pub(super) index: i32, + pub(super) statement: &'c Statement, } // https://www.sqlite.org/c3ref/column_blob.html