Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky committed Apr 23, 2024
1 parent cf9eecd commit b6848ea
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target
Cargo.lock
.idea
.direnv/
.vscode
1 change: 1 addition & 0 deletions src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Config {

#[derive(Clone, Debug)]
pub(crate) enum TrustConfig {
#[allow(dead_code)]
CaCertificateLocation(PathBuf),
TrustAll,
Default,
Expand Down
4 changes: 2 additions & 2 deletions src/client/config/ado_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions src/client/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin + Send> Connection<S> {

/// 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,
Expand Down
8 changes: 5 additions & 3 deletions src/tds/codec/column_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl<'a> Encode<BytesMutWithTypeInfo<'a>> 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);
}
Expand Down Expand Up @@ -502,7 +502,8 @@ impl<'a> Encode<BytesMutWithTypeInfo<'a>> 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);
}
Expand All @@ -527,7 +528,8 @@ impl<'a> Encode<BytesMutWithTypeInfo<'a>> 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
Expand Down
2 changes: 1 addition & 1 deletion src/tds/codec/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions src/tds/collation.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/tds/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Context {
}

pub fn last_meta(&self) -> Option<Arc<TokenColMetaData<'static>>> {
self.last_meta.as_ref().map(Arc::clone)
self.last_meta.clone()
}

pub fn packet_size(&self) -> u32 {
Expand Down
4 changes: 2 additions & 2 deletions src/tds/time/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions tests/bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b6848ea

Please sign in to comment.