2013-06-28 13:48:38 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Piotr Mrówczyński <mrow4a@yahoo.com>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
2015-02-26 13:37:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* small wrapper around \Doctrine\DBAL\Driver\Statement to make it behave, more like an MDB2 Statement
|
2014-03-28 15:57:27 +04:00
|
|
|
*
|
2015-02-26 13:37:37 +03:00
|
|
|
* @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);
|
2013-06-28 13:48:38 +04:00
|
|
|
*/
|
|
|
|
class OC_DB_StatementWrapper {
|
|
|
|
/**
|
|
|
|
* @var \Doctrine\DBAL\Driver\Statement
|
|
|
|
*/
|
2013-07-11 20:47:19 +04:00
|
|
|
private $statement = null;
|
|
|
|
private $isManipulation = false;
|
2020-03-26 11:30:18 +03:00
|
|
|
private $lastArguments = [];
|
2013-06-28 13:48:38 +04:00
|
|
|
|
2014-02-06 19:30:58 +04:00
|
|
|
/**
|
|
|
|
* @param boolean $isManipulation
|
|
|
|
*/
|
2013-07-11 20:47:19 +04:00
|
|
|
public function __construct($statement, $isManipulation) {
|
|
|
|
$this->statement = $statement;
|
|
|
|
$this->isManipulation = $isManipulation;
|
2013-06-28 13:48:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pass all other function directly to the \Doctrine\DBAL\Driver\Statement
|
|
|
|
*/
|
|
|
|
public function __call($name,$arguments) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return call_user_func_array([$this->statement,$name], $arguments);
|
2013-06-28 13:48:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* make execute return the result instead of a bool
|
2014-02-07 17:03:39 +04:00
|
|
|
*
|
|
|
|
* @param array $input
|
2017-07-19 21:21:05 +03:00
|
|
|
* @return \OC_DB_StatementWrapper|int|bool
|
2013-06-28 13:48:38 +04:00
|
|
|
*/
|
2017-04-20 12:31:00 +03:00
|
|
|
public function execute($input= []) {
|
2013-06-28 13:48:38 +04:00
|
|
|
$this->lastArguments = $input;
|
|
|
|
if (count($input) > 0) {
|
2013-07-11 20:47:19 +04:00
|
|
|
$result = $this->statement->execute($input);
|
2013-06-28 13:48:38 +04:00
|
|
|
} else {
|
2013-07-11 20:47:19 +04:00
|
|
|
$result = $this->statement->execute();
|
2013-06-28 13:48:38 +04:00
|
|
|
}
|
2014-11-14 17:48:55 +03:00
|
|
|
|
2013-07-11 20:47:19 +04:00
|
|
|
if ($result === false) {
|
2013-06-28 13:48:38 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-11 20:47:19 +04:00
|
|
|
if ($this->isManipulation) {
|
2018-01-26 02:02:03 +03:00
|
|
|
return $this->statement->rowCount();
|
2013-07-11 20:47:19 +04:00
|
|
|
} else {
|
|
|
|
return $this;
|
|
|
|
}
|
2013-06-28 13:48:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* provide an alias for fetch
|
2014-03-28 15:57:27 +04:00
|
|
|
*
|
|
|
|
* @return mixed
|
2013-06-28 13:48:38 +04:00
|
|
|
*/
|
|
|
|
public function fetchRow() {
|
|
|
|
return $this->statement->fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide a simple fetchOne.
|
2014-03-28 15:57:27 +04:00
|
|
|
*
|
2013-06-28 13:48:38 +04:00
|
|
|
* fetch single column from the next row
|
2014-03-28 15:57:27 +04:00
|
|
|
* @param int $column the column number to fetch
|
2013-06-28 13:48:38 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
2014-03-28 15:57:27 +04:00
|
|
|
public function fetchOne($column = 0) {
|
|
|
|
return $this->statement->fetchColumn($column);
|
2013-06-28 13:48:38 +04:00
|
|
|
}
|
2014-01-16 17:07:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2013-06-28 13:48:38 +04:00
|
|
|
}
|