Skip to main content

StringLiteral

Enum StringLiteral 

Source
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

Source

pub const CASES: [(StringLiteral, &'static str); 4]

The names of the cases, as PHP declares them.

Source

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().

Source

pub const fn escapes_in_plain_literal(self) -> bool

Whether a backslash escapes in a literal without a prefix.

PHP: escapesInPlainLiteral().

Source

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'");
Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for StringLiteral

Source§

impl Debug for StringLiteral

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StringLiteral

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for StringLiteral

Source§

impl PartialEq for StringLiteral

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StringLiteral

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.