Class Sqlserver
SQLServer driver.
Constants
Property Summary
- 
        $_autoQuoting protectedboolIndicates whether the driver is doing automatic identifier quoting for all queries 
- 
        $_baseConfig protectedarray<string, mixed>Base configuration settings for Sqlserver driver 
- 
        $_config protectedarray<string, mixed>Configuration data. 
- 
        $_endQuote protectedstringString used to end a database identifier quoting to make it safe 
- 
        $_schemaDialect protectedCake\Database\Schema\SchemaDialectThe schema dialect for this driver 
- 
        $_startQuote protectedstringString used to start a database identifier quoting to make it safe 
- 
        $_version protectedstring|nullThe server version 
- 
        $connectRetries protectedintThe last number of connection retry attempts. 
- 
        $logger protected?LoggerInterfaceThe logger instance. 
- 
        $pdo protectedPDO|nullInstance of PDO. 
- 
        $quoter protectedCake\Database\IdentifierQuoter|nullIdentifier quoter 
Method Summary
- 
          __construct() publicConstructor 
- 
          __debugInfo() publicReturns an array that can be used to describe the internal state of this object. 
- 
          __destruct() publicDestructor 
- 
          _deleteQueryTranslator() protectedApply translation steps to delete queries. 
- 
          _expressionTranslators() protectedReturns 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() protectedApply translation steps to insert queries. 
- 
          _pagingSubquery() protectedGenerate a paging subquery for older versions of SQLserver. 
- 
          _removeAliasesFromConditions() protectedRemoves aliases from the WHEREclause of a query.
- 
          _selectQueryTranslator() protectedApply translation steps to select queries. 
- 
          _transformDistinct() protectedReturns 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() protectedReceives a FunctionExpression and changes it so that it conforms to this SQL dialect. 
- 
          _transformTupleComparison() protectedReceives a TupleExpression and changes it so that it conforms to this SQL dialect. 
- 
          _updateQueryTranslator() protectedApply translation steps to update queries. 
- 
          beginTransaction() publicStarts a transaction. 
- 
          commitTransaction() publicCommits a transaction. 
- 
          compileQuery() publicTransforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string. 
- 
          config() publicGet the configuration data used to create the driver. 
- 
          connect() publicEstablishes a connection to the database server. 
- 
          createLogger() protectedCreate logger instance. 
- 
          createPdo() protectedEstablishes a connection to the database server 
- 
          disableAutoQuoting() publicDisable auto quoting of identifiers in queries. 
- 
          disableForeignKeySQL() publicGet the SQL for disabling foreign keys. 
- 
          disconnect() publicDisconnects from database server. 
- 
          enableAutoQuoting() publicSets whether this driver should automatically quote identifiers in queries. 
- 
          enableForeignKeySQL() publicGet the SQL for enabling foreign keys. 
- 
          enabled() publicReturns whether PHP is able to use this driver for connecting to database 
- 
          exec() publicExecute the SQL query using the internal PDO instance. 
- 
          execute() publicExecutes a query using $params for interpolating values and $types as a hint for each those params. 
- 
          executeStatement() protectedExecute the statement and log the query string. 
- 
          getLogger() publicGet the logger instance. 
- 
          getMaxAliasLength() publicReturns the maximum alias length allowed. 
- 
          getPdo() protectedGet the PDO connection instance. 
- 
          getRole() publicReturns the connection role this driver performs. 
- 
          inTransaction() publicReturns whether a transaction is active for connection. 
- 
          isAutoQuotingEnabled() publicReturns whether this driver should automatically quote identifiers in queries. 
- 
          isConnected() publicChecks whether the driver is connected. 
- 
          lastInsertId() publicReturns last id generated for a table or sequence in database. 
- 
          log() publicLogs a message or query using the configured logger object. 
- 
          newCompiler() public
- 
          newTableSchema() publicConstructs new TableSchema. 
- 
          prepare() publicPrepares a sql statement to be executed. 
- 
          quoteIdentifier() publicQuotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words 
- 
          quoter() publicGet identifier quoter instance. 
- 
          releaseSavePointSQL() publicReturns a SQL snippet for releasing a previously created save point 
- 
          rollbackSavePointSQL() publicReturns a SQL snippet for rollbacking a previously created save point 
- 
          rollbackTransaction() publicRollbacks a transaction. 
- 
          run() publicExecutes the provided query after compiling it for the specific driver dialect and returns the executed Statement object. 
- 
          savePointSQL() publicReturns a SQL snippet for creating a new transaction savepoint 
- 
          schema() publicReturns the schema name that's being used. 
- 
          schemaDialect() publicGet the schema dialect. 
- 
          schemaValue() publicEscapes values for use in schema definitions. 
- 
          setLogger() publicSets a logger. 
- 
          supports() publicReturns whether the driver supports the feature. 
- 
          transformQuery() protectedTransform the query to accommodate any specificities of the SQL dialect in use. 
- 
          version() publicReturns 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>_deleteQueryTranslator() ¶ protected
