From 000b5a801f27914d0a906b5f4c6ff58e14e5aebe Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 1 Jul 2013 18:20:27 +0200 Subject: [PATCH] Move building error string to connection --- lib/db.php | 10 +--------- lib/db/connection.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/db.php b/lib/db.php index 48e1439a33..9270b2a151 100644 --- a/lib/db.php +++ b/lib/db.php @@ -433,16 +433,8 @@ class OC_DB { */ public static function getErrorMessage($error) { if (self::$connection) { - $msg = self::$connection->errorCode() . ': '; - $errorInfo = self::$connection->errorInfo(); - if (is_array($errorInfo)) { - $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; - $msg .= 'Driver Code = '.$errorInfo[1] . ', '; - $msg .= 'Driver Message = '.$errorInfo[2]; - } - return $msg; + return self::$connection->getError(); } - return ''; } diff --git a/lib/db/connection.php b/lib/db/connection.php index e18062d78f..1f01fae4f7 100644 --- a/lib/db/connection.php +++ b/lib/db/connection.php @@ -148,6 +148,23 @@ class Connection extends \Doctrine\DBAL\Connection { return $this->adapter->insertIfNotExist($table, $input); } + /** + * returns the error code and message as a string for logging + * works with DoctrineException + * @param mixed $error + * @return string + */ + public function getError() { + $msg = $this->errorCode() . ': '; + $errorInfo = $this->errorInfo(); + if (is_array($errorInfo)) { + $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; + $msg .= 'Driver Code = '.$errorInfo[1] . ', '; + $msg .= 'Driver Message = '.$errorInfo[2]; + } + return $msg; + } + // internal use protected function replaceTablePrefix($statement) { return str_replace( '*PREFIX*', $this->table_prefix, $statement );