2013-06-28 09:48:38 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-02-26 10:37:37 +00:00
|
|
|
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* small wrapper around \Doctrine\DBAL\Driver\Statement to make it behave, more like an MDB2 Statement
|
2014-03-28 11:57:27 +00:00
|
|
|
*
|
2015-02-26 10:37:37 +00: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 09:48:38 +00:00
|
|
|
*/
|
|
|
|
class OC_DB_StatementWrapper {
|
|
|
|
/**
|
|
|
|
* @var \Doctrine\DBAL\Driver\Statement
|
|
|
|
*/
|
2013-07-11 16:47:19 +00:00
|
|
|
private $statement = null;
|
|
|
|
private $isManipulation = false;
|
|
|
|
private $lastArguments = array();
|
2013-06-28 09:48:38 +00:00
|
|
|
|
2014-02-06 15:30:58 +00:00
|
|
|
/**
|
|
|
|
* @param boolean $isManipulation
|
|
|
|
*/
|
2013-07-11 16:47:19 +00:00
|
|
|
public function __construct($statement, $isManipulation) {
|
|
|
|
$this->statement = $statement;
|
|
|
|
$this->isManipulation = $isManipulation;
|
2013-06-28 09:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pass all other function directly to the \Doctrine\DBAL\Driver\Statement
|
|
|
|
*/
|
|
|
|
public function __call($name,$arguments) {
|
|
|
|
return call_user_func_array(array($this->statement,$name), $arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* make execute return the result instead of a bool
|
2014-02-07 13:03:39 +00:00
|
|
|
*
|
|
|
|
* @param array $input
|
2014-05-11 17:28:45 +00:00
|
|
|
* @return \OC_DB_StatementWrapper|int
|
2013-06-28 09:48:38 +00:00
|
|
|
*/
|
|
|
|
public function execute($input=array()) {
|
|
|
|
if(OC_Config::getValue( "log_query", false)) {
|
2013-08-07 16:16:34 +00:00
|
|
|
$params_str = str_replace("\n", " ", var_export($input, true));
|
2013-06-28 09:48:38 +00:00
|
|
|
OC_Log::write('core', 'DB execute with arguments : '.$params_str, OC_Log::DEBUG);
|
|
|
|
}
|
|
|
|
$this->lastArguments = $input;
|
|
|
|
if (count($input) > 0) {
|
2013-07-11 16:47:19 +00:00
|
|
|
$result = $this->statement->execute($input);
|
2013-06-28 09:48:38 +00:00
|
|
|
} else {
|
2013-07-11 16:47:19 +00:00
|
|
|
$result = $this->statement->execute();
|
2013-06-28 09:48:38 +00:00
|
|
|
}
|
2014-11-14 14:48:55 +00:00
|
|
|
|
2013-07-11 16:47:19 +00:00
|
|
|
if ($result === false) {
|
2013-06-28 09:48:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-11 16:47:19 +00:00
|
|
|
if ($this->isManipulation) {
|
2015-02-23 16:17:20 +00:00
|
|
|
$count = $this->statement->rowCount();
|
|
|
|
return $count;
|
2013-07-11 16:47:19 +00:00
|
|
|
} else {
|
|
|
|
return $this;
|
|
|
|
}
|
2013-06-28 09:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* provide an alias for fetch
|
2014-03-28 11:57:27 +00:00
|
|
|
*
|
|
|
|
* @return mixed
|
2013-06-28 09:48:38 +00:00
|
|
|
*/
|
|
|
|
public function fetchRow() {
|
|
|
|
return $this->statement->fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide a simple fetchOne.
|
2014-03-28 11:57:27 +00:00
|
|
|
*
|
2013-06-28 09:48:38 +00:00
|
|
|
* fetch single column from the next row
|
2014-03-28 11:57:27 +00:00
|
|
|
* @param int $column the column number to fetch
|
2013-06-28 09:48:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2014-03-28 11:57:27 +00:00
|
|
|
public function fetchOne($column = 0) {
|
|
|
|
return $this->statement->fetchColumn($column);
|
2013-06-28 09:48:38 +00:00
|
|
|
}
|
2014-01-16 13:07:16 +00: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 09:48:38 +00:00
|
|
|
}
|