use crate::{MssqlProfile, NanosecondPolicy, PlanOptions, mssql::profile::DateTimeRounding};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct RuntimeConversionContext {
profile: MssqlProfile,
plan_options: PlanOptions,
}
impl RuntimeConversionContext {
pub(crate) const fn new(profile: MssqlProfile, plan_options: PlanOptions) -> Self {
Self {
profile,
plan_options,
}
}
#[allow(dead_code)]
pub(crate) const fn profile(self) -> MssqlProfile {
self.profile
}
#[allow(dead_code)]
pub(crate) const fn plan_options(self) -> PlanOptions {
self.plan_options
}
#[allow(dead_code)]
pub(crate) const fn nanosecond_policy(self) -> NanosecondPolicy {
self.plan_options.nanosecond_policy
}
#[allow(dead_code)]
pub(crate) const fn datetime_rounding(self) -> DateTimeRounding {
self.profile.datetime_rounding()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn selects_datetime_rounding_from_profile() {
let options = PlanOptions::default();
assert_eq!(
RuntimeConversionContext::new(MssqlProfile::sql_server_2016_compat_100(), options)
.datetime_rounding(),
DateTimeRounding::LegacyPre130
);
assert_eq!(
RuntimeConversionContext::new(MssqlProfile::sql_server_2017_compat_140(), options)
.datetime_rounding(),
DateTimeRounding::Compat130Plus
);
}
}