Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\PDO;
4
 
5
use Doctrine\DBAL\Driver\PDO\SQLSrv\Statement;
6
use Doctrine\DBAL\Driver\Result;
7
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
8
use Doctrine\DBAL\Driver\Statement as StatementInterface;
9
use Doctrine\DBAL\ParameterType;
10
use PDO;
11
 
12
class SqlServerConnection implements ServerInfoAwareConnection
13
{
14
    /**
15
     * The underlying connection instance.
16
     *
17
     * @var \Illuminate\Database\PDO\Connection
18
     */
19
    protected $connection;
20
 
21
    /**
22
     * Create a new SQL Server connection instance.
23
     *
24
     * @param  \Illuminate\Database\PDO\Connection  $connection
25
     * @return void
26
     */
27
    public function __construct(Connection $connection)
28
    {
29
        $this->connection = $connection;
30
    }
31
 
32
    /**
33
     * Prepare a new SQL statement.
34
     *
35
     * @param  string  $sql
36
     * @return \Doctrine\DBAL\Driver\Statement
37
     */
38
    public function prepare(string $sql): StatementInterface
39
    {
40
        return new Statement(
41
            $this->connection->prepare($sql)
42
        );
43
    }
44
 
45
    /**
46
     * Execute a new query against the connection.
47
     *
48
     * @param  string  $sql
49
     * @return \Doctrine\DBAL\Driver\Result
50
     */
51
    public function query(string $sql): Result
52
    {
53
        return $this->connection->query($sql);
54
    }
55
 
56
    /**
57
     * Execute an SQL statement.
58
     *
59
     * @param  string  $statement
60
     * @return int
61
     */
62
    public function exec(string $statement): int
63
    {
64
        return $this->connection->exec($statement);
65
    }
66
 
67
    /**
68
     * Get the last insert ID.
69
     *
70
     * @param  string|null  $name
71
     * @return mixed
72
     */
73
    public function lastInsertId($name = null)
74
    {
75
        if ($name === null) {
76
            return $this->connection->lastInsertId($name);
77
        }
78
 
79
        return $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?')
80
            ->execute([$name])
81
            ->fetchOne();
82
    }
83
 
84
    /**
85
     * Begin a new database transaction.
86
     *
87
     * @return void
88
     */
89
    public function beginTransaction()
90
    {
91
        return $this->connection->beginTransaction();
92
    }
93
 
94
    /**
95
     * Commit a database transaction.
96
     *
97
     * @return void
98
     */
99
    public function commit()
100
    {
101
        return $this->connection->commit();
102
    }
103
 
104
    /**
105
     * Rollback a database transaction.
106
     *
107
     * @return void
108
     */
109
    public function rollBack()
110
    {
111
        return $this->connection->rollBack();
112
    }
113
 
114
    /**
115
     * Wrap quotes around the given input.
116
     *
117
     * @param  string  $value
118
     * @param  int  $type
119
     * @return string
120
     */
121
    public function quote($value, $type = ParameterType::STRING)
122
    {
123
        $val = $this->connection->quote($value, $type);
124
 
125
        // Fix for a driver version terminating all values with null byte...
126
        if (\is_string($val) && str_contains($val, "\0")) {
127
            $val = \substr($val, 0, -1);
128
        }
129
 
130
        return $val;
131
    }
132
 
133
    /**
134
     * Get the server version for the connection.
135
     *
136
     * @return string
137
     */
138
    public function getServerVersion()
139
    {
140
        return $this->connection->getServerVersion();
141
    }
142
 
143
    /**
144
     * Get the wrapped PDO connection.
145
     *
146
     * @return \PDO
147
     */
148
    public function getWrappedConnection(): PDO
149
    {
150
        return $this->connection->getWrappedConnection();
151
    }
152
}