Sqlserver
extends Driver
in package
uses
SqlDialectTrait, TupleComparisonTranslatorTrait
SQLServer driver.
Table of Contents
Constants
- MAX_ALIAS_LENGTH = 128
- RETRY_ERROR_CODES = [40613]
Properties
- $_autoQuoting : bool
- Indicates whether the driver is doing automatic identifier quoting for all queries
- $_baseConfig : array<string, mixed>
- Base configuration settings for Sqlserver driver
- $_config : array<string, mixed>
- Configuration data.
- $_connection : PDO
- Instance of PDO.
- $_endQuote : string
- String used to end a database identifier quoting to make it safe
- $_schemaDialect : SqlserverSchemaDialect|null
- The schema dialect class for this driver
- $_startQuote : string
- String used to start a database identifier quoting to make it safe
- $_version : string|null
- The server version
- $connectRetries : int
- The last number of connection retry attempts.
Methods
- __construct() : mixed
- Constructor
- __debugInfo() : array<string, mixed>
- Returns an array that can be used to describe the internal state of this object.
- __destruct() : mixed
- Destructor
- beginTransaction() : bool
- Starts a transaction.
- commitTransaction() : bool
- Commits a transaction.
- compileQuery() : array<string|int, mixed>
- Transforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
- connect() : bool
- Establishes a connection to the database server.
- disableAutoQuoting() : $this
- Disable auto quoting of identifiers in queries.
- disableForeignKeySQL() : string
- Get the SQL for disabling foreign keys.
- disconnect() : void
- Disconnects from database server.
- enableAutoQuoting() : $this
- Sets whether this driver should automatically quote identifiers in queries.
- enabled() : bool
- Returns whether PHP is able to use this driver for connecting to database
- enableForeignKeySQL() : string
- Get the SQL for enabling foreign keys.
- getConnection() : PDO
- Get the internal PDO connection instance.
- getConnectRetries() : int
- Returns the number of connection retry attempts made.
- getMaxAliasLength() : int|null
- Returns the maximum alias length allowed.
- inTransaction() : bool
- Returns whether a transaction is active for connection.
- isAutoQuotingEnabled() : bool
- Returns whether this driver should automatically quote identifiers in queries.
- isConnected() : bool
- Checks whether the driver is connected.
- lastInsertId() : string|int
- Returns last id generated for a table or sequence in database.
- newCompiler() : SqlserverCompiler
- Returns an instance of a QueryCompiler.
- newTableSchema() : TableSchema
- Constructs new TableSchema.
- prepare() : StatementInterface
- Prepares a sql statement to be executed
- queryTranslator() : Closure
- Returns a callable function that will be used to transform a passed Query object.
- quote() : string
- Returns a value in a safe representation to be used in a query string
- quoteIdentifier() : string
- Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words.
- releaseSavePointSQL() : string
- Get the SQL for releasing a save point.
- rollbackSavePointSQL() : string
- Get the SQL for rollingback a save point.
- rollbackTransaction() : bool
- Rollbacks a transaction.
- savePointSQL() : string
- Get the SQL for creating a save point.
- schema() : string
- Returns the schema name that's being used.
- schemaDialect() : SchemaDialect
- Get the schema dialect.
- schemaValue() : string
- Escapes values for use in schema definitions.
- setConnection() : $this
- Set the internal PDO connection instance.
- supports() : bool
- Returns whether the driver supports the feature.
- supportsCTEs() : bool
- Returns true if the server supports common table expressions.
- supportsDynamicConstraints() : bool
- Returns whether the driver supports adding or dropping constraints to already created tables.
- supportsQuoting() : bool
- Checks if the driver supports quoting, as PDO_ODBC does not support it.
- supportsSavePoints() : bool
- Returns whether this driver supports save points for nested transactions.
- version() : string
- Returns connected server version.
- _connect() : bool
- Establishes a connection to the database server
- _expressionTranslators() : array<string|int, mixed>
- _pagingSubquery() : Query
- Generate a paging subquery for older versions of SQLserver.
- _selectQueryTranslator() : Query
- _transformDistinct() : Query
- _transformFunctionExpression() : void
- Receives a FunctionExpression and changes it so that it conforms to this SQL dialect.
Constants
MAX_ALIAS_LENGTH
protected
int|null
MAX_ALIAS_LENGTH
= 128
Maximum alias length or null if no limit
Tags
RETRY_ERROR_CODES
protected
array<string|int, int>
RETRY_ERROR_CODES
= [40613]
DB-specific error codes that allow connect retry
Tags
Properties
$_autoQuoting
Indicates whether the driver is doing automatic identifier quoting for all queries
protected
bool
$_autoQuoting
= false
$_baseConfig
Base configuration settings for Sqlserver driver
protected
array<string, mixed>
$_baseConfig
= [
'host' => 'localhost\SQLEXPRESS',
'username' => '',
'password' => '',
'database' => 'cake',
'port' => '',
// PDO::SQLSRV_ENCODING_UTF8
'encoding' => 65001,
'flags' => [],
'init' => [],
'settings' => [],
'attributes' => [],
'app' => null,
'connectionPooling' => null,
'failoverPartner' => null,
'loginTimeout' => null,
'multiSubnetFailover' => null,
'encrypt' => null,
'trustServerCertificate' => null,
]
$_config
Configuration data.
protected
array<string, mixed>
$_config
$_connection
Instance of PDO.
protected
PDO
$_connection
$_endQuote
String used to end a database identifier quoting to make it safe
protected
string
$_endQuote
= ']'
$_schemaDialect
The schema dialect class for this driver
protected
SqlserverSchemaDialect|null
$_schemaDialect
$_startQuote
String used to start a database identifier quoting to make it safe
protected
string
$_startQuote
= '['
$_version
The server version
protected
string|null
$_version
$connectRetries
The last number of connection retry attempts.
protected
int
$connectRetries
= 0
Methods
__construct()
Constructor
public
__construct([array<string, mixed> $config = [] ]) : mixed
Parameters
- $config : array<string, mixed> = []
-
The configuration for the driver.
Tags
__debugInfo()
Returns an array that can be used to describe the internal state of this object.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__destruct()
Destructor
public
__destruct() : mixed
beginTransaction()
Starts a transaction.
public
beginTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
commitTransaction()
Commits a transaction.
public
commitTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
compileQuery()
Transforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
public
compileQuery(Query $query, ValueBinder $binder) : array<string|int, mixed>
Parameters
- $query : Query
-
The query to compile.
- $binder : ValueBinder
-
The value binder to use.
Tags
Return values
array<string|int, mixed> —containing 2 entries. The first entity is the transformed query and the second one the compiled SQL.
connect()
Establishes a connection to the database server.
public
connect() : bool
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).
Tags
Return values
bool —true on success
disableAutoQuoting()
Disable auto quoting of identifiers in queries.
public
disableAutoQuoting() : $this
Tags
Return values
$thisdisableForeignKeySQL()
Get the SQL for disabling foreign keys.
public
disableForeignKeySQL() : string
Tags
Return values
stringdisconnect()
Disconnects from database server.
public
disconnect() : void
Tags
enableAutoQuoting()
Sets whether this driver should automatically quote identifiers in queries.
public
enableAutoQuoting([bool $enable = true ]) : $this
Parameters
- $enable : bool = true
-
Whether to enable auto quoting
Tags
Return values
$thisenabled()
Returns whether PHP is able to use this driver for connecting to database
public
enabled() : bool
Return values
bool —true if it is valid to use this driver
enableForeignKeySQL()
Get the SQL for enabling foreign keys.
public
enableForeignKeySQL() : string
Tags
Return values
stringgetConnection()
Get the internal PDO connection instance.
public
getConnection() : PDO
Return values
PDOgetConnectRetries()
Returns the number of connection retry attempts made.
public
getConnectRetries() : int
Return values
intgetMaxAliasLength()
Returns the maximum alias length allowed.
public
getMaxAliasLength() : int|null
This can be different from the maximum identifier length for columns.
Return values
int|null —Maximum alias length or null if no limit
inTransaction()
Returns whether a transaction is active for connection.
public
inTransaction() : bool
Return values
boolisAutoQuotingEnabled()
Returns whether this driver should automatically quote identifiers in queries.
public
isAutoQuotingEnabled() : bool
Tags
Return values
boolisConnected()
Checks whether the driver is connected.
public
isConnected() : bool
Tags
Return values
boollastInsertId()
Returns last id generated for a table or sequence in database.
public
lastInsertId([string|null $table = null ][, string|null $column = null ]) : string|int
Parameters
- $table : string|null = null
-
table name or sequence to get last insert value from.
- $column : string|null = null
-
the name of the column representing the primary key.
Tags
Return values
string|intnewCompiler()
Returns an instance of a QueryCompiler.
public
newCompiler() : SqlserverCompiler
Return values
SqlserverCompilernewTableSchema()
Constructs new TableSchema.
public
newTableSchema(string $table[, array<string|int, mixed> $columns = [] ]) : TableSchema
Parameters
- $table : string
-
The table name.
- $columns : array<string|int, mixed> = []
-
The list of columns for the schema.
Tags
Return values
TableSchemaprepare()
Prepares a sql statement to be executed
public
prepare(Query|string $query) : StatementInterface
Parameters
- $query : Query|string
-
The query to prepare.
Return values
StatementInterfacequeryTranslator()
Returns a callable function that will be used to transform a passed Query object.
public
abstract queryTranslator(string $type) : Closure
Parameters
- $type : string
-
The type of query to be transformed (select, insert, update, delete).
Tags
Return values
Closurequote()
Returns a value in a safe representation to be used in a query string
public
quote(mixed $value[, mixed $type = PDO::PARAM_STR ]) : string
Parameters
- $value : mixed
-
The value to quote.
- $type : mixed = PDO::PARAM_STR
-
Must be one of the \PDO::PARAM_* constants
Tags
Return values
stringquoteIdentifier()
Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words.
public
abstract quoteIdentifier(string $identifier) : string
Parameters
- $identifier : string
-
The identifier expression to quote.
Tags
Return values
stringreleaseSavePointSQL()
Get the SQL for releasing a save point.
public
releaseSavePointSQL(mixed $name) : string
Parameters
- $name : mixed
-
Save point name or id
Tags
Return values
stringrollbackSavePointSQL()
Get the SQL for rollingback a save point.
public
rollbackSavePointSQL(mixed $name) : string
Parameters
- $name : mixed
-
Save point name or id
Tags
Return values
stringrollbackTransaction()
Rollbacks a transaction.
public
rollbackTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
savePointSQL()
Get the SQL for creating a save point.
public
savePointSQL(mixed $name) : string
Parameters
- $name : mixed
-
Save point name or id
Tags
Return values
stringschema()
Returns the schema name that's being used.
public
schema() : string
Tags
Return values
stringschemaDialect()
Get the schema dialect.
public
schemaDialect() : SchemaDialect
Tags
Return values
SchemaDialectschemaValue()
Escapes values for use in schema definitions.
public
schemaValue(mixed $value) : string
Parameters
- $value : mixed
-
The value to escape.
Tags
Return values
string —String for use in schema definitions.
setConnection()
Set the internal PDO connection instance.
public
setConnection(PDO $connection) : $this
Parameters
- $connection : PDO
-
PDO instance.
Tags
Return values
$thissupports()
Returns whether the driver supports the feature.
public
supports(string $feature) : bool
Parameters
- $feature : string
-
Driver feature name
Tags
Return values
boolsupportsCTEs()
Returns true if the server supports common table expressions.
public
supportsCTEs() : bool
Use supports(DriverInterface::FEATURE_QUOTE)
instead
Return values
boolsupportsDynamicConstraints()
Returns whether the driver supports adding or dropping constraints to already created tables.
public
supportsDynamicConstraints() : bool
Tags
Return values
bool —True if driver supports dynamic constraints.
supportsQuoting()
Checks if the driver supports quoting, as PDO_ODBC does not support it.
public
supportsQuoting() : bool
Use supports(DriverInterface::FEATURE_QUOTE)
instead
Return values
boolsupportsSavePoints()
Returns whether this driver supports save points for nested transactions.
public
supportsSavePoints() : bool
Tags
Return values
bool —True if save points are supported, false otherwise.
version()
Returns connected server version.
public
version() : string
Return values
string_connect()
Establishes a connection to the database server
protected
_connect(string $dsn, array<string, mixed> $config) : bool
Parameters
- $dsn : string
-
A Driver-specific PDO-DSN
- $config : array<string, mixed>
-
configuration to be used for creating connection
Return values
bool —true on success
_expressionTranslators()
protected
_expressionTranslators() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>_pagingSubquery()
Generate a paging subquery for older versions of SQLserver.
protected
_pagingSubquery(Query $original, int|null $limit, int|null $offset) : Query
Prior to SQLServer 2012 there was no equivalent to LIMIT OFFSET, so a subquery must be used.
Parameters
- $original : Query
-
The query to wrap in a subquery.
- $limit : int|null
-
The number of rows to fetch.
- $offset : int|null
-
The number of rows to offset.
Return values
Query —Modified query object.
_selectQueryTranslator()
protected
_selectQueryTranslator(Query $query) : Query
Parameters
- $query : Query
Tags
Return values
Query_transformDistinct()
protected
_transformDistinct(Query $query) : Query
Parameters
- $query : Query
Tags
Return values
Query_transformFunctionExpression()
Receives a FunctionExpression and changes it so that it conforms to this SQL dialect.
protected
_transformFunctionExpression(FunctionExpression $expression) : void
Parameters
- $expression : FunctionExpression
-
The function expression to convert to TSQL.