1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* @copyright 2020 Christoph Wurst <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @author 2020 Christoph Wurst <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace OC\DB; |
27
|
|
|
|
28
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
29
|
|
|
use Doctrine\DBAL\Schema\Schema; |
30
|
|
|
use OCP\DB\IPreparedStatement; |
31
|
|
|
use OCP\DB\IResult; |
32
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
33
|
|
|
use OCP\IDBConnection; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Adapts the public API to our internal DBAL connection wrapper |
37
|
|
|
*/ |
38
|
|
|
class ConnectionAdapter implements IDBConnection { |
39
|
|
|
|
40
|
|
|
/** @var Connection */ |
41
|
|
|
private $inner; |
42
|
|
|
|
43
|
|
|
public function __construct(Connection $inner) { |
44
|
|
|
$this->inner = $inner; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getQueryBuilder(): IQueryBuilder { |
48
|
|
|
return $this->inner->getQueryBuilder(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function prepare($sql, $limit = null, $offset = null): IPreparedStatement { |
52
|
|
|
return new PreparedStatement( |
53
|
|
|
$this->inner->prepare($sql, $limit, $offset) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function executeQuery(string $sql, array $params = [], $types = []): IResult { |
58
|
|
|
return new ResultAdapter( |
59
|
|
|
$this->inner->executeQuery($sql, $params, $types) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function executeUpdate(string $sql, array $params = [], array $types = []): int { |
64
|
|
|
return $this->inner->executeUpdate($sql, $params, $types); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function executeStatement($sql, array $params = [], array $types = []): int { |
68
|
|
|
return $this->inner->executeStatement($sql, $params, $types); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function lastInsertId(string $table): int { |
72
|
|
|
return (int) $this->inner->lastInsertId($table); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function insertIfNotExist(string $table, array $input, array $compare = null) { |
76
|
|
|
return $this->inner->insertIfNotExist($table, $input, $compare); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function insertIgnoreConflict(string $table, array $values): int { |
80
|
|
|
return $this->inner->insertIgnoreConflict($table, $values); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []): int { |
84
|
|
|
return $this->inner->setValues($table, $keys, $values, $updatePreconditionValues); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function lockTable($tableName): void { |
88
|
|
|
$this->inner->lockTable($tableName); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function unlockTable(): void { |
92
|
|
|
$this->inner->unlockTable(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function beginTransaction(): void { |
96
|
|
|
$this->inner->beginTransaction(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function inTransaction(): bool { |
100
|
|
|
return $this->inner->inTransaction(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function commit(): void { |
104
|
|
|
$this->inner->commit(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function rollBack(): void { |
108
|
|
|
$this->inner->rollBack(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getError(): string { |
112
|
|
|
return $this->inner->getError(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function errorCode() { |
116
|
|
|
return $this->inner->errorCode(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function errorInfo() { |
120
|
|
|
return $this->inner->errorInfo(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function connect(): bool { |
124
|
|
|
return $this->inner->connect(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function close(): void { |
128
|
|
|
$this->inner->close(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function quote($input, $type = IQueryBuilder::PARAM_STR) { |
132
|
|
|
return $this->inner->quote($input, $type); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @todo we are leaking a 3rdparty type here |
137
|
|
|
*/ |
138
|
|
|
public function getDatabasePlatform(): AbstractPlatform { |
139
|
|
|
return $this->inner->getDatabasePlatform(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function dropTable(string $table): void { |
143
|
|
|
$this->inner->dropTable($table); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function tableExists(string $table): bool { |
147
|
|
|
return $this->inner->tableExists($table); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function escapeLikeParameter(string $param): string { |
151
|
|
|
return $this->inner->escapeLikeParameter($param); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function supports4ByteText(): bool { |
155
|
|
|
return $this->inner->supports4ByteText(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @todo leaks a 3rdparty type |
160
|
|
|
*/ |
161
|
|
|
public function createSchema(): Schema { |
162
|
|
|
return $this->inner->createSchema(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function migrateToSchema(Schema $toSchema): void { |
166
|
|
|
$this->inner->migrateToSchema($toSchema); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function getInner(): Connection { |
170
|
|
|
return $this->inner; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|