Executes SQL statements in SQL Server, returning the number of rows effected. Passthrough method for [`tiberius::Client::execute`]. 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 ToSql],
)
| 148 | /// |
| 149 | /// [`Future`]: std::future::Future |
| 150 | pub async fn execute<'a>( |
| 151 | &mut self, |
| 152 | query: impl Into<Cow<'a, str>>, |
| 153 | params: &[&dyn ToSql], |
| 154 | ) -> Result<SmallVec<[u64; 1]>, SqlServerError> { |
| 155 | let (tx, rx) = tokio::sync::oneshot::channel(); |
| 156 | |
| 157 | let params = params |
| 158 | .iter() |
| 159 | .map(|p| OwnedColumnData::from(p.to_sql())) |
| 160 | .collect(); |
| 161 | let kind = RequestKind::Execute { |
| 162 | query: query.into().to_string(), |
| 163 | params, |
| 164 | }; |
| 165 | self.tx |
| 166 | .send(Request { tx, kind }) |
| 167 | .context("sending request")?; |
| 168 | |
| 169 | let response = rx.await.context("channel")??; |
| 170 | match response { |
| 171 | Response::Execute { rows_affected } => Ok(rows_affected), |
| 172 | other @ Response::Rows(_) | other @ Response::RowStream { .. } => { |
| 173 | Err(SqlServerError::ProgrammingError(format!( |
| 174 | "expected Response::Execute, got {other:?}" |
| 175 | ))) |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /// Executes SQL statements in SQL Server, returning the resulting rows. |
| 181 | /// |
no test coverage detected