diff --git a/sqlx-core/src/any/column.rs b/sqlx-core/src/any/column.rs index 9836e1e0..22049033 100644 --- a/sqlx-core/src/any/column.rs +++ b/sqlx-core/src/any/column.rs @@ -8,10 +8,10 @@ use crate::postgres::{PgColumn, PgRow, PgStatement}; use crate::mysql::{MySqlColumn, MySqlRow, MySqlStatement}; #[cfg(feature = "sqlite")] -use crate::sqlite::{SqliteColumn, SqliteStatement, SqliteRow}; +use crate::sqlite::{SqliteColumn, SqliteRow, SqliteStatement}; #[cfg(feature = "mssql")] -use crate::mssql::{MssqlColumn, MssqlStatement, MssqlRow}; +use crate::mssql::{MssqlColumn, MssqlRow, MssqlStatement}; #[derive(Debug, Clone)] pub struct AnyColumn { @@ -76,7 +76,6 @@ impl Column for AnyColumn { } } - // FIXME: Find a nice way to auto-generate the below or petition Rust to add support for #[cfg] // to trait bounds @@ -89,7 +88,14 @@ impl Column for AnyColumn { feature = "sqlite" ))] pub trait AnyColumnIndex: - ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -100,7 +106,14 @@ pub trait AnyColumnIndex: feature = "sqlite" ))] impl AnyColumnIndex for I where - I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -111,7 +124,12 @@ impl AnyColumnIndex for I where all(feature = "postgres", feature = "mysql", feature = "sqlite") ))] pub trait AnyColumnIndex: - ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -120,7 +138,12 @@ pub trait AnyColumnIndex: all(feature = "postgres", feature = "mysql", feature = "sqlite") ))] impl AnyColumnIndex for I where - I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -129,7 +152,12 @@ impl AnyColumnIndex for I where all(feature = "postgres", feature = "mssql", feature = "sqlite") ))] pub trait AnyColumnIndex: - ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -138,7 +166,12 @@ pub trait AnyColumnIndex: all(feature = "postgres", feature = "mssql", feature = "sqlite") ))] impl AnyColumnIndex for I where - I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -147,7 +180,12 @@ impl AnyColumnIndex for I where all(feature = "postgres", feature = "mysql", feature = "mssql") ))] pub trait AnyColumnIndex: - ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -156,7 +194,12 @@ pub trait AnyColumnIndex: all(feature = "postgres", feature = "mysql", feature = "mssql") ))] impl AnyColumnIndex for I where - I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -165,7 +208,12 @@ impl AnyColumnIndex for I where all(feature = "sqlite", feature = "mysql", feature = "mssql") ))] pub trait AnyColumnIndex: - ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -174,7 +222,12 @@ pub trait AnyColumnIndex: all(feature = "sqlite", feature = "mysql", feature = "mssql") ))] impl AnyColumnIndex for I where - I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> { } @@ -184,73 +237,145 @@ impl AnyColumnIndex for I where not(any(feature = "mssql", feature = "sqlite")), all(feature = "postgres", feature = "mysql") ))] -pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +pub trait AnyColumnIndex: + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "mssql", feature = "sqlite")), all(feature = "postgres", feature = "mysql") ))] -impl AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "mysql", feature = "sqlite")), all(feature = "postgres", feature = "mssql") ))] -pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +pub trait AnyColumnIndex: + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "mysql", feature = "sqlite")), all(feature = "postgres", feature = "mssql") ))] -impl AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "mysql", feature = "mssql")), all(feature = "postgres", feature = "sqlite") ))] -pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +pub trait AnyColumnIndex: + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "mysql", feature = "mssql")), all(feature = "postgres", feature = "sqlite") ))] -impl AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "postgres", feature = "sqlite")), all(feature = "mssql", feature = "mysql") ))] -pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +pub trait AnyColumnIndex: + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "postgres", feature = "sqlite")), all(feature = "mssql", feature = "mysql") ))] -impl AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "postgres", feature = "mysql")), all(feature = "mssql", feature = "sqlite") ))] -pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +pub trait AnyColumnIndex: + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "postgres", feature = "mysql")), all(feature = "mssql", feature = "sqlite") ))] -impl AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "postgres", feature = "mssql")), all(feature = "mysql", feature = "sqlite") ))] -pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +pub trait AnyColumnIndex: + ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "postgres", feature = "mssql")), all(feature = "mysql", feature = "sqlite") ))] -impl AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> + ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + + for<'q> ColumnIndex> + + ColumnIndex + + for<'q> ColumnIndex> +{ +} // only 1 (4) @@ -264,7 +389,10 @@ pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "postgres", feature = "mssql", feature = "sqlite")), @@ -276,7 +404,10 @@ pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "mysql", feature = "postgres", feature = "sqlite")), @@ -288,16 +419,25 @@ pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "mysql", feature = "mssql", feature = "postgres")), feature = "sqlite" ))] -pub trait AnyColumnIndex: ColumnIndex + for<'q> ColumnIndex> {} +pub trait AnyColumnIndex: + ColumnIndex + for<'q> ColumnIndex> +{ +} #[cfg(all( not(any(feature = "mysql", feature = "mssql", feature = "postgres")), feature = "sqlite" ))] -impl AnyColumnIndex for I where I: ColumnIndex + for<'q> ColumnIndex> {} +impl AnyColumnIndex for I where + I: ColumnIndex + for<'q> ColumnIndex> +{ +} diff --git a/sqlx-core/src/any/connection/executor.rs b/sqlx-core/src/any/connection/executor.rs index 344c6e53..1aae7dab 100644 --- a/sqlx-core/src/any/connection/executor.rs +++ b/sqlx-core/src/any/connection/executor.rs @@ -1,13 +1,13 @@ -use either::Either; -use futures_core::future::BoxFuture; -use futures_core::stream::BoxStream; -use futures_util::{StreamExt, TryStreamExt}; use crate::any::connection::AnyConnectionKind; -use crate::any::{Any, AnyStatement, AnyColumn, AnyConnection, AnyDone, AnyRow, AnyTypeInfo}; +use crate::any::{Any, AnyColumn, AnyConnection, AnyDone, AnyRow, AnyStatement, AnyTypeInfo}; use crate::database::Database; use crate::describe::Describe; use crate::error::Error; use crate::executor::{Execute, Executor}; +use either::Either; +use futures_core::future::BoxFuture; +use futures_core::stream::BoxStream; +use futures_util::{StreamExt, TryStreamExt}; impl<'c> Executor<'c> for &'c mut AnyConnection { type Database = Any; @@ -126,9 +126,7 @@ impl<'c> Executor<'c> for &'c mut AnyConnection { Box::pin(async move { Ok(match &mut self.0 { #[cfg(feature = "postgres")] - AnyConnectionKind::Postgres(conn) => { - conn.describe(sql).await.map(map_describe)? - } + AnyConnectionKind::Postgres(conn) => conn.describe(sql).await.map(map_describe)?, #[cfg(feature = "mysql")] AnyConnectionKind::MySql(conn) => conn.describe(sql).await.map(map_describe)?, diff --git a/sqlx-core/src/any/database.rs b/sqlx-core/src/any/database.rs index e253ec41..dce948b1 100644 --- a/sqlx-core/src/any/database.rs +++ b/sqlx-core/src/any/database.rs @@ -1,7 +1,6 @@ use crate::any::{ - AnyArgumentBuffer, AnyArguments, AnyColumn, AnyConnection, AnyDone, AnyRow, + AnyArgumentBuffer, AnyArguments, AnyColumn, AnyConnection, AnyDone, AnyRow, AnyStatement, AnyTransactionManager, AnyTypeInfo, AnyValue, AnyValueRef, - AnyStatement, }; use crate::database::{Database, HasArguments, HasStatement, HasStatementCache, HasValueRef}; diff --git a/sqlx-core/src/any/mod.rs b/sqlx-core/src/any/mod.rs index 978f3d6b..214a2a69 100644 --- a/sqlx-core/src/any/mod.rs +++ b/sqlx-core/src/any/mod.rs @@ -17,17 +17,16 @@ mod done; mod kind; mod options; pub(crate) mod row; +mod statement; mod transaction; pub(crate) mod type_info; pub mod types; -mod statement; pub(crate) mod value; #[cfg(feature = "migrate")] mod migrate; pub use arguments::{AnyArgumentBuffer, AnyArguments}; -pub use statement::AnyStatement; pub use column::{AnyColumn, AnyColumnIndex}; pub use connection::AnyConnection; pub use database::Any; @@ -38,6 +37,7 @@ pub use kind::AnyKind; pub use options::AnyConnectOptions; pub use r#type::AnyType; pub use row::AnyRow; +pub use statement::AnyStatement; pub use transaction::AnyTransactionManager; pub use type_info::AnyTypeInfo; pub use value::{AnyValue, AnyValueRef}; diff --git a/sqlx-core/src/any/row.rs b/sqlx-core/src/any/row.rs index 8932bfc6..f619b5c2 100644 --- a/sqlx-core/src/any/row.rs +++ b/sqlx-core/src/any/row.rs @@ -1,4 +1,4 @@ -use crate::any::{Any, AnyColumnIndex, AnyColumn}; +use crate::any::{Any, AnyColumn, AnyColumnIndex}; use crate::column::ColumnIndex; use crate::database::HasValueRef; use crate::error::Error; diff --git a/sqlx-core/src/any/statement.rs b/sqlx-core/src/any/statement.rs index 5c037462..19b712a3 100644 --- a/sqlx-core/src/any/statement.rs +++ b/sqlx-core/src/any/statement.rs @@ -1,12 +1,12 @@ -use crate::any::{Any, AnyTypeInfo, AnyColumn, AnyArguments, AnyColumnIndex}; -use crate::statement::Statement; +use crate::any::{Any, AnyArguments, AnyColumn, AnyColumnIndex, AnyTypeInfo}; use crate::column::ColumnIndex; -use either::Either; -use std::sync::Arc; -use hashbrown::HashMap; -use crate::ext::ustr::UStr; -use std::borrow::Cow; use crate::error::Error; +use crate::ext::ustr::UStr; +use crate::statement::Statement; +use either::Either; +use hashbrown::HashMap; +use std::borrow::Cow; +use std::sync::Arc; pub struct AnyStatement<'q> { pub(crate) sql: Cow<'q, str>, @@ -35,7 +35,7 @@ impl<'q> Statement<'q> for AnyStatement<'q> { match &self.parameters { Some(Either::Left(types)) => Some(Either::Left(&types)), Some(Either::Right(count)) => Some(Either::Right(*count)), - None => None + None => None, } } diff --git a/sqlx-core/src/any/value.rs b/sqlx-core/src/any/value.rs index 4019fc21..b01d3ab7 100644 --- a/sqlx-core/src/any/value.rs +++ b/sqlx-core/src/any/value.rs @@ -1,7 +1,7 @@ use crate::any::{Any, AnyTypeInfo}; use crate::database::HasValueRef; -use std::borrow::Cow; use crate::value::{Value, ValueRef}; +use std::borrow::Cow; #[cfg(feature = "postgres")] use crate::postgres::{PgValue, PgValueRef}; diff --git a/sqlx-core/src/mssql/statement.rs b/sqlx-core/src/mssql/statement.rs index 2de8f29d..eb90d427 100644 --- a/sqlx-core/src/mssql/statement.rs +++ b/sqlx-core/src/mssql/statement.rs @@ -61,7 +61,12 @@ impl<'q> From> for crate::any::AnyStatement<'q> { #[inline] fn from(statement: MssqlStatement<'q>) -> Self { crate::any::AnyStatement::<'q> { - columns: statement.metadata.columns.iter().map(|col| col.clone().into()).collect(), + columns: statement + .metadata + .columns + .iter() + .map(|col| col.clone().into()) + .collect(), column_names: std::sync::Arc::new(statement.metadata.column_names.clone()), parameters: None, sql: statement.sql, diff --git a/sqlx-core/src/mysql/statement.rs b/sqlx-core/src/mysql/statement.rs index 0d7bcccc..b9ba75f6 100644 --- a/sqlx-core/src/mysql/statement.rs +++ b/sqlx-core/src/mysql/statement.rs @@ -63,7 +63,12 @@ impl<'q> From> for crate::any::AnyStatement<'q> { #[inline] fn from(statement: MySqlStatement<'q>) -> Self { crate::any::AnyStatement::<'q> { - columns: statement.metadata.columns.iter().map(|col| col.clone().into()).collect(), + columns: statement + .metadata + .columns + .iter() + .map(|col| col.clone().into()) + .collect(), column_names: statement.metadata.column_names, parameters: Some(Either::Right(statement.metadata.parameters)), sql: statement.sql, diff --git a/sqlx-core/src/postgres/statement.rs b/sqlx-core/src/postgres/statement.rs index 351e4fb4..06aead1f 100644 --- a/sqlx-core/src/postgres/statement.rs +++ b/sqlx-core/src/postgres/statement.rs @@ -63,9 +63,21 @@ impl<'q> From> for crate::any::AnyStatement<'q> { #[inline] fn from(statement: PgStatement<'q>) -> Self { crate::any::AnyStatement::<'q> { - columns: statement.metadata.columns.iter().map(|col| col.clone().into()).collect(), + columns: statement + .metadata + .columns + .iter() + .map(|col| col.clone().into()) + .collect(), column_names: std::sync::Arc::new(statement.metadata.column_names.clone()), - parameters: Some(Either::Left(statement.metadata.parameters.iter().map(|ty| ty.clone().into()).collect())), + parameters: Some(Either::Left( + statement + .metadata + .parameters + .iter() + .map(|ty| ty.clone().into()) + .collect(), + )), sql: statement.sql, } } diff --git a/sqlx-core/src/sqlite/statement/mod.rs b/sqlx-core/src/sqlite/statement/mod.rs index 4ade850e..dfb3ce55 100644 --- a/sqlx-core/src/sqlite/statement/mod.rs +++ b/sqlx-core/src/sqlite/statement/mod.rs @@ -66,7 +66,11 @@ impl<'q> From> for crate::any::AnyStatement<'q> { #[inline] fn from(statement: SqliteStatement<'q>) -> Self { crate::any::AnyStatement::<'q> { - columns: statement.columns.iter().map(|col| col.clone().into()).collect(), + columns: statement + .columns + .iter() + .map(|col| col.clone().into()) + .collect(), column_names: statement.column_names, parameters: Some(Either::Right(statement.parameters)), sql: statement.sql, diff --git a/tests/mysql/mysql.rs b/tests/mysql/mysql.rs index 7ab7b435..1bcd1c10 100644 --- a/tests/mysql/mysql.rs +++ b/tests/mysql/mysql.rs @@ -276,16 +276,24 @@ async fn it_can_bind_only_null_issue_540() -> anyhow::Result<()> { async fn it_can_bind_and_return_years() -> anyhow::Result<()> { let mut conn = new::().await?; - conn.execute(r#" + conn.execute( + r#" CREATE TEMPORARY TABLE too_many_years ( id INT PRIMARY KEY AUTO_INCREMENT, the YEAR NOT NULL ); - "#).await?; + "#, + ) + .await?; - sqlx::query(r#" + sqlx::query( + r#" INSERT INTO too_many_years ( the ) VALUES ( ? ); - "#).bind(2142).execute(&mut conn).await?; + "#, + ) + .bind(2142) + .execute(&mut conn) + .await?; let the: u16 = sqlx::query_scalar("SELECT the FROM too_many_years") .fetch_one(&mut conn)