diff --git a/src/client/config.rs b/src/client/config.rs index fff68bc1..e57f278f 100644 --- a/src/client/config.rs +++ b/src/client/config.rs @@ -32,6 +32,7 @@ pub struct Config { pub(crate) trust: TrustConfig, pub(crate) auth: AuthMethod, pub(crate) readonly: bool, + pub(crate) packet_size: Option, } #[derive(Clone, Debug)] @@ -65,6 +66,7 @@ impl Default for Config { trust: TrustConfig::Default, auth: AuthMethod::None, readonly: false, + packet_size: None, } } } @@ -115,6 +117,22 @@ impl Config { self.application_name = Some(name.to_string()); } + /// Sets the TDS packet size for the connection. + /// + /// Larger packet sizes can improve bulk insert performance by reducing + /// the number of network round-trips. Valid values are 512 to 32767. + /// The server may negotiate a different size. + /// + /// - Defaults to 4096 bytes. + pub fn packet_size(&mut self, size: u32) { + self.packet_size = Some(size); + } + + /// Gets the configured packet size, if set. + pub fn get_packet_size(&self) -> Option { + self.packet_size + } + /// Set the preferred encryption level. /// /// - With `tls` feature, defaults to `Required`. diff --git a/src/client/connection.rs b/src/client/connection.rs index 09d37256..b283524b 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -106,6 +106,7 @@ impl Connection { config.host, config.application_name, config.readonly, + config.packet_size, prelogin, ) .await?; @@ -293,6 +294,7 @@ impl Connection { server_name: Option, application_name: Option, readonly: bool, + packet_size: Option, prelogin: PreloginMessage, ) -> crate::Result { let mut login_message = LoginMessage::new(); @@ -311,6 +313,10 @@ impl Connection { login_message.readonly(readonly); + if let Some(size) = packet_size { + login_message.packet_size(size); + } + match auth { #[cfg(all(windows, feature = "winauth"))] AuthMethod::Integrated => { diff --git a/src/tds/codec/login.rs b/src/tds/codec/login.rs index 265db381..92fc353b 100644 --- a/src/tds/codec/login.rs +++ b/src/tds/codec/login.rs @@ -240,6 +240,14 @@ impl<'a> LoginMessage<'a> { self.type_flags.remove(LoginTypeFlag::ReadOnlyIntent); } } + + /// Sets the requested TDS packet size. + /// + /// Valid values are 512 to 32767. The server may negotiate a different size. + /// Larger packet sizes can improve bulk insert performance. + pub fn packet_size(&mut self, size: u32) { + self.packet_size = size; + } } impl<'a> Encode for LoginMessage<'a> {