final class SqlQuoteProfile

How one dialect closes a run of text it opened with a quote.

Strings and identifiers are both written between delimiters, and a dialect decides which pairs spell each, whether a run may instead be closed by a tag of its own, and whether a backslash escapes inside a string.

Methods§

public function __construct(
    array<string, string> $stringQuotePairs,
    array<string, string> $identifierQuotePairs,
    private string|null $dollarQuoteDelimiterPattern,
    list<string> $backslashEscapedStringPrefixes,
    private bool $backslashEscapedStrings,
    private LexicalPattern $patterns = new \ZtdQuery\Sql\LexicalPattern(),
    LexicalDelimiters $delimiters = new \ZtdQuery\Sql\LexicalDelimiters(),
)

Parameters

$stringQuotePairsarray<string, string>Opening quote => the one that closes the string
$identifierQuotePairsarray<string, string>Opening quote => the one that closes the identifier
$dollarQuoteDelimiterPatternstring|nullPattern a dollar-quoted delimiter is written as, or null where the dialect has none
$backslashEscapedStringPrefixeslist<string>Prefixes that make the string they introduce use backslash escapes
$backslashEscapedStringsboolWhether every string uses backslash escapes
$patternsLexicalPatternReads a regular expression against a position
$delimitersLexicalDelimitersRefuses lexical data a scanner could not use

Throws

InvalidDefinitionException When a delimiter is empty or a pattern is unreadable
Calls 5
public function stringQuoteClosing(string $opening): string|null

Answers the quote that closes a string this one opened.

Parameters

$openingstringQuote that opened it

Returns

string|null The closing quote, or null when nothing opens a string with that
Called from 1
public function identifierQuoteClosing(string $opening): string|null

Answers the quote that closes an identifier this one opened.

Parameters

$openingstringQuote that opened it

Returns

string|null The closing quote, or null when nothing opens an identifier with that
Called from 1
public function unquoteIdentifier(string $identifier): string

Answers the name a quoted identifier stands for.

A closing quote doubled inside the name is one such character rather than the end of it, which is how every dialect here writes a quote in a name.

Parameters

$identifierstringIdentifier as it was written

Returns

string The name, or the identifier unchanged when it was not quoted
Called from 1
Calls 5
public function quotedIdentifierValue(string $identifier): string|null

Answers the name a quoted identifier stands for, and nothing for anything else.

This differs from unquoteIdentifier() in what it says about an identifier that was never quoted: here that is not an identifier this can speak for, rather than one that stands for itself.

Parameters

$identifierstringIdentifier as it was written

Returns

string|null The name, or null when it was not a complete quoted identifier
Called from 1
Calls 5
public function dollarQuoteDelimiterAt(string $sql, int $offset): string|null

Answers the dollar-quoted delimiter starting here, if any.

Parameters

$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

string|null The delimiter, or null when none starts there
Called from 1
Calls 1
public function stringUsesBackslashEscapes(
    string $sql,
    int $quoteOffset,
    SqlSymbolProfile $symbols,
): bool

Reports whether the string opening here treats a backslash as an escape.

Some dialects say so for every string; others only for a string introduced by a particular prefix, and only where that prefix is a prefix rather than the tail of an identifier, which is why what spells an identifier is asked.

Parameters

$sqlstringStatement being scanned
$quoteOffsetintPosition of the quote that opens the string
$symbolsSqlSymbolProfileWhat the dialect spells an identifier with

Returns

bool True when a backslash escapes inside it
Called from 1
Calls 3

Private surface 6§

Implementation details, listed for orientation only.

private array<non-empty-string, non-empty-string> $stringQuotePairs
private array<non-empty-string, non-empty-string> $identifierQuotePairs
private list<non-empty-string> $backslashEscapedStringPrefixes
private string|null $dollarQuoteDelimiterPattern
private bool $backslashEscapedStrings
private LexicalPattern $patterns = new \ZtdQuery\Sql\LexicalPattern()

Test cases 12§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 1
Other tests reaching this symbol 11

Relations§

Instantiated in 1
Method calls 6
Type declarations 1