diff --git a/.gitignore b/.gitignore index 39d7d3fc..147270ed 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target Cargo.lock .idea .direnv/ +.vscode diff --git a/src/client/config.rs b/src/client/config.rs index b23ad449..fff68bc1 100644 --- a/src/client/config.rs +++ b/src/client/config.rs @@ -36,6 +36,7 @@ pub struct Config { #[derive(Clone, Debug)] pub(crate) enum TrustConfig { + #[allow(dead_code)] CaCertificateLocation(PathBuf), TrustAll, Default, diff --git a/src/client/config/ado_net.rs b/src/client/config/ado_net.rs index 09091fca..94df9ca3 100644 --- a/src/client/config/ado_net.rs +++ b/src/client/config/ado_net.rs @@ -37,14 +37,14 @@ impl ConfigString for AdoNetConfig { let parts: Vec<&str> = parts[0].split('\\').collect(); ServerDefinition { - host: Some(parts[0].replace("(local)", "localhost").into()), + host: Some(parts[0].replace("(local)", "localhost")), port, instance: Some(parts[1].into()), } } else { // Connect using a TCP target ServerDefinition { - host: Some(parts[0].replace("(local)", "localhost").into()), + host: Some(parts[0].replace("(local)", "localhost")), port: parse_port(&parts[1..])?, instance: None, } diff --git a/src/client/connection.rs b/src/client/connection.rs index 95bc25cd..c6ce1d66 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -284,6 +284,7 @@ impl Connection { /// Defines the login record rules with SQL Server. Authentication with /// connection options. + #[allow(clippy::too_many_arguments)] async fn login<'a>( mut self, auth: AuthMethod, diff --git a/src/tds/codec/column_data.rs b/src/tds/codec/column_data.rs index 6df30173..fecd83f7 100644 --- a/src/tds/codec/column_data.rs +++ b/src/tds/codec/column_data.rs @@ -341,7 +341,7 @@ impl<'a> Encode> for ColumnData<'a> { dst.put_u32_le(bytes.len() as u32); dst.extend_from_slice(bytes.as_slice()); - if bytes.len() > 0 { + if !bytes.is_empty() { // no next blob dst.put_u32_le(0u32); } @@ -502,7 +502,8 @@ impl<'a> Encode> for ColumnData<'a> { // unknown size dst.put_u64_le(0xfffffffffffffffe); dst.put_u32_le(bytes.len() as u32); - if bytes.len() > 0 { + + if !bytes.is_empty() { dst.extend(bytes.into_owned()); dst.put_u32_le(0); } @@ -527,7 +528,8 @@ impl<'a> Encode> for ColumnData<'a> { dst.put_u64_le(0xfffffffffffffffe_u64); // We'll write in one chunk, length is the whole bytes length dst.put_u32_le(bytes.len() as u32); - if bytes.len() > 0 { + + if !bytes.is_empty() { // Payload dst.extend(bytes.into_owned()); // PLP_TERMINATOR diff --git a/src/tds/codec/type_info.rs b/src/tds/codec/type_info.rs index 0b9aa624..20647d70 100644 --- a/src/tds/codec/type_info.rs +++ b/src/tds/codec/type_info.rs @@ -271,7 +271,7 @@ impl TypeInfo { Err(()) => Err(Error::Protocol( format!("invalid or unsupported column type: {:?}", ty).into(), )), - Ok(ty) if ty == VarLenType::Xml => { + Ok(VarLenType::Xml) => { let has_schema = src.read_u8().await?; let schema = if has_schema == 1 { diff --git a/src/tds/collation.rs b/src/tds/collation.rs index 13b8dbce..20367728 100644 --- a/src/tds/collation.rs +++ b/src/tds/collation.rs @@ -1,13 +1,13 @@ -use std::fmt; +//! legacy implementation of collations (or codepages rather) for dealing with varchar's with legacy databases +//! references [1] which has some mappings from the katmai (SQL Server 2008) source code and is a TDS driver +//! directly from microsoft +//! [2] is helpful to map CP1234 to the appropriate encoding +//! +//! [1] https://github.com/Microsoft/mssql-jdbc/blob/eb14f63077c47ef1fc1c690deb8cfab602baeb85/src/main/java/com/microsoft/sqlserver/jdbc/SQLCollation.java +//! [2] https://github.com/lifthrasiir/rust-encoding/blob/496823171f15d9b9446b2ec3fb7765f22346256b/src/label.rs#L282 -///! legacy implementation of collations (or codepages rather) for dealing with varchar's with legacy databases -///! references [1] which has some mappings from the katmai (SQL Server 2008) source code and is a TDS driver -///! directly from microsoft -///! [2] is helpful to map CP1234 to the appropriate encoding -///! -///! [1] https://github.com/Microsoft/mssql-jdbc/blob/eb14f63077c47ef1fc1c690deb8cfab602baeb85/src/main/java/com/microsoft/sqlserver/jdbc/SQLCollation.java -///! [2] https://github.com/lifthrasiir/rust-encoding/blob/496823171f15d9b9446b2ec3fb7765f22346256b/src/label.rs#L282 use encoding_rs::Encoding; +use std::fmt; use crate::error::Error; diff --git a/src/tds/context.rs b/src/tds/context.rs index 4c43b22b..732bac15 100644 --- a/src/tds/context.rs +++ b/src/tds/context.rs @@ -35,7 +35,7 @@ impl Context { } pub fn last_meta(&self) -> Option>> { - self.last_meta.as_ref().map(Arc::clone) + self.last_meta.clone() } pub fn packet_size(&self) -> u32 { diff --git a/src/tds/time/time.rs b/src/tds/time/time.rs index 70d1c4d3..5a2b1cfa 100644 --- a/src/tds/time/time.rs +++ b/src/tds/time/time.rs @@ -4,10 +4,10 @@ //! The time library offers better ergonomy and are highly recommended if //! needing to modify and deal with date and time in SQL Server. -pub use time::*; +use std::time::Duration; +pub use time::{Date, Month, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset}; use crate::tds::codec::ColumnData; -use std::time::Duration; #[inline] fn from_days(days: u64, start_year: i32) -> Date { diff --git a/tests/bulk.rs b/tests/bulk.rs index 2e12a38a..9f491edc 100644 --- a/tests/bulk.rs +++ b/tests/bulk.rs @@ -112,9 +112,21 @@ test_bulk_type!(smallint("SMALLINT", 2000, 0..2000i16)); test_bulk_type!(int("INT", 2000, 0..2000i32)); test_bulk_type!(bigint("BIGINT", 2000, 0..2000i64)); -test_bulk_type!(empty_varchar("VARCHAR(MAX)", 1, [""].into_iter())); -test_bulk_type!(empty_nvarchar("NVARCHAR(MAX)", 1, [""].into_iter())); -test_bulk_type!(empty_varbinary("VARBINARY(MAX)", 1, [b""].into_iter())); +test_bulk_type!(empty_varchar( + "VARCHAR(MAX)", + 100, + vec![""; 100].into_iter() +)); +test_bulk_type!(empty_nvarchar( + "NVARCHAR(MAX)", + 100, + vec![""; 100].into_iter() +)); +test_bulk_type!(empty_varbinary( + "VARBINARY(MAX)", + 100, + vec![b""; 100].into_iter() +)); test_bulk_type!(real( "REAL",