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 ssrp;
18mod stream;
19mod tls_prelogin_stream_wrapper;
20
21pub struct MssqlConnection {
22 pub(crate) stream: MssqlStream,
23 pub(crate) cache_statement: StatementCache<Arc<MssqlStatementMetadata>>,
24 log_settings: LogSettings,
25}
26
27impl Debug for MssqlConnection {
28 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
29 f.debug_struct("MssqlConnection").finish()
30 }
31}
32
33impl Connection for MssqlConnection {
34 type Database = Mssql;
35
36 type Options = MssqlConnectOptions;
37
38 fn close(mut self) -> BoxFuture<'static, Result<(), Error>> {
39 use sqlx_rt::AsyncWriteExt;
42
43 async move { self.stream.shutdown().await.map_err(Into::into) }.boxed()
46 }
47
48 fn close_hard(self) -> BoxFuture<'static, Result<(), Error>> {
49 self.close()
50 }
51
52 fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> {
53 self.execute("/* SQLx ping */").map_ok(|_| ()).boxed()
55 }
56
57 fn begin(&mut self) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>>
58 where
59 Self: Sized,
60 {
61 Transaction::begin(self)
62 }
63
64 #[doc(hidden)]
65 fn flush(&mut self) -> BoxFuture<'_, Result<(), Error>> {
66 self.stream.wait_until_ready().boxed()
67 }
68
69 #[doc(hidden)]
70 fn should_flush(&self) -> bool {
71 !self.stream.wbuf.is_empty()
72 }
73
74 fn dbms_name(&mut self) -> BoxFuture<'_, Result<String, Error>> {
75 futures_util::future::ready(Ok("Microsoft SQL Server".to_string())).boxed()
76 }
77}