pub enum StringLiteral {
Backslash,
BackslashUtf8,
Extended,
Standard,
}Expand description
The rules a dialect’s string literals follow.
PHP: Utopia\Query\StringLiteral.
Variants§
Backslash
MySQL and MariaDB: a backslash escapes in every literal, and one after a byte of 0x80 or above is refused.
BackslashUtf8
ClickHouse: a backslash escapes, and the connection is always UTF-8.
Extended
PostgreSQL: a backslash escapes only in E'...'.
Standard
SQLite: a backslash is a character like any other.
Implementations§
Source§impl StringLiteral
impl StringLiteral
Sourcepub const CASES: [(StringLiteral, &'static str); 4]
pub const CASES: [(StringLiteral, &'static str); 4]
The names of the cases, as PHP declares them.
Sourcepub const fn escape_prefix(self) -> &'static str
pub const fn escape_prefix(self) -> &'static str
The letter before the quote of a literal whose backslashes escape: E
for PostgreSQL, nothing elsewhere.
PHP: escapePrefix().
Sourcepub const fn escapes_in_plain_literal(self) -> bool
pub const fn escapes_in_plain_literal(self) -> bool
Whether a backslash escapes in a literal without a prefix.
PHP: escapesInPlainLiteral().
Sourcepub fn quote(self, value: &str) -> Result<String>
pub fn quote(self, value: &str) -> Result<String>
value as a literal of the dialect. A NUL byte is refused where the
dialect has none, and so is a backslash after a character above 127
where a multibyte connection charset could read the pair as one
character.
PHP: quote().
use utopia_query::StringLiteral;
assert_eq!(StringLiteral::Backslash.quote("it's a\\b")?, "'it''s a\\\\b'");
assert_eq!(StringLiteral::Extended.quote("a\\b")?, "E'a\\\\b'");
assert_eq!(StringLiteral::Standard.quote("a\\b")?, "'a\\b'");Sourcepub fn unquote(self, literal: &[u8]) -> Result<Vec<u8>>
pub fn unquote(self, literal: &[u8]) -> Result<Vec<u8>>
The bytes a literal of the dialect stands for.
PHP: unquote().
use utopia_query::StringLiteral;
assert_eq!(StringLiteral::Backslash.unquote(b"'a\\nb'")?, b"a\nb");
assert_eq!(StringLiteral::Extended.unquote(b"E'\\u00e9'")?, "é".as_bytes());
assert_eq!(StringLiteral::Standard.unquote(b"'a\\nb'")?, b"a\\nb");Trait Implementations§
Source§impl Clone for StringLiteral
impl Clone for StringLiteral
impl Copy for StringLiteral
Source§impl Debug for StringLiteral
impl Debug for StringLiteral
Source§impl Default for StringLiteral
impl Default for StringLiteral
impl Eq for StringLiteral
Source§impl PartialEq for StringLiteral
impl PartialEq for StringLiteral
impl StructuralPartialEq for StringLiteral
Auto Trait Implementations§
impl Forget for StringLiteral
impl Freeze for StringLiteral
impl Move for StringLiteral
impl RefUnwindSafe for StringLiteral
impl Send for StringLiteral
impl Sync for StringLiteral
impl Unpin for StringLiteral
impl UnsafeUnpin for StringLiteral
impl UnwindSafe for StringLiteral
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.