Class yii\db\mssql\Quoter
| Inheritance | yii\ |
|---|---|
| Available since version | 22.0 |
| Source Code | https://github.com/yiisoft/yii2/blob/master/framework/db/mssql/Quoter.php |
Provides connection-free helpers for quoting MSSQL values and identifiers when building SQL.
Unlike {@see \
Public Methods
| Method | Description | Defined By |
|---|---|---|
| escapeLiteralValue() | Escapes single quotes in a value for embedding as a Transact-SQL string literal. | yii\ |
| extractSimpleIdentifier() | Returns the trailing single-part identifier of a bracket-quoted qualified name, keeping its brackets. | yii\ |
| isIdentifierBracketQuoted() | Returns whether an identifier is already wrapped in MSSQL square brackets ([identifier]). |
yii\ |
Method Details
Escapes single quotes in a value for embedding as a Transact-SQL string literal.
Doubles every single quote (' becomes '') without adding the surrounding quote characters, so the result can
be placed inside '...' or N'...'.
Usage example:
`php
$literal = \`
| public static string escapeLiteralValue ( string $value ) | ||
| $value | string |
Value to escape. |
| return | string |
Value with single quotes doubled, ready to embed inside a quoted literal. |
|---|---|---|
public static function escapeLiteralValue(string $value): string
{
return str_replace("'", "''", $value);
}
Returns the trailing single-part identifier of a bracket-quoted qualified name, keeping its brackets.
Splits on the last ].[ boundary; a name without that boundary is returned unchanged.
Usage example:
`php
\`
| public static string extractSimpleIdentifier ( string $name ) | ||
| $name | string |
Bracket-quoted qualified identifier. |
| return | string |
Trailing single-part identifier with brackets preserved. |
|---|---|---|
public static function extractSimpleIdentifier(string $name): string
{
$pos = strrpos($name, '].[');
if ($pos !== false) {
return substr($name, $pos + 2);
}
return $name;
}
Returns whether an identifier is already wrapped in MSSQL square brackets ([identifier]).
Canonical predicate for an already bracket-quoted identifier; the value starts with [ and ends with ].
Usage example:
`php
\`
| public static boolean isIdentifierBracketQuoted ( string $identifier ) | ||
| $identifier | string |
Identifier to inspect. |
| return | boolean |
Whether the identifier is already bracket-quoted. |
|---|---|---|
public static function isIdentifierBracketQuoted(string $identifier): bool
{
return str_starts_with($identifier, '[') && str_ends_with($identifier, ']');
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.