pub fn escape_name(name: &str) -> Result<String>Expand description
Escapes a SQL identifier for safe use in queries.
This function properly quotes and escapes a name to prevent SQL injection. The result is wrapped in double quotes with internal quotes escaped.
§Errors
Returns an error if the name exceeds the PostgreSQL identifier limit (63 characters).
This behavior is consistent with Name::try_new().
§Example
use hyperdb_api::{escape_name, Result};
fn demo() -> Result<()> {
let escaped = escape_name("my_table")?;
assert_eq!(escaped, "\"my_table\"");
let special = escape_name("table\"with\"quotes")?;
assert_eq!(special, "\"table\"\"with\"\"quotes\"");
Ok(())
}
// Names exceeding 63 characters are rejected
let long_name = "a".repeat(64);
assert!(escape_name(&long_name).is_err());