Quoter
API reference › yii › db › mssql › Quoter
Provides connection-free helpers for quoting MSSQL values and identifiers when building SQL.
Unlike Schema::quoteValue(), the helpers never open a database connection, so they are safe to call
while QueryBuilder assembles dynamic SQL ahead of execution.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
escapeLiteralValue() static | Escapes single quotes in a value for embedding as a Transact-SQL string literal. | Quoter |
extractSimpleIdentifier() static | Returns the trailing single-part identifier of a bracket-quoted qualified name, keeping its brackets. | Quoter |
isIdentifierBracketQuoted() static | Returns whether an identifier is already wrapped in MSSQL square brackets ([identifier]). | Quoter |
Method details
Section titled “Method details”escapeLiteralValue()
Section titled “escapeLiteralValue() ”public static function escapeLiteralValue(string $value): stringEscapes 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:
$literal = \yii\db\mssql\Quoter::escapeLiteralValue("O'Brien"); // O''Brien$sql = "DECLARE @name SYSNAME = N'{$literal}'";Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string | Value to escape. |
Returns
string: Value with single quotes doubled, ready to embed inside a quoted literal.
extractSimpleIdentifier()
Section titled “extractSimpleIdentifier() ”public static function extractSimpleIdentifier(string $name): stringReturns 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:
\yii\db\mssql\Quoter::extractSimpleIdentifier('[schema].[table]'); // [table]\yii\db\mssql\Quoter::extractSimpleIdentifier('[table]'); // [table]Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Bracket-quoted qualified identifier. |
Returns
string: Trailing single-part identifier with brackets preserved.
isIdentifierBracketQuoted()
Section titled “isIdentifierBracketQuoted() ”public static function isIdentifierBracketQuoted(string $identifier): boolReturns 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:
\yii\db\mssql\Quoter::isIdentifierBracketQuoted('[user]'); // true\yii\db\mssql\Quoter::isIdentifierBracketQuoted('user'); // falseParameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | Identifier to inspect. |
Returns
bool: Whether the identifier is already bracket-quoted.