sqlx_core_oldapi/mssql/connection/
mod.rsuse crate::common::StatementCache;
use crate::connection::{Connection, LogSettings};
use crate::error::Error;
use crate::executor::Executor;
use crate::mssql::connection::stream::MssqlStream;
use crate::mssql::statement::MssqlStatementMetadata;
use crate::mssql::{Mssql, MssqlConnectOptions};
use crate::transaction::Transaction;
use futures_core::future::BoxFuture;
use futures_util::{FutureExt, TryFutureExt};
use std::fmt::{self, Debug, Formatter};
use std::sync::Arc;
mod establish;
mod executor;
mod prepare;
mod stream;
mod tls_prelogin_stream_wrapper;
pub struct MssqlConnection {
pub(crate) stream: MssqlStream,
pub(crate) cache_statement: StatementCache<Arc<MssqlStatementMetadata>>,
log_settings: LogSettings,
}
impl Debug for MssqlConnection {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("MssqlConnection").finish()
}
}
use std::ops::DerefMut;
impl Connection for MssqlConnection {
type Database = Mssql;
type Options = MssqlConnectOptions;
#[allow(unused_mut)]
fn close(mut self) -> BoxFuture<'static, Result<(), Error>> {
#[cfg(feature = "_rt-async-std")]
{
use std::future::ready;
use std::net::Shutdown;
ready(self.stream.shutdown(Shutdown::Both).map_err(Into::into)).boxed()
}
#[cfg(feature = "_rt-tokio")]
{
use sqlx_rt::AsyncWriteExt;
async move { self.stream.shutdown().await.map_err(Into::into) }.boxed()
}
}
fn close_hard(self) -> BoxFuture<'static, Result<(), Error>> {
self.close()
}
fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> {
self.execute("/* SQLx ping */").map_ok(|_| ()).boxed()
}
fn begin(&mut self) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>>
where
Self: Sized,
{
Transaction::begin(self)
}
#[doc(hidden)]
fn flush(&mut self) -> BoxFuture<'_, Result<(), Error>> {
self.stream.wait_until_ready().boxed()
}
#[doc(hidden)]
fn should_flush(&self) -> bool {
!self.stream.wbuf.is_empty()
}
}