mirror of
https://github.com/nextcloud/server.git
synced 2024-08-09 14:13:00 +02:00
dont handle database exception in OC_DB
give the caller the option to handle the exception
This commit is contained in:
parent
75367f91e0
commit
65e4dc183c
25
lib/db.php
25
lib/db.php
@ -20,6 +20,19 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class DatabaseException extends Exception{
|
||||||
|
private $query;
|
||||||
|
|
||||||
|
public function __construct($message, $query){
|
||||||
|
parent::__construct($message);
|
||||||
|
$this->query = $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQuery(){
|
||||||
|
return $this->query;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manages the access to the database. It basically is a wrapper for
|
* This class manages the access to the database. It basically is a wrapper for
|
||||||
* MDB2 with some adaptions.
|
* MDB2 with some adaptions.
|
||||||
@ -320,21 +333,13 @@ class OC_DB {
|
|||||||
|
|
||||||
// Die if we have an error (error means: bad query, not 0 results!)
|
// Die if we have an error (error means: bad query, not 0 results!)
|
||||||
if( PEAR::isError($result)) {
|
if( PEAR::isError($result)) {
|
||||||
$entry = 'DB Error: "'.$result->getMessage().'"<br />';
|
throw new DatabaseException($result->getMessage(), $query);
|
||||||
$entry .= 'Offending command was: '.htmlentities($query).'<br />';
|
|
||||||
OC_Log::write('core', $entry, OC_Log::FATAL);
|
|
||||||
error_log('DB error: '.$entry);
|
|
||||||
OC_Template::printErrorPage( $entry );
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
try{
|
try{
|
||||||
$result=self::$connection->prepare($query);
|
$result=self::$connection->prepare($query);
|
||||||
}catch(PDOException $e) {
|
}catch(PDOException $e) {
|
||||||
$entry = 'DB Error: "'.$e->getMessage().'"<br />';
|
throw new DatabaseException($e->getMessage(), $query);
|
||||||
$entry .= 'Offending command was: '.htmlentities($query).'<br />';
|
|
||||||
OC_Log::write('core', $entry, OC_Log::FATAL);
|
|
||||||
error_log('DB error: '.$entry);
|
|
||||||
OC_Template::printErrorPage( $entry );
|
|
||||||
}
|
}
|
||||||
$result=new PDOStatementWrapper($result);
|
$result=new PDOStatementWrapper($result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user