Executes SQL statements in SQL Server, returning the resulting rows. Passthrough method for [`tiberius::Client::query`]. Note: The returned [`Future`] does not need to be awaited for the query to be sent. [`Future`]: std::future::Future
(
&mut self,
query: impl Into<Cow<'a, str>>,
params: &[&dyn tiberius::ToSql],
)
| 186 | /// |
| 187 | /// [`Future`]: std::future::Future |
| 188 | pub async fn query<'a>( |
| 189 | &mut self, |
| 190 | query: impl Into<Cow<'a, str>>, |
| 191 | params: &[&dyn tiberius::ToSql], |
| 192 | ) -> Result<SmallVec<[tiberius::Row; 1]>, SqlServerError> { |
| 193 | let (tx, rx) = tokio::sync::oneshot::channel(); |
| 194 | |
| 195 | let params = params |
| 196 | .iter() |
| 197 | .map(|p| OwnedColumnData::from(p.to_sql())) |
| 198 | .collect(); |
| 199 | let kind = RequestKind::Query { |
| 200 | query: query.into().to_string(), |
| 201 | params, |
| 202 | }; |
| 203 | self.tx |
| 204 | .send(Request { tx, kind }) |
| 205 | .context("sending request")?; |
| 206 | |
| 207 | let response = rx.await.context("channel")??; |
| 208 | match response { |
| 209 | Response::Rows(rows) => Ok(rows), |
| 210 | other @ Response::Execute { .. } | other @ Response::RowStream { .. } => Err( |
| 211 | SqlServerError::ProgrammingError(format!("expected Response::Rows, got {other:?}")), |
| 212 | ), |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /// Executes SQL statements in SQL Server, returning a [`Stream`] of |
| 217 | /// resulting rows. |