_deleteQueryTranslator(Cake\Database\Query\DeleteQuery $query): Cake\Database\Query\DeleteQueryApply 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\DeleteQuery$query
- The query to translate 
Returns
Cake\Database\Query\DeleteQueryThe modified query
_expressionTranslators() ¶ protected
_expressionTranslators(): array<class-string, 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<class-string, string>_insertQueryTranslator() ¶ protected
_insertQueryTranslator(Cake\Database\Query\InsertQuery $query): Cake\Database\Query\InsertQueryApply translation steps to insert queries.
Parameters
- 
                Cake\Database\Query\InsertQuery$query
- The query to translate 
Returns
Cake\Database\Query\InsertQueryThe modified query
_pagingSubquery() ¶ protected
_pagingSubquery(Cake\Database\Query\SelectQuery<mixed> $original, int|null $limit, int|null $offset): Cake\Database\Query\SelectQuery<mixed>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\SelectQuery<mixed>$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\SelectQuery<mixed>Modified query object.
_removeAliasesFromConditions() ¶ protected
_removeAliasesFromConditions(Cake\Database\Query\UpdateQuery|Cake\Database\Query\DeleteQuery $query): Cake\Database\Query\UpdateQuery|Cake\Database\Query\DeleteQueryRemoves aliases from the WHERE clause of a query.
Templates
              T
               of (\Cake\Database\Query\UpdateQuery | \Cake\Database\Query\DeleteQuery)                            Parameters
- 
                Cake\Database\Query\UpdateQuery|Cake\Database\Query\DeleteQuery$query
- The query to process. 
Returns
Cake\Database\Query\UpdateQuery|Cake\Database\Query\DeleteQueryThe modified query.
Throws
Cake\Database\Exception\DatabaseExceptionIn 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\SelectQuery<mixed> $query): Cake\Database\Query\SelectQuery<mixed>Apply translation steps to select queries.
Parameters
- 
                Cake\Database\Query\SelectQuery<mixed>$query
Returns
Cake\Database\Query\SelectQuery<mixed>_transformDistinct() ¶ protected
_transformDistinct(Cake\Database\Query\SelectQuery<mixed> $query): Cake\Database\Query\SelectQuery<mixed>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\SelectQuery<mixed>$query
Returns
Cake\Database\Query\SelectQuery<mixed>_transformFunctionExpression() ¶ protected
_transformFunctionExpression(Cake\Database\Expression\FunctionExpression $expression): voidReceives 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): voidReceives 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\UpdateQuery $query): Cake\Database\Query\UpdateQueryApply 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\UpdateQuery$query
- The query to translate 
Returns
Cake\Database\Query\UpdateQueryThe modified query
beginTransaction() ¶ public
beginTransaction(): boolStarts a transaction.
Returns
boolTrue on success, false otherwise.
commitTransaction() ¶ public
commitTransaction(): boolCommits a transaction.
Returns
boolTrue on success, false otherwise.
compileQuery() ¶ public
compileQuery(Cake\Database\Query $query, Cake\Database\ValueBinder $binder): stringTransforms 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
- The query to compile. 
- 
                Cake\Database\ValueBinder$binder
- The value binder to use. 
Returns
stringThe compiled SQL.
config() ¶ public
config(): array<string, mixed>Get the configuration data used to create the driver.
Returns
array<string, mixed>connect() ¶ public
connect(): voidEstablishes 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
voidThrows
InvalidArgumentExceptionif an unsupported setting is in the driver config
createLogger() ¶ protected
createLogger(string|null $className): Psr\Log\LoggerInterfaceCreate logger instance.
Parameters
- 
                string|null$className
- Logger's class name 
Returns
Psr\Log\LoggerInterfacecreatePdo() ¶ protected
createPdo(string $dsn, array<string, mixed> $config): PDOEstablishes 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
PDOdisableAutoQuoting() ¶ public
disableAutoQuoting(): $thisDisable auto quoting of identifiers in queries.
Returns
$thisdisableForeignKeySQL() ¶ public
disableForeignKeySQL(): stringGet the SQL for disabling foreign keys.
Returns
stringenableAutoQuoting() ¶ public
enableAutoQuoting(bool $enable = true): $thisSets whether this driver should automatically quote identifiers in queries.
Parameters
- 
                bool$enable optional
- Whether to enable auto quoting 
Returns
$thisenableForeignKeySQL() ¶ public
enableForeignKeySQL(): stringGet the SQL for enabling foreign keys.
Returns
stringenabled() ¶ public
enabled(): boolReturns whether PHP is able to use this driver for connecting to database
Returns
booltrue if it is valid to use this driver
exec() ¶ public
exec(string $sql): int|falseExecute the SQL query using the internal PDO instance.
Parameters
- 
                string$sql
- SQL query. 
Returns
int|falseexecute() ¶ public
execute(string $sql, array $params = [], array $types = []): Cake\Database\StatementInterfaceExecutes a query using $params for interpolating values and $types as a hint for each those params.
Parameters
- 
                string$sql
- SQL to be executed and interpolated with $params 
- 
                array$params optional
- List or associative array of params to be interpolated in $sql as values. 
- 
                array$types optional
