sqlx_core_oldapi/mssql/connection/
mod.rs1use crate::common::StatementCache;
2use crate::connection::{Connection, LogSettings};
3use crate::error::Error;
4use crate::executor::Executor;
5use crate::mssql::connection::stream::MssqlStream;
6use crate::mssql::statement::MssqlStatementMetadata;
7use crate::mssql::{Mssql, MssqlConnectOptions};
8use crate::transaction::Transaction;
9use futures_core::future::BoxFuture;
10use futures_util::{FutureExt, TryFutureExt};
11use std::fmt::{self, Debug, Formatter};
12use std::sync::Arc;
13
14mod establish;
15mod executor;
16mod prepare;
17mod stream;
18mod tls_prelogin_stream_wrapper;
19
20pub struct MssqlConnection {
21 pub(crate) stream: MssqlStream,
22 pub(crate) cache_statement: StatementCache<Arc<MssqlStatementMetadata>>,
23 log_settings: LogSettings,
24}
25
26impl Debug for MssqlConnection {
27 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28 f.debug_struct("MssqlConnection").finish()
29 }
30}
31
32impl Connection for MssqlConnection {
33 type Database = Mssql;
34
35 type Options = MssqlConnectOptions;
36
37 #[allow(unused_mut)]
38 fn close(mut self) -> BoxFuture<'static, Result<(), Error>> {
39 #[cfg(feature = "_rt-async-std")]
42 {
43 use std::future::ready;
44 use std::net::Shutdown;
45
46 ready(self.stream.shutdown(Shutdown::Both).map_err(Into::into)).boxed()
47 }
48
49 #[cfg(feature = "_rt-tokio")]
50 {
51 use sqlx_rt::AsyncWriteExt;
52
53 async move { self.stream.shutdown().await.map_err(Into::into) }.boxed()
56 }
57 }
58
59 fn close_hard(self) -> BoxFuture<'static, Result<(), Error>> {
60 self.close()
61 }
62
63 fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> {
64 self.execute("/* SQLx ping */").map_ok(|_| ()).boxed()
66 }
67
68 fn begin(&mut self) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>>
69 where
70 Self: Sized,
71 {
72 Transaction::begin(self)
73 }
74
75 #[doc(hidden)]
76 fn flush(&mut self) -> BoxFuture<'_, Result<(), Error>> {
77 self.stream.wait_until_ready().boxed()
78 }
79
80 #[doc(hidden)]
81 fn should_flush(&self) -> bool {
82 !self.stream.wbuf.is_empty()
83 }
84}