pub fn escape_attribute_value(unescaped: &str) -> Cow<'_, str>
Expand description

You can use this method to escape a password so it is suitable to be appended to an ODBC connection string as the value for the PWD attribute. This method is only of interest for application in need to create their own connection strings.

See:

Example

use odbc_api::escape_attribute_value;

let password = "abc;123}";
let user = "SA";
let mut connection_string_without_credentials =
    "Driver={ODBC Driver 17 for SQL Server};Server=localhost;";

let connection_string = format!(
    "{}UID={};PWD={};",
    connection_string_without_credentials,
    user,
    escape_attribute_value(password)
);

assert_eq!(
    "Driver={ODBC Driver 17 for SQL Server};Server=localhost;UID=SA;PWD={abc;123}}};",
    connection_string
);
use odbc_api::escape_attribute_value;
assert_eq!("abc", escape_attribute_value("abc"));
assert_eq!("ab}c", escape_attribute_value("ab}c"));
assert_eq!("{ab;c}", escape_attribute_value("ab;c"));
assert_eq!("{a}}b;c}", escape_attribute_value("a}b;c"));
assert_eq!("{ab+c}", escape_attribute_value("ab+c"));