SqlServerConnection
class SqlServerConnection extends Connection (View source)
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
protected PDO|Closure | $pdo | The active PDO connection. |
from Connection |
protected PDO|Closure | $readPdo | The active PDO connection used for reads. |
from Connection |
protected string | $database | The name of the connected database. |
from Connection |
protected string|null | $readWriteType | The type of the connection. |
from Connection |
protected string | $tablePrefix | The table prefix for the connection. |
from Connection |
protected array | $config | The database connection configuration options. |
from Connection |
protected callable | $reconnector | The reconnector instance for the connection. |
from Connection |
protected Grammar | $queryGrammar | The query grammar implementation. |
from Connection |
protected Grammar | $schemaGrammar | The schema grammar implementation. |
from Connection |
protected Processor | $postProcessor | The query post processor implementation. |
from Connection |
protected Dispatcher|null | $events | The event dispatcher instance. |
from Connection |
protected int | $fetchMode | The default fetch mode of the connection. |
from Connection |
protected int | $transactions | The number of active transactions. |
from Connection |
protected DatabaseTransactionsManager|null | $transactionsManager | The transaction manager instance. |
from Connection |
protected bool | $recordsModified | Indicates if changes have been made to the database. |
from Connection |
protected bool | $readOnWriteConnection | Indicates if the connection should use the "write" PDO connection. |
from Connection |
protected array | $queryLog | All of the queries run against the connection. |
from Connection |
protected bool | $loggingQueries | Indicates whether queries are being logged. |
from Connection |
protected float | $totalQueryDuration | The duration of all executed queries in milliseconds. |
from Connection |
protected array | $queryDurationHandlers | All of the registered query duration handlers. |
from Connection |
protected bool | $pretending | Indicates if the connection is in a "dry run". |
from Connection |
protected Closure[] | $beforeStartingTransaction | All of the callbacks that should be invoked before a transaction is started. |
from Connection |
protected Closure[] | $beforeExecutingCallbacks | All of the callbacks that should be invoked before a query is executed. |
from Connection |
static protected Closure[] | $resolvers | The connection resolvers. |
from Connection |
Methods
Determine if the given exception was caused by a concurrency error such as a deadlock or serialization failure.
Determine if the given exception was caused by a lost connection.
Handle an exception encountered when running a transacted statement.
Handle an exception encountered when committing a transaction.
Rollback the active database transaction.
Execute the callback after a transaction commits.
Get the number of seconds until the given DateTime.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new database connection instance.
Get the default query grammar instance.
Set the schema grammar to the default implementation.
Get the default schema grammar instance.
Set the query post processor to the default implementation.
Get the default post processor instance.
Get a schema builder instance for the connection.
Begin a fluent query against a database table.
Run a select statement and return a single result.
Run a select statement and return the first column of the first row.
Run a select statement against the database.
Run a select statement against the database.
Run a select statement against the database and returns all of the result sets.
Run a select statement against the database and returns a generator.
Get the PDO connection to use for a select query.
Run an insert statement against the database.
Run an update statement against the database.
Run a delete statement against the database.
Execute an SQL statement and return the boolean result.
Run an SQL statement and get the number of rows affected.
Run a raw, unprepared query against the PDO connection.
Bind values to their parameters in the given statement.
Run a SQL statement and log its execution context.
Determine if the given database exception was caused by a unique constraint violation.
Log a query in the connection's query log.
Get the elapsed time since a given starting point.
Register a callback to be invoked when the connection queries for longer than a given amount of time.
Allow all the query duration handlers to run again, even if they have already run.
Handle a query exception.
Handle a query exception that occurred during query execution.
Reconnect to the database if a PDO connection is missing.
Register a hook to be run just before a database transaction is started.
Register a hook to be run just before a database query is executed.
Escape a value for safe SQL embedding.
Escape a binary value for safe SQL embedding.
Determine if the database connection has modified any database records.
Indicate if any records have been modified.
Indicate that the connection should use the write PDO connection for reads.
Get the current PDO connection parameter without executing any reconnect logic.
Get the current read PDO connection parameter without executing any reconnect logic.
Set the reconnect instance on the connection.
Get an option from the configuration options.
Get a human-readable name for the given connection driver.
Set the transaction manager instance on the connection.
Set the read / write type of the connection.
Get the connection resolver for the given driver.
Get the schema state for the connection.
Details
protected bool
causedByConcurrencyError(Throwable $e)
Determine if the given exception was caused by a concurrency error such as a deadlock or serialization failure.
protected bool
causedByLostConnection(Throwable $e)
Determine if the given exception was caused by a lost connection.
protected void
handleTransactionException(Throwable $e, int $currentAttempt, int $maxAttempts)
Handle an exception encountered when running a transacted statement.
protected void
handleBeginTransactionException(Throwable $e)
Handle an exception from a transaction beginning.
protected void
handleCommitTransactionException(Throwable $e, int $currentAttempt, int $maxAttempts)
Handle an exception encountered when committing a transaction.
protected int
secondsUntil(DateTimeInterface|DateInterval|int $delay)
Get the number of seconds until the given DateTime.
protected int
availableAt(DateTimeInterface|DateInterval|int $delay = 0)
Get the "available at" UNIX timestamp.
protected DateTimeInterface|int
parseDateInterval(DateTimeInterface|DateInterval|int $delay)
If the given value is an interval, convert it to a DateTime instance.
protected string
runTimeForHumans(float $startTime, float $endTime = null)
Given a start time, format the total run time for human readability.
__construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = [])
Create a new database connection instance.
Builder
table(Closure|Builder|string $table, string|null $as = null)
Begin a fluent query against a database table.
mixed
selectOne(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement and return a single result.
mixed
scalar(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement and return the first column of the first row.
array
selectFromWriteConnection(string $query, array $bindings = [])
Run a select statement against the database.
array
select(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement against the database.
array
selectResultSets(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement against the database and returns all of the result sets.
Generator
cursor(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement against the database and returns a generator.
protected PDO
getPdoForSelect(bool $useReadPdo = true)
Get the PDO connection to use for a select query.
bool
statement(string $query, array $bindings = [])
Execute an SQL statement and return the boolean result.
int
affectingStatement(string $query, array $bindings = [])
Run an SQL statement and get the number of rows affected.
void
bindValues(PDOStatement $statement, array $bindings)
Bind values to their parameters in the given statement.
protected mixed
run(string $query, array $bindings, Closure $callback)
Run a SQL statement and log its execution context.
protected mixed
runQueryCallback(string $query, array $bindings, Closure $callback)
Run a SQL statement.
protected bool
isUniqueConstraintError(Exception $exception)
Determine if the given database exception was caused by a unique constraint violation.
void
logQuery(string $query, array $bindings, float|null $time = null)
Log a query in the connection's query log.
void
whenQueryingForLongerThan(DateTimeInterface|CarbonInterval|float|int $threshold, callable $handler)
Register a callback to be invoked when the connection queries for longer than a given amount of time.
void
allowQueryDurationHandlersToRunAgain()
Allow all the query duration handlers to run again, even if they have already run.
protected mixed
handleQueryException(QueryException $e, string $query, array $bindings, Closure $callback)
Handle a query exception.
protected mixed
tryAgainIfCausedByLostConnection(QueryException $e, string $query, array $bindings, Closure $callback)
Handle a query exception that occurred during query execution.
$this
beforeStartingTransaction(Closure $callback)
Register a hook to be run just before a database transaction is started.
$this
beforeExecuting(Closure $callback)
Register a hook to be run just before a database query is executed.
string
escape(string|float|int|bool|null $value, bool $binary = false)
Escape a value for safe SQL embedding.
$this
useWriteConnectionWhenReading(bool $value = true)
Indicate that the connection should use the write PDO connection for reads.
PDO|Closure|null
getRawPdo()
Get the current PDO connection parameter without executing any reconnect logic.
PDO|Closure|null
getRawReadPdo()
Get the current read PDO connection parameter without executing any reconnect logic.
$this
setTransactionManager(DatabaseTransactionsManager $manager)
Set the transaction manager instance on the connection.