- List or associative array of types to be used for casting values in query. 
Returns
Cake\Database\StatementInterfaceExecuted statement
executeStatement() ¶ protected
executeStatement(Cake\Database\StatementInterface $statement, array|null $params = null): voidExecute the statement and log the query string.
Parameters
- 
                Cake\Database\StatementInterface$statement
- Statement to execute. 
- 
                array|null$params optional
- List of values to be bound to query. 
Returns
voidgetLogger() ¶ public
getLogger(): Psr\Log\LoggerInterface|nullGet the logger instance.
Returns
Psr\Log\LoggerInterface|nullgetMaxAliasLength() ¶ public
getMaxAliasLength(): int|nullReturns the maximum alias length allowed.
This can be different from the maximum identifier length for columns.
Returns
int|nullMaximum alias length or null if no limit
getRole() ¶ public
getRole(): stringReturns the connection role this driver performs.
Returns
stringinTransaction() ¶ public
inTransaction(): boolReturns whether a transaction is active for connection.
Returns
boolisAutoQuotingEnabled() ¶ public
isAutoQuotingEnabled(): boolReturns whether this driver should automatically quote identifiers in queries.
Returns
boollastInsertId() ¶ public
lastInsertId(string|null $table = null): stringReturns last id generated for a table or sequence in database.
Parameters
- 
                string|null$table optional
- table name or sequence to get last insert value from. 
Returns
stringlog() ¶ public
log(Stringable|string $message, array $context = []): boolLogs a message or query using the configured logger object.
Parameters
- 
                Stringable|string$message
- Message string or query. 
- 
                array$context optional
- Logging context. 
Returns
boolTrue if message was logged.
newCompiler() ¶ public
newCompiler(): Cake\Database\SqlserverCompilerReturns
Cake\Database\SqlserverCompilernewTableSchema() ¶ public
newTableSchema(string $table, array<string, mixed> $columns = []): Cake\Database\Schema\TableSchemaInterfaceConstructs new TableSchema.
Parameters
- 
                string$table
- The table name. 
- 
                array<string, mixed>$columns optional
- The list of columns for the schema. 
Returns
Cake\Database\Schema\TableSchemaInterfaceprepare() ¶ public
prepare(Cake\Database\Query|string $query): Cake\Database\StatementInterfacePrepares a sql statement to be executed.
Parameters
- 
                Cake\Database\Query|string$query
Returns
Cake\Database\StatementInterfacequoteIdentifier() ¶ public
quoteIdentifier(string $identifier): stringQuotes 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
stringquoter() ¶ public
quoter(): Cake\Database\IdentifierQuoterGet identifier quoter instance.
Returns
Cake\Database\IdentifierQuoterreleaseSavePointSQL() ¶ public
releaseSavePointSQL(string|int $name): stringReturns a SQL snippet for releasing a previously created save point
Parameters
- 
                string|int$name
Returns
stringrollbackSavePointSQL() ¶ public
rollbackSavePointSQL(string|int $name): stringReturns a SQL snippet for rollbacking a previously created save point
Parameters
- 
                string|int$name
Returns
stringrollbackTransaction() ¶ public
rollbackTransaction(): boolRollbacks a transaction.
Returns
boolTrue on success, false otherwise.
run() ¶ public
run(Cake\Database\Query $query): Cake\Database\StatementInterfaceExecutes the provided query after compiling it for the specific driver dialect and returns the executed Statement object.
Parameters
- 
                Cake\Database\Query$query
- The query to be executed. 
Returns
Cake\Database\StatementInterfaceExecuted statement
savePointSQL() ¶ public
savePointSQL(string|int $name): stringReturns a SQL snippet for creating a new transaction savepoint
Parameters
- 
                string|int$name
Returns
stringschemaDialect() ¶ public
schemaDialect(): Cake\Database\Schema\SchemaDialectGet 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\SchemaDialectschemaValue() ¶ public
schemaValue(mixed $value): stringEscapes values for use in schema definitions.
Parameters
- 
                mixed$value
- The value to escape. 
Returns
stringString for use in schema definitions.
setLogger() ¶ public
setLogger(LoggerInterface $logger): voidSets a logger.
Parameters
- 
                LoggerInterface$logger
Returns
voidsupports() ¶ public
supports(Cake\Database\DriverFeatureEnum $feature): boolReturns whether the driver supports the feature.
Should return false for unknown features.
Parameters
- 
                Cake\Database\DriverFeatureEnum$feature
Returns
booltransformQuery() ¶ protected
transformQuery(Cake\Database\Query $query): Cake\Database\QueryTransform the query to accommodate any specificities of the SQL dialect in use.
It will also quote the identifiers if auto quoting is enabled.
Parameters
- 
                Cake\Database\Query$query
- Query to transform. 
Returns
Cake\Database\QueryProperty Detail
$_autoQuoting ¶ protected
Indicates whether the driver is doing automatic identifier quoting for all queries
Type
bool$_schemaDialect ¶ protected
The schema dialect for this driver
Type
Cake\Database\Schema\SchemaDialect$_startQuote ¶ protected
String used to start a database identifier quoting to make it safe
Type
string