Completed
Push — master ( 432e52...365595 )
by Morris
118:14 queued 100:55
created

DB::beginTransaction()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bart Visscher <[email protected]>
6
 * @author Dan Bartram <[email protected]>
7
 * @author Frank Karlitschek <[email protected]>
8
 * @author Joas Schilling <[email protected]>
9
 * @author Jörn Friedrich Dreyer <[email protected]>
10
 * @author Lukas Reschke <[email protected]>
11
 * @author Morris Jobke <[email protected]>
12
 * @author Robin Appelman <[email protected]>
13
 * @author Roeland Jago Douma <[email protected]>
14
 * @author Thomas Müller <[email protected]>
15
 * @author Thomas Tanghus <[email protected]>
16
 *
17
 * @license AGPL-3.0
18
 *
19
 * This code is free software: you can redistribute it and/or modify
20
 * it under the terms of the GNU Affero General Public License, version 3,
21
 * as published by the Free Software Foundation.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
 * GNU Affero General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU Affero General Public License, version 3,
29
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
30
 *
31
 */
32
33
/**
34
 * Public interface of ownCloud for apps to use.
35
 * DB Class
36
 *
37
 */
38
39
// use OCP namespace for all classes that are considered public.
40
// This means that they should be used by apps instead of the internal ownCloud classes
41
namespace OCP;
42
43
/**
44
 * This class provides access to the internal database system. Use this class exlusively if you want to access databases
45
 * @deprecated 8.1.0 use methods of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
46
 * @since 4.5.0
47
 */
48
class DB {
49
	/**
50
	 * Prepare a SQL query
51
	 * @param string $query Query string
52
	 * @param int $limit Limit of the SQL statement
53
	 * @param int $offset Offset of the SQL statement
54
	 * @return \OC_DB_StatementWrapper prepared SQL query
55
	 *
56
	 * SQL query via Doctrine prepare(), needs to be execute()'d!
57
	 * @deprecated 8.1.0 use prepare() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
58
	 * @since 4.5.0
59
	 */
60
	static public function prepare( $query, $limit=null, $offset=null ) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
61
		return \OC_DB::prepare($query, $limit, $offset);
62
	}
63
64
	/**
65
	 * Insert a row if the matching row does not exists.
66
	 *
67
	 * @param string $table The table name (will replace *PREFIX* with the actual prefix)
68
	 * @param array $input data that should be inserted into the table  (column name => value)
69
	 * @param array|null $compare List of values that should be checked for "if not exists"
70
	 *				If this is null or an empty array, all keys of $input will be compared
71
	 * @return int number of inserted rows
72
	 * @throws \Doctrine\DBAL\DBALException
73
	 * @deprecated 8.1.0 use insertIfNotExist() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
74
	 * @since 5.0.0 - parameter $compare was added in 8.1.0
75
	 *
76
	 */
77
	public static function insertIfNotExist($table, $input, array $compare = null) {
78
		return \OC::$server->getDatabaseConnection()->insertIfNotExist($table, $input, $compare);
79
	}
80
81
	/**
82
	 * Start a transaction
83
	 * @deprecated 8.1.0 use beginTransaction() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
84
	 * @since 4.5.0
85
	 */
86
	public static function beginTransaction() {
87
		\OC::$server->getDatabaseConnection()->beginTransaction();
88
	}
89
90
	/**
91
	 * Commit the database changes done during a transaction that is in progress
92
	 * @deprecated 8.1.0 use commit() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
93
	 * @since 4.5.0
94
	 */
95
	public static function commit() {
96
		\OC::$server->getDatabaseConnection()->commit();
97
	}
98
99
	/**
100
	 * returns the error code and message as a string for logging
101
	 * works with DoctrineException
102
	 * @return string
103
	 * @deprecated 8.1.0 use getError() of \OCP\IDBConnection - \OC::$server->getDatabaseConnection()
104
	 * @since 6.0.0
105
	 */
106
	public static function getErrorMessage() {
107
		return \OC::$server->getDatabaseConnection()->getError();
108
	}
109
110
}
111