Expand description
§mssql-value-serializer
Convert Rust values into SQL Server-compatible literal expressions, enabling dynamic SQL generation without parameter count limitations.
Prepared statements are commonly used to improve performance and security. By separating the SQL command from the data values, the database can cache execution plans and protect against SQL injection. Each variable passed to the query becomes a parameter, allowing safe reuse of the same statement with different values. However, because SQL Server enforces a strict 2100-parameter limit, queries that bind large collections of parameters—such as long IN lists or bulk inserts—can easily exceed this cap and trigger the too many parameters error.
§Usage
use mssql_value_serializer::{SqlServerCharWrapper, SqlServerLiteralWrapper, SqlServerLiteralDynWrapper, SqlServerLiteralForValueListWrapper};
let sql = format!("
SELECT
*
FROM
[table]
WHERE
[name] = {name}
", name = SqlServerLiteralWrapper::new("David"));
assert_eq!("
SELECT
*
FROM
[table]
WHERE
[name] = N'David'
", sql);
let sql = format!("
SELECT
*
FROM
[table]
WHERE
[name] = {name}
", name = SqlServerCharWrapper::new("David")); // use `SqlServerCharWrapper` to format a value into a non-Unicode character string
assert_eq!("
SELECT
*
FROM
[table]
WHERE
[name] = 'David'
", sql);
let sql = format!("
INSERT INTO [table]([id], [name], [disabled])
VALUES
({values})
", values = SqlServerLiteralForValueListWrapper::new(vec![SqlServerLiteralDynWrapper::from(2u32), SqlServerLiteralDynWrapper::from("David"), SqlServerLiteralDynWrapper::from(false)]));
assert_eq!("
INSERT INTO [table]([id], [name], [disabled])
VALUES
(2, N'David', 0)
", sql);§Optional Features
serde: Implementsserde::Serializefor wrapper types, enabling SQL Server literal serialization behavior.chronoortime: Adds support for SQL Server date and time types.chronoandstable-local: If your local timezone does not observe daylight saving time (DST), enable this feature to use a fixed offset forDateTime<Local>, improving formatting performance.
rust_decimalorbigdecimal: Adds support for SQL Server decimal/numeric types.num-bigint: Adds support for SQL Server decimal/numeric types (only integers).uuid: Adds support for SQL Server UNIQUEIDENTIFIER type.
Structs§
- SqlLiteral
Error With Index - Errors that occur when serializing a SQL Server literal for a value list.
- SqlServer
Char Wrapper - A wrapper type for string values.
- SqlServer
Literal ForValue List Wrapper - A wrapper type for any value implementing
SqlServerLiteralForValueList. - SqlServer
Literal Wrapper - A wrapper type for any value implementing
SqlServerLiteral.
Enums§
- SqlLiteral
Error - Errors that occur when serializing a SQL Server literal.
- SqlServer
Literal DynWrapper - A wrapper type that can hold either a borrowed or owned [
dyn SqlServerLiteral] value.
Traits§
- SqlServer
Literal - Represents a type that can be converted into a valid SQL Server literal.
- SqlServer
Literal ForValue List - Represents a type that can serialize a collection of SQL Server literal values.
Functions§
- append_
sql_ literal_ for_ value_ list - Appends a comma-separated list of SQL Server literals to the provided output string.