commit 72c3c191b51117035367048d151273a1468b627b
parent 114ac289429a47e485b68c9bf369bb2704195948
Author: Jan Dankert <devnull@localhost>
Date: Thu, 7 Dec 2017 23:02:20 +0100
Kleinere Verbesserung im Datenbank-Treiber, z.B. Exception-Handling.
Diffstat:
3 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/action/StartAction.class.php b/action/StartAction.class.php
@@ -1692,7 +1692,6 @@ class StartAction extends Action
public function userprojecttimelineView()
{
$project = Session::getProject();
- Logger::debug('1');
$result = $project->getMyLastChanges();
$this->setTemplateVar('timeline', $result);
diff --git a/modules/database/Database.class.php b/modules/database/Database.class.php
@@ -132,7 +132,6 @@ class Database
$this->available = false;
throw new RuntimeException( "Database type '$type' is not available, class '$classname' was not found");
}
- $f = new driver\PDODriver();
// Client instanziieren
$this->client = new $classname;
@@ -198,8 +197,12 @@ class Database
$this->transactionInProgress = false;
}
}
-
- public function sql( $sql )
+
+ /**
+ * @param $sql
+ * @return Statement
+ */
+ public function sql($sql )
{
return new Statement( $sql,$this->client,$this->conf);
}
diff --git a/modules/database/driver/PDODriver.class.php b/modules/database/driver/PDODriver.class.php
@@ -21,7 +21,6 @@
namespace database\driver;
use \Logger;
-use \OpenRatException;
use \PDO;
use \PDOException;
use \RuntimeException;
@@ -38,7 +37,7 @@ class PDODriver
/**
* Die PDO-Verbindung.
*
- * @var Resource
+ * @var PDO
*/
var $connection;
@@ -54,7 +53,13 @@ class PDODriver
var $params;
- function connect( $conf )
+ /**
+ * @var \PDOStatement
+ */
+ public $stmt;
+
+
+ function connect( $conf )
{
$url = $conf['dsn' ];
$user = $conf['user' ];
@@ -84,20 +89,35 @@ class PDODriver
// We like Exceptions
$options[ PDO::ERRMODE_EXCEPTION ] = true;
$options[ PDO::ATTR_DEFAULT_FETCH_MODE ] = PDO::FETCH_ASSOC;
-
- $this->connection = new PDO($url, $user, $pw, $options);
-
+
+ try
+ {
+ $this->connection = new PDO($url, $user, $pw, $options);
+ }
+ catch(\PDOException $e)
+ {
+ throw new \RuntimeException("Could not connect to database on host $url.",$e);
+ }
+
+ // This should never happen, because PDO should throw an exception if the connection fails.
if ( !is_object($this->connection) )
- throw new OpenRatException( 'DATABASE_ERROR_CONNECTION',"Could not connect to database on host $host. ".PDO::errorInfo() );
+ throw new RuntimeException("Could not connect to database on host $url. ".PDO::errorInfo() );
return true;
}
-
- function disconnect()
+ /**
+ * Disconnects the database connection.
+ *
+ * @return bool
+ */
+ function disconnect()
{
+ // There is no disconnection-function.
+ // So the GC will call the finalize-method of the connection object.
$this->connection = null;
+
return true;
}
@@ -163,8 +183,6 @@ class PDODriver
$offset = $offset + strlen($name);
}
- Logger::debug('PDO: SQL-before-preparation: '.$query);
-
$this->stmt = $this->connection->prepare($query);
if ( $this->stmt === false )
@@ -188,8 +206,6 @@ class PDODriver
throw new RuntimeException( 'Unknown type' );
$this->stmt->bindValue($name,$value,$type);
-
- Logger::debug('PDO: SQL-Binding of parameter '.$name);
}