Completed
Pull Request — master (#29676)
by Tom
09:20
created

Db::upsert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Bernhard Posselt <[email protected]>
4
 * @author Joas Schilling <[email protected]>
5
 * @author Morris Jobke <[email protected]>
6
 * @author Robin Appelman <[email protected]>
7
 * @author Robin McCorkell <[email protected]>
8
 * @author Thomas Müller <[email protected]>
9
 * @author Tom Needham <[email protected]>
10
 *
11
 * @copyright Copyright (c) 2017, ownCloud GmbH
12
 * @license AGPL-3.0
13
 *
14
 * This code is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License, version 3,
16
 * as published by the Free Software Foundation.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License, version 3,
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
25
 *
26
 */
27
28
namespace OC\AppFramework\Db;
29
30
use Doctrine\DBAL\Schema\Schema;
31
use OCP\DB\QueryBuilder\IQueryBuilder;
32
use OCP\IDb;
33
use OCP\IDBConnection;
34
35
/**
36
 * @deprecated use IDBConnection directly, will be removed in ownCloud 10
37
 * Small Facade for being able to inject the database connection for tests
38
 */
39
class Db implements IDb {
40
	/**
41
	 * @var IDBConnection
42
	 */
43
	protected $connection;
44
45
	/**
46
	 * @param IDBConnection $connection
47
	 */
48
	public function __construct(IDBConnection $connection) {
49
		$this->connection = $connection;
50
	}
51
52
	/**
53
	 * @inheritdoc
54
	 */
55
	public function getQueryBuilder() {
56
		return $this->connection->getQueryBuilder();
57
	}
58
59
	/**
60
	 * @inheritdoc
61
	 */
62
	public function prepareQuery($sql, $limit = null, $offset = null) {
63
		$isManipulation = \OC_DB::isManipulation($sql);
64
		$statement = $this->connection->prepare($sql, $limit, $offset);
65
		return new \OC_DB_StatementWrapper($statement, $isManipulation);
66
	}
67
68
69
	/**
70
	 * @inheritdoc
71
	 */
72
	public function getInsertId($tableName) {
73
		return $this->connection->lastInsertId($tableName);
74
	}
75
76
	/**
77
	 * @inheritdoc
78
	 */
79
	public function prepare($sql, $limit=null, $offset=null) {
80
		return $this->connection->prepare($sql, $limit, $offset);
81
	}
82
83
	/**
84
	 * @inheritdoc
85
	 */
86
	public function executeQuery($query, array $params = [], $types = []) {
87
		return $this->connection->executeQuery($query, $params, $types);
88
	}
89
90
	/**
91
	 * @inheritdoc
92
	 */
93
	public function executeUpdate($query, array $params = [], array $types = []) {
94
		return $this->connection->executeUpdate($query, $params, $types);
95
	}
96
97
	/**
98
	 * @inheritdoc
99
	 */
100
	public function lastInsertId($table = null) {
101
		return $this->connection->lastInsertId($table);
102
	}
103
104
	/**
105
	 * @inheritdoc
106
	 */
107
	public function insertIfNotExist($table, $input, array $compare = null) {
108
		return $this->connection->insertIfNotExist($table, $input, $compare);
109
	}
110
111
	/**
112
	 * @inheritdoc
113
	 */
114
	public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) {
115
		return $this->connection->setValues($table, $keys, $values, $updatePreconditionValues);
116
	}
117
118
	/**
119
	 * @inheritdoc
120
	 */
121
	public function lockTable($tableName) {
122
		$this->connection->lockTable($tableName);
123
	}
124
125
	/**
126
	 * @inheritdoc
127
	 */
128
	public function unlockTable() {
129
		$this->connection->unlockTable();
130
	}
131
132
	/**
133
	 * @inheritdoc
134
	 */
135
	public function beginTransaction() {
136
		$this->connection->beginTransaction();
137
	}
138
139
	/**
140
	 * @inheritdoc
141
	 */
142
	public function inTransaction() {
143
		return $this->connection->inTransaction();
144
	}
145
146
	/**
147
	 * @inheritdoc
148
	 */
149
	public function commit() {
150
		$this->connection->commit();
151
	}
152
153
	/**
154
	 * @inheritdoc
155
	 */
156
	public function rollBack() {
157
		$this->connection->rollBack();
158
	}
159
160
	/**
161
	 * @inheritdoc
162
	 */
163
	public function getError() {
164
		return $this->connection->getError();
165
	}
166
167
	/**
168
	 * @inheritdoc
169
	 */
170
	public function errorCode() {
171
		return $this->connection->errorCode();
172
	}
173
174
	/**
175
	 * @inheritdoc
176
	 */
177
	public function errorInfo() {
178
		return $this->connection->errorInfo();
179
	}
180
181
	/**
182
	 * @inheritdoc
183
	 */
184
	public function connect() {
185
		return $this->connection->connect();
186
	}
187
188
	/**
189
	 * @inheritdoc
190
	 */
191
	public function close() {
192
		$this->connection->close();
193
	}
194
195
	/**
196
	 * @inheritdoc
197
	 */
198
	public function quote($input, $type = IQueryBuilder::PARAM_STR) {
199
		return $this->connection->quote($input, $type);
200
	}
201
202
	/**
203
	 * @inheritdoc
204
	 */
205
	public function getDatabasePlatform() {
206
		return $this->connection->getDatabasePlatform();
207
	}
208
209
	/**
210
	 * @inheritdoc
211
	 */
212
	public function dropTable($table) {
213
		$this->connection->dropTable($table);
214
	}
215
216
	/**
217
	 * @inheritdoc
218
	 */
219
	public function tableExists($table) {
220
		return $this->connection->tableExists($table);
221
	}
222
223
	/**
224
	 * @inheritdoc
225
	 */
226
	public function escapeLikeParameter($param) {
227
		return $this->connection->escapeLikeParameter($param);
228
	}
229
230
	/**
231
	 * @inheritdoc
232
	 */
233
	public function createSchema() {
234
		return $this->connection->createSchema();
235
	}
236
237
	/**
238
	 * @inheritdoc
239
	 */
240
	public function migrateToSchema(Schema $toSchema) {
241
		return $this->connection->migrateToSchema($toSchema);
242
	}
243
244
	/**
245
	 * @inheritdoc
246
	 */
247
	public function getTransactionIsolation() {
248
		return $this->connection->getTransactionIsolation();
249
	}
250
251
	/**
252
	 * @inheritdoc
253
	 */
254
	public function allows4ByteCharacters() {
255
		return $this->connection->allows4ByteCharacters();
256
	}
257
258
	/**
259
	 * @inheritdoc
260
	 */
261
	public function upsert($table, $input, array $compare = null) {
262
		return $this->connection->upsert($table, $input, $compare);
263
	}
264
}
265