pub trait ToSql {
// Required methods
fn to_sql(&self) -> Result<SqlValue, TypeError>;
fn sql_type(&self) -> &'static str;
// Provided method
fn encrypted_param_type(&self) -> Option<EncryptedParamType> { ... }
}Expand description
Trait for types that can be converted to SQL values.
This trait is implemented for common Rust types to enable type-safe parameter binding in queries.
Required Methods§
Provided Methods§
Sourcefn encrypted_param_type(&self) -> Option<EncryptedParamType>
fn encrypted_param_type(&self) -> Option<EncryptedParamType>
The explicit SQL type a parameter must be declared and encrypted as, when the value alone cannot convey it.
Returns None for every type except the typed-parameter wrappers
(e.g. numeric, datetime2, time). An Always Encrypted column
requires the declared type — including precision, scale, or length — to
match the column exactly, which a bare value cannot always express (a
Decimal carries no precision; a NaiveDateTime is ambiguous between
datetime and datetime2(n)). The driver uses this to declare the
parameter for sp_describe_parameter_encryption and to normalize the
value before encryption.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl ToSql for DateTime<FixedOffset>
Available on crate feature chrono only.
impl ToSql for DateTime<FixedOffset>
chrono only.Source§impl ToSql for NaiveDateTime
Available on crate feature chrono only.
impl ToSql for NaiveDateTime
chrono only.Implementors§
impl ToSql for Binary
impl ToSql for Char
impl ToSql for DateTime2
chrono only.impl ToSql for DateTimeLegacy
chrono only.impl ToSql for DateTimeOffset
chrono only.impl ToSql for Money
decimal only.impl ToSql for NChar
impl ToSql for Numeric
decimal only.impl ToSql for SmallDateTime
chrono only.impl ToSql for SmallMoney
decimal only.impl ToSql for Time
chrono only.