diff --git a/sqlx-core/src/lib.rs b/sqlx-core/src/lib.rs index 43b8fe4a..6619214f 100644 --- a/sqlx-core/src/lib.rs +++ b/sqlx-core/src/lib.rs @@ -1,4 +1,5 @@ #![recursion_limit="256"] +#![allow(unused_imports)] #[macro_use] mod macros; diff --git a/sqlx-core/src/mariadb/backend.rs b/sqlx-core/src/mariadb/backend.rs index 9f204be8..f71eda74 100644 --- a/sqlx-core/src/mariadb/backend.rs +++ b/sqlx-core/src/mariadb/backend.rs @@ -1,4 +1,6 @@ -use super::{MariaDb, MariaDbQueryParameters, MariaDbRow}; +use super::MariaDb; +use crate::mariadb::protocol::ResultRow; +use crate::mariadb::query::MariaDbQueryParameters; use crate::{ backend::Backend, describe::{Describe, ResultField}, @@ -9,7 +11,7 @@ use crate::url::Url; impl Backend for MariaDb { type QueryParameters = MariaDbQueryParameters; - type Row = MariaDbRow; + type Row = ResultRow; type TableIdent = String; fn open(url: &str) -> BoxFuture<'static, crate::Result> { @@ -21,15 +23,11 @@ impl Backend for MariaDb { }) } - fn close(mut self) -> BoxFuture<'static, crate::Result<()>> { + fn close(self) -> BoxFuture<'static, crate::Result<()>> { Box::pin(async move { self.close().await }) } - - // async fn ping(&mut self) -> crate::Result<()> { - // self.ping().await - // } } impl_from_row_for_backend!(MariaDb); diff --git a/sqlx-core/src/mariadb/connection.rs b/sqlx-core/src/mariadb/connection.rs index 67c763ce..44c6bd7e 100644 --- a/sqlx-core/src/mariadb/connection.rs +++ b/sqlx-core/src/mariadb/connection.rs @@ -7,7 +7,7 @@ use crate::{ ComStmtExecute, ComStmtPrepare, ComStmtPrepareOk, Encode, EofPacket, ErrPacket, OkPacket, ResultRow, StmtExecFlag, }, - MariaDbQueryParameters, + query::MariaDbQueryParameters, }, Error, Result, }; @@ -157,17 +157,6 @@ impl MariaDb { }) } - pub(super) async fn check_eof(&mut self) -> Result<()> { - if !self - .capabilities - .contains(Capabilities::CLIENT_DEPRECATE_EOF) - { - let _ = EofPacket::decode(self.receive().await?)?; - } - - Ok(()) - } - pub(super) async fn send_prepare<'c>( &'c mut self, statement: &'c str, @@ -189,35 +178,6 @@ impl MariaDb { ComStmtPrepareOk::decode(packet).map_err(Into::into) } - pub(super) async fn step( - &mut self, - columns: &Vec, - packet: &[u8], - ) -> Result> { - // For each row in the result set we will receive a ResultRow packet. - // We may receive an [OkPacket], [EofPacket], or [ErrPacket] (depending on if EOFs are enabled) to finalize the iteration. - if packet[0] == 0xFE && packet.len() < 0xFF_FF_FF { - // NOTE: It's possible for a ResultRow to start with 0xFE (which would normally signify end-of-rows) - // but it's not possible for an Ok/Eof to be larger than 0xFF_FF_FF. - if !self - .capabilities - .contains(Capabilities::CLIENT_DEPRECATE_EOF) - { - let _eof = EofPacket::decode(packet)?; - Ok(None) - } else { - let _ok = OkPacket::decode(packet, self.capabilities)?; - Ok(None) - } - } else if packet[0] == 0xFF { - let _ = ErrPacket::decode(packet)?; - // TODO: Should be error - Ok(None) - } else { - Ok(Some(ResultRow::decode(packet, columns)?)) - } - } - pub(super) async fn column_definitions( &mut self ) -> Result> { diff --git a/sqlx-core/src/mariadb/executor.rs b/sqlx-core/src/mariadb/executor.rs index 1a7e40eb..5fafaf04 100644 --- a/sqlx-core/src/mariadb/executor.rs +++ b/sqlx-core/src/mariadb/executor.rs @@ -1,4 +1,4 @@ -use super::{MariaDb, MariaDbQueryParameters, MariaDbRow}; +use super::MariaDb; use crate::{ backend::Backend, describe::{Describe, ResultField}, @@ -8,6 +8,7 @@ use crate::{ Capabilities, ColumnCountPacket, ColumnDefinitionPacket, ComStmtExecute, EofPacket, ErrPacket, OkPacket, ResultRow, StmtExecFlag, }, + mariadb::query::MariaDbQueryParameters, row::FromRow, url::Url, }; @@ -28,7 +29,7 @@ impl Executor for MariaDb { Box::pin(async move { let prepare = self.send_prepare(query).await?; - self.send_execute(prepare.statement_id, params); + self.send_execute(prepare.statement_id, params).await?; let columns = self.column_definitions().await?; let capabilities = self.capabilities; @@ -77,7 +78,7 @@ impl Executor for MariaDb { Box::pin(async_stream::try_stream! { let prepare = self.send_prepare(query).await?; - self.send_execute(prepare.statement_id, params); + self.send_execute(prepare.statement_id, params).await?; let columns = self.column_definitions().await?; let capabilities = self.capabilities; diff --git a/sqlx-core/src/mariadb/mod.rs b/sqlx-core/src/mariadb/mod.rs index 5d33572d..eea94377 100644 --- a/sqlx-core/src/mariadb/mod.rs +++ b/sqlx-core/src/mariadb/mod.rs @@ -9,4 +9,4 @@ mod query; mod row; pub mod types; -pub use self::{connection::MariaDb, query::MariaDbQueryParameters, row::MariaDbRow}; +pub use self::connection::MariaDb; diff --git a/sqlx-core/src/mariadb/row.rs b/sqlx-core/src/mariadb/row.rs index 50031110..fcb13b19 100644 --- a/sqlx-core/src/mariadb/row.rs +++ b/sqlx-core/src/mariadb/row.rs @@ -3,20 +3,17 @@ use crate::{ row::Row, }; -#[derive(Debug)] -pub struct MariaDbRow(pub(crate) ResultRow); - -impl Row for MariaDbRow { +impl Row for ResultRow { type Backend = MariaDb; #[inline] fn len(&self) -> usize { - self.0.values.len() + self.values.len() } #[inline] fn get_raw(&self, index: usize) -> Option<&[u8]> { - self.0.values[index] + self.values[index] .as_ref() .map(|value| unsafe { value.as_ref() }) } diff --git a/sqlx-core/src/postgres/backend.rs b/sqlx-core/src/postgres/backend.rs index a92359ba..20e0e0c1 100644 --- a/sqlx-core/src/postgres/backend.rs +++ b/sqlx-core/src/postgres/backend.rs @@ -1,16 +1,18 @@ -use super::{connection::Step, Postgres, PostgresQueryParameters, PostgresRow}; +use super::{connection::Step, Postgres}; use crate::{ backend::Backend, describe::{Describe, ResultField}, + postgres::protocol::DataRow, params::QueryParameters, url::Url, }; use futures_core::{future::BoxFuture, stream::BoxStream}; +use crate::postgres::query::PostgresQueryParameters; impl Backend for Postgres { type QueryParameters = PostgresQueryParameters; - type Row = PostgresRow; + type Row = DataRow; type TableIdent = u32; @@ -33,7 +35,7 @@ impl Backend for Postgres { }) } - fn close(mut self) -> BoxFuture<'static, crate::Result<()>> { + fn close(self) -> BoxFuture<'static, crate::Result<()>> { Box::pin(self.terminate()) } } diff --git a/sqlx-core/src/postgres/connection.rs b/sqlx-core/src/postgres/connection.rs index 7ad9793e..4ded3855 100644 --- a/sqlx-core/src/postgres/connection.rs +++ b/sqlx-core/src/postgres/connection.rs @@ -2,7 +2,6 @@ use crate::{ io::{Buf, BufStream}, postgres::{ protocol::{self, Decode, Encode, Message}, - PostgresDatabaseError, PostgresQueryParameters, PostgresRow, }, }; use async_std::net::TcpStream; @@ -11,6 +10,8 @@ use std::{ io, net::{Shutdown, SocketAddr}, }; +use crate::postgres::query::PostgresQueryParameters; +use crate::postgres::error::PostgresDatabaseError; pub struct Postgres { stream: BufStream, @@ -193,7 +194,7 @@ impl Postgres { } Message::DataRow(body) => { - return Ok(Some(Step::Row(PostgresRow(body)))); + return Ok(Some(Step::Row(body))); } Message::ReadyForQuery(_) => { @@ -291,7 +292,7 @@ impl Postgres { #[derive(Debug)] pub(super) enum Step { Command(u64), - Row(PostgresRow), + Row(protocol::DataRow), ParamDesc(Box), RowDesc(Box), } diff --git a/sqlx-core/src/postgres/executor.rs b/sqlx-core/src/postgres/executor.rs index 18eb6c51..c014eb3f 100644 --- a/sqlx-core/src/postgres/executor.rs +++ b/sqlx-core/src/postgres/executor.rs @@ -1,4 +1,4 @@ -use super::{connection::Step, Postgres, PostgresQueryParameters, PostgresRow}; +use super::{connection::Step, Postgres}; use crate::{ backend::Backend, describe::{Describe, ResultField}, @@ -104,7 +104,7 @@ impl Executor for Postgres { query: &'q str, ) -> BoxFuture<'e, crate::Result>> { Box::pin(async move { - self.parse("", query, &PostgresQueryParameters::new()); + self.parse("", query, &QueryParameters::new()); self.describe(""); self.sync().await?; diff --git a/sqlx-core/src/postgres/mod.rs b/sqlx-core/src/postgres/mod.rs index e6c77936..a51d821b 100644 --- a/sqlx-core/src/postgres/mod.rs +++ b/sqlx-core/src/postgres/mod.rs @@ -14,6 +14,5 @@ pub mod protocol; pub mod types; pub use self::{ - connection::Postgres, error::PostgresDatabaseError, query::PostgresQueryParameters, - row::PostgresRow, + connection::Postgres }; diff --git a/sqlx-core/src/postgres/protocol/data_row.rs b/sqlx-core/src/postgres/protocol/data_row.rs index 70039429..8c4dbcd9 100644 --- a/sqlx-core/src/postgres/protocol/data_row.rs +++ b/sqlx-core/src/postgres/protocol/data_row.rs @@ -11,7 +11,7 @@ use std::{ pub struct DataRow { #[used] buffer: Pin>, - values: Box<[Option>]>, + pub(crate) values: Box<[Option>]>, } // SAFE: Raw pointers point to pinned memory inside the struct @@ -46,31 +46,14 @@ impl Decode for DataRow { } } -impl DataRow { - #[inline] - pub fn is_empty(&self) -> bool { - self.values.is_empty() - } - - #[inline] - pub fn len(&self) -> usize { - self.values.len() - } - - #[inline] - pub fn get(&self, index: usize) -> Option<&[u8]> { - self.values[index] - .as_ref() - .map(|value| unsafe { value.as_ref() }) - } -} - impl Debug for DataRow { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use crate::row::Row; + write!(f, "DataRow(")?; f.debug_list() - .entries((0..self.len()).map(|i| self.get(i).map(ByteStr))) + .entries((0..self.len()).map(|i| self.get_raw(i).map(ByteStr))) .finish()?; write!(f, ")")?; diff --git a/sqlx-core/src/postgres/row.rs b/sqlx-core/src/postgres/row.rs index f612f422..d182a052 100644 --- a/sqlx-core/src/postgres/row.rs +++ b/sqlx-core/src/postgres/row.rs @@ -1,19 +1,16 @@ use super::{protocol::DataRow, Postgres}; use crate::row::Row; -#[derive(Debug)] -pub struct PostgresRow(pub(crate) DataRow); - -impl Row for PostgresRow { +impl Row for DataRow { type Backend = Postgres; - #[inline] fn len(&self) -> usize { - self.0.len() + self.values.len() } - #[inline] fn get_raw(&self, index: usize) -> Option<&[u8]> { - self.0.get(index) + self.values[index] + .as_ref() + .map(|value| unsafe { value.as_ref() }) } }