Class Sqlserver
SQLServer driver.
Constants
-
string
FEATURE_CTE ¶'cte'
Common Table Expressions (with clause) support.
-
string
FEATURE_DISABLE_CONSTRAINT_WITHOUT_TRANSACTION ¶'disable-constraint-without-transaction'
Disabling constraints without being in transaction support.
-
string
FEATURE_JSON ¶'json'
Native JSON data type support.
-
string
FEATURE_QUOTE ¶'quote'
PDO::quote() support.
-
string
FEATURE_SAVEPOINT ¶'savepoint'
Transaction savepoint support.
-
string
FEATURE_TRUNCATE_WITH_CONSTRAINTS ¶'truncate-with-constraints'
Truncate with foreign keys attached support.
-
string
FEATURE_WINDOW ¶'window'
Window function support (all or partial clauses).
-
int|null
MAX_ALIAS_LENGTH ¶128
-
array<int>
RETRY_ERROR_CODES ¶[40613]
Property Summary
-
$_autoQuoting protected
bool
Indicates whether the driver is doing automatic identifier quoting for all queries
-
$_baseConfig protected
array<string, mixed>
Base configuration settings for Sqlserver driver
-
$_config protected
array<string, mixed>
Configuration data.
-
$_connection protected
PDO
Instance of PDO.
-
$_endQuote protected
string
String used to end a database identifier quoting to make it safe
-
$_schemaDialect protected
Cake\Database\Schema\SqlserverSchemaDialect|null
The schema dialect class for this driver
-
$_startQuote protected
string
String used to start a database identifier quoting to make it safe
-
$_version protected
string|null
The server version
-
$connectRetries protected
int
The last number of connection retry attempts.
Method Summary
-
__construct() public
Constructor
-
__debugInfo() public
Returns an array that can be used to describe the internal state of this object.
-
__destruct() public
Destructor
-
_connect() protected
Establishes a connection to the database server
-
_deleteQueryTranslator() protected
Apply translation steps to delete queries.
-
_expressionTranslators() protected
Returns an associative array of methods that will transform Expression objects to conform with the specific SQL dialect. Keys are class names and values a method in this class.
-
_insertQueryTranslator() protected
Apply translation steps to insert queries.
-
_pagingSubquery() protected
Generate a paging subquery for older versions of SQLserver.
-
_removeAliasesFromConditions() protected
Removes aliases from the
WHERE
clause of a query. -
_selectQueryTranslator() protected
Apply translation steps to select queries.
-
_transformDistinct() protected
Returns the passed query after rewriting the DISTINCT clause, so that drivers that do not support the "ON" part can provide the actual way it should be done
-
_transformFunctionExpression() protected
Receives a FunctionExpression and changes it so that it conforms to this SQL dialect.
-
_transformTupleComparison() protected
Receives a TupleExpression and changes it so that it conforms to this SQL dialect.
-
_updateQueryTranslator() protected
Apply translation steps to update queries.
-
beginTransaction() public
Starts a transaction.
-
commitTransaction() public
Commits a transaction.
-
compileQuery() public
Transforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
-
connect() public
Establishes a connection to the database server.
-
disableAutoQuoting() public
Disable auto quoting of identifiers in queries.
-
disableForeignKeySQL() public
Get the SQL for disabling foreign keys.
-
disconnect() public
Disconnects from database server.
-
enableAutoQuoting() public
Sets whether this driver should automatically quote identifiers in queries.
-
enableForeignKeySQL() public
Get the SQL for enabling foreign keys.
-
enabled() public
Returns whether PHP is able to use this driver for connecting to database
-
getConnectRetries() public
Returns the number of connection retry attempts made.
-
getConnection() public
Get the internal PDO connection instance.
-
getMaxAliasLength() public
Returns the maximum alias length allowed. This can be different from the maximum identifier length for columns.
-
inTransaction() public
Returns whether a transaction is active for connection.
-
isAutoQuotingEnabled() public
Returns whether this driver should automatically quote identifiers in queries.
-
isConnected() public
Checks whether the driver is connected.
-
lastInsertId() public
Returns last id generated for a table or sequence in database.
-
newCompiler() public
Returns an instance of a QueryCompiler.
-
newTableSchema() public
Constructs new TableSchema.
-
prepare() public
Prepares a sql statement to be executed
-
queryTranslator() public
Returns a callable function that will be used to transform a passed Query object. This function, in turn, will return an instance of a Query object that has been transformed to accommodate any specificities of the SQL dialect in use.
-
quote() public
Returns a value in a safe representation to be used in a query string
-
quoteIdentifier() public
Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words
-
releaseSavePointSQL() public
Returns a SQL snippet for releasing a previously created save point
-
rollbackSavePointSQL() public
Returns a SQL snippet for rollbacking a previously created save point
-
rollbackTransaction() public
Rollbacks a transaction.
-
savePointSQL() public
Returns a SQL snippet for creating a new transaction savepoint
-
schema() public
Returns the schema name that's being used.
-
schemaDialect() public
Get the schema dialect.
-
schemaValue() public
Escapes values for use in schema definitions.
-
setConnection() public
Set the internal PDO connection instance.
-
supports() public
Returns whether the driver supports the feature.
-
supportsCTEs() public deprecated
Returns true if the server supports common table expressions.
-
supportsDynamicConstraints() public
Returns whether the driver supports adding or dropping constraints to already created tables.
-
supportsQuoting() public deprecated
Checks if the driver supports quoting, as PDO_ODBC does not support it.
-
supportsSavePoints() public
Returns whether this driver supports save points for nested transactions.
-
version() public
Returns connected server version.
Method Detail
__construct() ¶ public
__construct(array<string, mixed> $config = [])
Constructor
Parameters
-
array<string, mixed>
$config optional The configuration for the driver.
Throws
InvalidArgumentException
__debugInfo() ¶ public
__debugInfo(): array<string, mixed>
Returns an array that can be used to describe the internal state of this object.
Returns
array<string, mixed>
_connect() ¶ protected
_connect(string $dsn, array<string, mixed> $config): bool
Establishes a connection to the database server
Parameters
-
string
$dsn A Driver-specific PDO-DSN
-
array<string, mixed>
$config configuration to be used for creating connection
Returns
bool
_deleteQueryTranslator() ¶ protected
_deleteQueryTranslator(Cake\Database\Query $query): Cake\Database\Query
Apply translation steps to delete queries.
Chops out aliases on delete query conditions as most database dialects do not support aliases in delete queries. This also removes aliases in table names as they frequently don't work either.
We are intentionally not supporting deletes with joins as they have even poorer support.
Parameters
-
Cake\Database\Query
$query The query to translate
Returns
Cake\Database\Query
_expressionTranslators() ¶ protected
_expressionTranslators(): array<string>
Returns an associative array of methods that will transform Expression objects to conform with the specific SQL dialect. Keys are class names and values a method in this class.
Returns
array<string>
_insertQueryTranslator() ¶ protected
_insertQueryTranslator(Cake\Database\Query $query): Cake\Database\Query
Apply translation steps to insert queries.
Parameters
-
Cake\Database\Query
$query The query to translate
Returns
Cake\Database\Query
_pagingSubquery() ¶ protected
_pagingSubquery(Cake\Database\Query $original, int|null $limit, int|null $offset): Cake\Database\Query
Generate a paging subquery for older versions of SQLserver.
Prior to SQLServer 2012 there was no equivalent to LIMIT OFFSET, so a subquery must be used.
Parameters
-
Cake\Database\Query
$original The query to wrap in a subquery.
-
int|null
$limit The number of rows to fetch.
-
int|null
$offset The number of rows to offset.
Returns
Cake\Database\Query
_removeAliasesFromConditions() ¶ protected
_removeAliasesFromConditions(Cake\Database\Query $query): Cake\Database\Query
Removes aliases from the WHERE
clause of a query.
Parameters
-
Cake\Database\Query
$query The query to process.
Returns
Cake\Database\Query
Throws
RuntimeException
In case the processed query contains any joins, as removing aliases from the conditions can break references to the joined tables.
_selectQueryTranslator() ¶ protected
_selectQueryTranslator(Cake\Database\Query $query): Cake\Database\Query
Apply translation steps to select queries.
Parameters
-
Cake\Database\Query
$query
Returns
Cake\Database\Query
_transformDistinct() ¶ protected
_transformDistinct(Cake\Database\Query $query): Cake\Database\Query
Returns the passed query after rewriting the DISTINCT clause, so that drivers that do not support the "ON" part can provide the actual way it should be done
Parameters
-
Cake\Database\Query
$query
Returns
Cake\Database\Query
_transformFunctionExpression() ¶ protected
_transformFunctionExpression(Cake\Database\Expression\FunctionExpression $expression): void
Receives a FunctionExpression and changes it so that it conforms to this SQL dialect.
Parameters
-
Cake\Database\Expression\FunctionExpression
$expression The function expression to convert to TSQL.
Returns
void
_transformTupleComparison() ¶ protected
_transformTupleComparison(Cake\Database\Expression\TupleComparison $expression, Cake\Database\Query $query): void
Receives a TupleExpression and changes it so that it conforms to this SQL dialect.
It transforms expressions looking like '(a, b) IN ((c, d), (e, f))' into an equivalent expression of the form '((a = c) AND (b = d)) OR ((a = e) AND (b = f))'.
It can also transform transform expressions where the right hand side is a query selecting the same amount of columns as the elements in the left hand side of the expression:
(a, b) IN (SELECT c, d FROM a_table) is transformed into
1 = (SELECT 1 FROM a_table WHERE (a = c) AND (b = d))
Parameters
-
Cake\Database\Expression\TupleComparison
$expression The expression to transform
-
Cake\Database\Query
$query The query to update.
Returns
void
_updateQueryTranslator() ¶ protected
_updateQueryTranslator(Cake\Database\Query $query): Cake\Database\Query
Apply translation steps to update queries.
Chops out aliases on update query conditions as not all database dialects do support aliases in update queries.
Just like for delete queries, joins are currently not supported for update queries.
Parameters
-
Cake\Database\Query
$query The query to translate
Returns
Cake\Database\Query
compileQuery() ¶ public
compileQuery(Cake\Database\Query $query, Cake\Database\ValueBinder $binder): array
Transforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
Parameters
-
Cake\Database\Query
$query -
Cake\Database\ValueBinder
$binder
Returns
array
connect() ¶ public
connect(): bool
Establishes a connection to the database server.
Please note that the PDO::ATTR_PERSISTENT attribute is not supported by the SQL Server PHP PDO drivers. As a result you cannot use the persistent config option when connecting to a SQL Server (for more information see: https://github.com/Microsoft/msphpsql/issues/65).
Returns
bool
Throws
InvalidArgumentException
if an unsupported setting is in the driver config
disableAutoQuoting() ¶ public
disableAutoQuoting(): $this
Disable auto quoting of identifiers in queries.
Returns
$this
disableForeignKeySQL() ¶ public
disableForeignKeySQL(): string
Get the SQL for disabling foreign keys.
Returns
string
enableAutoQuoting() ¶ public
enableAutoQuoting(bool $enable = true): $this
Sets whether this driver should automatically quote identifiers in queries.
Parameters
-
bool
$enable optional
Returns
$this
enableForeignKeySQL() ¶ public
enableForeignKeySQL(): string
Get the SQL for enabling foreign keys.
Returns
string
enabled() ¶ public
enabled(): bool
Returns whether PHP is able to use this driver for connecting to database
Returns
bool
getConnectRetries() ¶ public
getConnectRetries(): int
Returns the number of connection retry attempts made.
Returns
int
getMaxAliasLength() ¶ public
getMaxAliasLength(): int|null
Returns the maximum alias length allowed. This can be different from the maximum identifier length for columns.
Returns
int|null
inTransaction() ¶ public
inTransaction(): bool
Returns whether a transaction is active for connection.
Returns
bool
isAutoQuotingEnabled() ¶ public
isAutoQuotingEnabled(): bool
Returns whether this driver should automatically quote identifiers in queries.
Returns
bool
lastInsertId() ¶ public
lastInsertId(string|null $table = null, string|null $column = null): string|int
Returns last id generated for a table or sequence in database.
Parameters
-
string|null
$table optional -
string|null
$column optional
Returns
string|int
newCompiler() ¶ public
newCompiler(): Cake\Database\SqlserverCompiler
Returns an instance of a QueryCompiler.
Returns
Cake\Database\SqlserverCompiler
newTableSchema() ¶ public
newTableSchema(string $table, array $columns = []): Cake\Database\Schema\TableSchema
Constructs new TableSchema.
Parameters
-
string
$table -
array
$columns optional
Returns
Cake\Database\Schema\TableSchema
prepare() ¶ public
prepare(Cake\Database\Query|string $query): Cake\Database\StatementInterface
Prepares a sql statement to be executed
Parameters
-
Cake\Database\Query|string
$query The query to prepare.
Returns
Cake\Database\StatementInterface
queryTranslator() ¶ public
queryTranslator(string $type): Closure
Returns a callable function that will be used to transform a passed Query object. This function, in turn, will return an instance of a Query object that has been transformed to accommodate any specificities of the SQL dialect in use.
Parameters
-
string
$type the type of query to be transformed (select, insert, update, delete)
Returns
Closure
quote() ¶ public
quote(mixed $value, int $type = PDO::PARAM_STR): string
Returns a value in a safe representation to be used in a query string
Parameters
-
mixed
$value -
int
$type optional
Returns
string
quoteIdentifier() ¶ public
quoteIdentifier(string $identifier): string
Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words
Parameters
-
string
$identifier The identifier to quote.
Returns
string
releaseSavePointSQL() ¶ public
releaseSavePointSQL(string|int $name): string
Returns a SQL snippet for releasing a previously created save point
Parameters
-
string|int
$name
Returns
string
rollbackSavePointSQL() ¶ public
rollbackSavePointSQL(string|int $name): string
Returns a SQL snippet for rollbacking a previously created save point
Parameters
-
string|int
$name
Returns
string
savePointSQL() ¶ public
savePointSQL(string|int $name): string
Returns a SQL snippet for creating a new transaction savepoint
Parameters
-
string|int
$name
Returns
string
schemaDialect() ¶ public
schemaDialect(): Cake\Database\Schema\SchemaDialect
Get the schema dialect.
Used by {@link \Cake\Database\Schema} package to reflect schema and generate schema.
If all the tables that use this Driver specify their own schemas, then this may return null.
Returns
Cake\Database\Schema\SchemaDialect
schemaValue() ¶ public
schemaValue(mixed $value): string
Escapes values for use in schema definitions.
Parameters
-
mixed
$value
Returns
string
setConnection() ¶ public
setConnection(object $connection): $this
Set the internal PDO connection instance.
Parameters
-
object
$connection PDO instance.
Returns
$this
supports() ¶ public
supports(string $feature): bool
Returns whether the driver supports the feature.
Defaults to true for FEATURE_QUOTE and FEATURE_SAVEPOINT.
Parameters
-
string
$feature
Returns
bool
supportsCTEs() ¶ public
supportsCTEs(): bool
Returns true if the server supports common table expressions.
Returns
bool
supportsDynamicConstraints() ¶ public
supportsDynamicConstraints(): bool
Returns whether the driver supports adding or dropping constraints to already created tables.
Returns
bool
supportsQuoting() ¶ public
supportsQuoting(): bool
Checks if the driver supports quoting, as PDO_ODBC does not support it.
Returns
bool
supportsSavePoints() ¶ public
supportsSavePoints(): bool
Returns whether this driver supports save points for nested transactions.
Returns
bool
Property Detail
$_autoQuoting ¶ protected
Indicates whether the driver is doing automatic identifier quoting for all queries
Type
bool
$_schemaDialect ¶ protected
The schema dialect class for this driver
Type
Cake\Database\Schema\SqlserverSchemaDialect|null
$_startQuote ¶ protected
String used to start a database identifier quoting to make it safe
Type
string