1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Bart Visscher <bartv@thisnet.nl>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
use OCP\DB\IPreparedStatement;
/**
* small wrapper around \Doctrine\DBAL\Driver\Statement to make it behave, more like an MDB2 Statement
*
* @method boolean bindValue(mixed $param, mixed $value, integer $type = null);
* @method string errorCode();
* @method array errorInfo();
* @method integer rowCount();
* @method array fetchAll(integer $fetchMode = null);
*/
class OC_DB_StatementWrapper {
/** @var IPreparedStatement */
private $statement = null;
/** @var bool */
private $isManipulation = false;
/** @var array */
private $lastArguments = [];
/**
* @param IPreparedStatement $statement
* @param boolean $isManipulation
*/
public function __construct(IPreparedStatement $statement, $isManipulation) {
$this->statement = $statement;
$this->isManipulation = $isManipulation;
}
/**
* pass all other function directly to the \Doctrine\DBAL\Driver\Statement
*/
public function __call($name,$arguments) {
return call_user_func_array([$this->statement,$name], $arguments);
}
/**
* make execute return the result instead of a bool
*
* @param mixed[] $input
* @return \OC_DB_StatementWrapper|int|bool
* @deprecated
*/
public function execute($input = []) {
$this->lastArguments = $input;
try {
if (count($input) > 0) {
$result = $this->statement->execute($input);
} else {
$result = $this->statement->execute();
}
} catch (\Doctrine\DBAL\Exception $e) {
return false;
}
if ($this->isManipulation) {
return $this->statement->rowCount();
}
return $this;
}
/**
* provide an alias for fetch
*
* @return mixed
* @deprecated
*/
public function fetchRow() {
return $this->statement->fetch();
}
/**
* Provide a simple fetchOne.
*
* fetch single column from the next row
* @return string
* @deprecated
*/
public function fetchOne() {
return $this->statement->fetchOne();
}
/**
* Closes the cursor, enabling the statement to be executed again.
*
* @deprecated Use Result::free() instead.
*/
public function closeCursor(): void {
$this->statement->closeCursor();
}
/**
* Binds a PHP variable to a corresponding named or question mark placeholder in the
* SQL statement that was use to prepare the statement.
*
* @param mixed $column Either the placeholder name or the 1-indexed placeholder index
* @param mixed $variable The variable to bind
* @param integer|null $type one of the PDO::PARAM_* constants
* @param integer|null $length max length when using an OUT bind
* @return boolean
*/
public function bindParam($column, &$variable, $type = null, $length = null) {
return $this->statement->bindParam($column, $variable, $type, $length);
}
}
|