Skip to content

Commit

Permalink
fix: improve column type info
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky committed Jul 17, 2024
1 parent b197032 commit 294d7d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 12 additions & 2 deletions src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,21 @@ impl From<&TypeInfo> for ColumnType {
},
TypeInfo::VarLenSized(cx) => match cx.r#type() {
VarLenType::Guid => Self::Guid,
VarLenType::Intn => Self::Intn,
VarLenType::Intn => match cx.len() {
1 => Self::Int1,
2 => Self::Int2,
4 => Self::Int4,
8 => Self::Int8,
_ => Self::Intn,
},
VarLenType::Bitn => Self::Bitn,
VarLenType::Decimaln => Self::Decimaln,
VarLenType::Numericn => Self::Numericn,
VarLenType::Floatn => Self::Floatn,
VarLenType::Floatn => match cx.len() {
4 => Self::Float4,
8 => Self::Float8,
_ => Self::Floatn,
},
VarLenType::Money => Self::Money,
VarLenType::Datetimen => Self::Datetimen,
#[cfg(feature = "tds73")]
Expand Down
6 changes: 3 additions & 3 deletions src/tds/time/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ from_sql!(
let offset = chrono::Duration::minutes(dto.offset as i64);
let naive = NaiveDateTime::new(date, time).sub(offset);

chrono::DateTime::from_naive_utc_and_offset(naive, Utc)
chrono::DateTime::from_utc(naive, Utc)

Check warning on line 84 in src/tds/time/chrono.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead

warning: use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead --> src/tds/time/chrono.rs:84:31 | 84 | chrono::DateTime::from_utc(naive, Utc) | ^^^^^^^^

Check warning on line 84 in src/tds/time/chrono.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead

warning: use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead --> src/tds/time/chrono.rs:84:31 | 84 | chrono::DateTime::from_utc(naive, Utc) | ^^^^^^^^ | = note: `#[warn(deprecated)]` on by default
}),
ColumnData::DateTime2(ref dt2) => dt2.map(|dt2| {
let date = from_days(dt2.date.days() as i64, 1);
let ns = dt2.time.increments as i64 * 10i64.pow(9 - dt2.time.scale as u32);
let time = NaiveTime::from_hms_opt(0,0,0).unwrap() + chrono::Duration::nanoseconds(ns);
let naive = NaiveDateTime::new(date, time);

chrono::DateTime::from_naive_utc_and_offset(naive, Utc)
chrono::DateTime::from_utc(naive, Utc)

Check warning on line 92 in src/tds/time/chrono.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead

warning: use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead --> src/tds/time/chrono.rs:92:31 | 92 | chrono::DateTime::from_utc(naive, Utc) | ^^^^^^^^

Check warning on line 92 in src/tds/time/chrono.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead

warning: use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead --> src/tds/time/chrono.rs:92:31 | 92 | chrono::DateTime::from_utc(naive, Utc) | ^^^^^^^^
});
chrono::DateTime<FixedOffset>: ColumnData::DateTimeOffset(ref dto) => dto.map(|dto| {
let date = from_days(dto.datetime2.date.days() as i64, 1);
Expand All @@ -99,7 +99,7 @@ from_sql!(
let offset = FixedOffset::east_opt((dto.offset as i32) * 60).unwrap();
let naive = NaiveDateTime::new(date, time);

chrono::DateTime::from_naive_utc_and_offset(naive, offset)
chrono::DateTime::from_utc(naive, offset)

Check warning on line 102 in src/tds/time/chrono.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead

warning: use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead --> src/tds/time/chrono.rs:102:27 | 102 | chrono::DateTime::from_utc(naive, offset) | ^^^^^^^^

Check warning on line 102 in src/tds/time/chrono.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead

warning: use of deprecated associated function `chrono::DateTime::<Tz>::from_utc`: Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead --> src/tds/time/chrono.rs:102:27 | 102 | chrono::DateTime::from_utc(naive, offset) | ^^^^^^^^
})
);

Expand Down
6 changes: 3 additions & 3 deletions tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,7 @@ where
.unwrap()
.and_hms_opt(16, 20, 0)
.unwrap();
let dt: DateTime<Utc> = DateTime::from_naive_utc_and_offset(naive, Utc);
let dt: DateTime<Utc> = DateTime::from_utc(naive, Utc);

let row = conn
.query("SELECT @P1", &[&dt])
Expand Down Expand Up @@ -2276,7 +2276,7 @@ where
.unwrap();

let fixed = FixedOffset::east_opt(3600 * 3).unwrap();
let dt: DateTime<FixedOffset> = DateTime::from_naive_utc_and_offset(naive, fixed);
let dt: DateTime<FixedOffset> = DateTime::from_utc(naive, fixed);

let row = conn
.query("SELECT @P1", &[&dt])
Expand Down Expand Up @@ -2314,7 +2314,7 @@ where
.and_hms_opt(16, 20, 0)
.unwrap();
let fixed = FixedOffset::east_opt(3600 * 3).unwrap();
let dt: DateTime<FixedOffset> = DateTime::from_naive_utc_and_offset(naive, fixed);
let dt: DateTime<FixedOffset> = DateTime::from_utc(naive, fixed);

let row = conn
.query(format!("SELECT CAST('{}' AS datetimeoffset(7))", dt), &[])
Expand Down

0 comments on commit 294d7d7

Please sign in to comment.