1 |
cb15593b
|
Cajova-Houba
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace Illuminate\Database;
|
4 |
|
|
|
5 |
|
|
use Closure;
|
6 |
|
|
use Exception;
|
7 |
|
|
use Throwable;
|
8 |
|
|
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as DoctrineDriver;
|
9 |
|
|
use Illuminate\Database\Query\Processors\SqlServerProcessor;
|
10 |
|
|
use Illuminate\Database\Query\Grammars\SqlServerGrammar as QueryGrammar;
|
11 |
|
|
use Illuminate\Database\Schema\Grammars\SqlServerGrammar as SchemaGrammar;
|
12 |
|
|
|
13 |
|
|
class SqlServerConnection extends Connection
|
14 |
|
|
{
|
15 |
|
|
/**
|
16 |
|
|
* Execute a Closure within a transaction.
|
17 |
|
|
*
|
18 |
|
|
* @param \Closure $callback
|
19 |
|
|
* @return mixed
|
20 |
|
|
*
|
21 |
|
|
* @throws \Exception|\Throwable
|
22 |
|
|
*/
|
23 |
|
|
public function transaction(Closure $callback)
|
24 |
|
|
{
|
25 |
|
|
if ($this->getDriverName() == 'sqlsrv') {
|
26 |
|
|
return parent::transaction($callback);
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
$this->getPdo()->exec('BEGIN TRAN');
|
30 |
|
|
|
31 |
|
|
// We'll simply execute the given callback within a try / catch block
|
32 |
|
|
// and if we catch any exception we can rollback the transaction
|
33 |
|
|
// so that none of the changes are persisted to the database.
|
34 |
|
|
try {
|
35 |
|
|
$result = $callback($this);
|
36 |
|
|
|
37 |
|
|
$this->getPdo()->exec('COMMIT TRAN');
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
// If we catch an exception, we will roll back so nothing gets messed
|
41 |
|
|
// up in the database. Then we'll re-throw the exception so it can
|
42 |
|
|
// be handled how the developer sees fit for their applications.
|
43 |
|
|
catch (Exception $e) {
|
44 |
|
|
$this->getPdo()->exec('ROLLBACK TRAN');
|
45 |
|
|
|
46 |
|
|
throw $e;
|
47 |
|
|
} catch (Throwable $e) {
|
48 |
|
|
$this->getPdo()->exec('ROLLBACK TRAN');
|
49 |
|
|
|
50 |
|
|
throw $e;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
return $result;
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
/**
|
57 |
|
|
* Get the default query grammar instance.
|
58 |
|
|
*
|
59 |
|
|
* @return \Illuminate\Database\Query\Grammars\SqlServerGrammar
|
60 |
|
|
*/
|
61 |
|
|
protected function getDefaultQueryGrammar()
|
62 |
|
|
{
|
63 |
|
|
return $this->withTablePrefix(new QueryGrammar);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
|
|
* Get the default schema grammar instance.
|
68 |
|
|
*
|
69 |
|
|
* @return \Illuminate\Database\Schema\Grammars\SqlServerGrammar
|
70 |
|
|
*/
|
71 |
|
|
protected function getDefaultSchemaGrammar()
|
72 |
|
|
{
|
73 |
|
|
return $this->withTablePrefix(new SchemaGrammar);
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* Get the default post processor instance.
|
78 |
|
|
*
|
79 |
|
|
* @return \Illuminate\Database\Query\Processors\SqlServerProcessor
|
80 |
|
|
*/
|
81 |
|
|
protected function getDefaultPostProcessor()
|
82 |
|
|
{
|
83 |
|
|
return new SqlServerProcessor;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* Get the Doctrine DBAL driver.
|
88 |
|
|
*
|
89 |
|
|
* @return \Doctrine\DBAL\Driver\PDOSqlsrv\Driver
|
90 |
|
|
*/
|
91 |
|
|
protected function getDoctrineDriver()
|
92 |
|
|
{
|
93 |
|
|
return new DoctrineDriver;
|
94 |
|
|
}
|
95 |
|
|
}
|