Skip to main content

escape_ruby_double_quoted

Function escape_ruby_double_quoted 

Source
pub fn escape_ruby_double_quoted(sql: &str) -> String
Expand description

Escape SQL text for splicing into a Ruby double-quoted "..." string literal.

Ruby double-quoted strings interpolate on #{expression}; SQL text containing that sequence would otherwise splice an in-scope variable’s value into the query the same way Kotlin’s $name does. Ruby double-quoted strings freely contain literal newlines and tabs, so only backslash, the closing quote, and a literal #{ need escaping.

Used by ruby-pg, ruby-sqlite3, ruby-mysql2, ruby-oci8, ruby-trilogy, and ruby-tiny-tds (on the raw SQL text, before that backend’s own #{client.escape(...)} parameter interpolations are spliced in – see that backend for why order matters there).