diff --git a/odbc-api/src/connection.rs b/odbc-api/src/connection.rs index c17cfd79..45ec1d88 100644 --- a/odbc-api/src/connection.rs +++ b/odbc-api/src/connection.rs @@ -372,6 +372,11 @@ impl<'c> Connection<'c> { self.connection.is_dead().into_result(&self.connection) } + /// Network packet size in bytes. Requries driver support. + pub fn packet_size(&self) -> Result { + self.connection.packet_size().into_result(&self.connection) + } + /// Get the name of the database management system used by the connection. pub fn database_management_system_name(&self) -> Result { let mut buf = Vec::new(); diff --git a/odbc-api/src/handles/connection.rs b/odbc-api/src/handles/connection.rs index bbf3e542..82ea37ee 100644 --- a/odbc-api/src/handles/connection.rs +++ b/odbc-api/src/handles/connection.rs @@ -383,6 +383,11 @@ impl<'c> Connection<'c> { } } + /// Networ packet size in bytes. + pub fn packet_size(&self) -> SqlResult { + unsafe { self.attribute_u32(ConnectionAttribute::PacketSize) } + } + /// # Safety /// /// Caller must ensure connection attribute is numeric. diff --git a/odbc-api/tests/integration.rs b/odbc-api/tests/integration.rs index 5749ed5f..4c7dcbbe 100644 --- a/odbc-api/tests/integration.rs +++ b/odbc-api/tests/integration.rs @@ -125,6 +125,17 @@ fn connect_to_db(profile: &Profile) { assert!(!conn.is_dead().unwrap()) } +#[test_case(MSSQL, 4096; "Microsoft SQL Server")] +#[test_case(MARIADB, 8192; "Maria DB")] +#[test_case(SQLITE_3, 16384; "SQLite 3")] +#[test_case(POSTGRES, 4096; "PostgreSQL")] +fn default_packet_size(profile: &Profile, expected_packet_size: u32) { + let conn = profile.connection().unwrap(); + let actual_packet_size = conn.packet_size().unwrap(); + + assert_eq!(expected_packet_size, actual_packet_size) +} + #[test_case(MSSQL; "Microsoft SQL Server")] fn describe_columns(profile: &Profile) { let table_name = table_name!();