mirror of
https://github.com/friendica/friendica
synced 2024-05-13 10:29:39 +02:00
Renaming driver & refactor server info
This commit is contained in:
parent
780b57c6e4
commit
f7ac20e151
|
@ -25,8 +25,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
private $configCache;
|
private $configCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The connection instance of the database
|
* The current driver of the database
|
||||||
*
|
|
||||||
* @var IDriver
|
* @var IDriver
|
||||||
*/
|
*/
|
||||||
private $driver;
|
private $driver;
|
||||||
|
@ -49,11 +48,12 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
*/
|
*/
|
||||||
private $dbRelation;
|
private $dbRelation;
|
||||||
|
|
||||||
public function __construct(IDriver $connection, IConfigCache $configCache, Profiler $profiler, LoggerInterface $logger)
|
public function __construct(IDriver $driver, IConfigCache $configCache, Profiler $profiler, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->configCache = $configCache;
|
$this->configCache = $configCache;
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
$this->driver = $connection;
|
$this->driver = $driver;
|
||||||
|
$this->logger = $logger;
|
||||||
$this->driver->connect();
|
$this->driver->connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$columns = $this->getDriver()->fetch($stmt);
|
$columns = $this->driver->fetch($stmt);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
|
$this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
|
||||||
|
|
||||||
|
@ -150,9 +150,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
*/
|
*/
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
$conn = $this->driver;
|
if (!$this->driver->performCommit()) {
|
||||||
|
|
||||||
if (!$conn->performCommit()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,9 +163,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
*/
|
*/
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
$conn = $this->driver;
|
$ret = $this->driver->rollbackTransaction();
|
||||||
|
|
||||||
$ret = $conn->rollbackTransaction();
|
|
||||||
|
|
||||||
$this->inTransaction = false;
|
$this->inTransaction = false;
|
||||||
|
|
||||||
|
@ -184,7 +180,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
*/
|
*/
|
||||||
public function delete($table, array $conditions, $cascade = true, array &$callstack = [])
|
public function delete($table, array $conditions, $cascade = true, array &$callstack = [])
|
||||||
{
|
{
|
||||||
$conn = $this->driver;
|
$driver = $this->driver;
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
|
|
||||||
if (empty($table) || empty($conditions)) {
|
if (empty($table) || empty($conditions)) {
|
||||||
|
@ -204,7 +200,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
|
|
||||||
$callstack[$key] = true;
|
$callstack[$key] = true;
|
||||||
|
|
||||||
$table = $conn->escape($table);
|
$table = $driver->escape($table);
|
||||||
|
|
||||||
$commands[$key] = ['table' => $table, 'conditions' => $conditions];
|
$commands[$key] = ['table' => $table, 'conditions' => $conditions];
|
||||||
|
|
||||||
|
@ -319,7 +315,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
*/
|
*/
|
||||||
public function update($table, array $fields, array $condition, $old_fields = [])
|
public function update($table, array $fields, array $condition, $old_fields = [])
|
||||||
{
|
{
|
||||||
$conn = $this->driver;
|
$driver = $this->driver;
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
|
|
||||||
if (empty($table) || empty($fields) || empty($condition)) {
|
if (empty($table) || empty($fields) || empty($condition)) {
|
||||||
|
@ -327,7 +323,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = $conn->escape($table);
|
$table = $driver->escape($table);
|
||||||
|
|
||||||
$condition_string = self::buildCondition($condition);
|
$condition_string = self::buildCondition($condition);
|
||||||
|
|
||||||
|
@ -376,13 +372,11 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
*/
|
*/
|
||||||
public function select($table, array $fields = [], array $condition = [], array $params = [])
|
public function select($table, array $fields = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
$conn = $this->driver;
|
|
||||||
|
|
||||||
if ($table == '') {
|
if ($table == '') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = $conn->escape($table);
|
$table = $this->driver->escape($table);
|
||||||
|
|
||||||
if (count($fields) > 0) {
|
if (count($fields) > 0) {
|
||||||
$select_fields = "`" . implode("`, `", array_values($fields)) . "`";
|
$select_fields = "`" . implode("`, `", array_values($fields)) . "`";
|
||||||
|
@ -436,7 +430,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$profiler = $this->profiler;
|
$profiler = $this->profiler;
|
||||||
$config = $this->configCache;
|
$config = $this->configCache;
|
||||||
$conn = $this->driver;
|
$driver = $this->driver;
|
||||||
|
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
|
|
||||||
|
@ -453,7 +447,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
$args[++$i] = $param;
|
$args[++$i] = $param;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$conn->isConnected()) {
|
if (!$driver->isConnected()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,8 +481,8 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$retval = $conn->executePrepared($sql, $args);
|
$retval = $driver->executePrepared($sql, $args);
|
||||||
self::$affected_rows = $conn->getNumRows($retval);
|
self::$affected_rows = $driver->getNumRows($retval);
|
||||||
|
|
||||||
} catch (DriverException $exception) {
|
} catch (DriverException $exception) {
|
||||||
// We are having an own error logging in the function "e"
|
// We are having an own error logging in the function "e"
|
||||||
|
@ -502,7 +496,7 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
|
|
||||||
// On a lost connection we try to reconnect - but only once.
|
// On a lost connection we try to reconnect - but only once.
|
||||||
if ($errorno == 2006) {
|
if ($errorno == 2006) {
|
||||||
if (self::$in_retrial || !$conn->reconnect()) {
|
if (self::$in_retrial || !$driver->reconnect()) {
|
||||||
// It doesn't make sense to continue when the database connection was lost
|
// It doesn't make sense to continue when the database connection was lost
|
||||||
if (self::$in_retrial) {
|
if (self::$in_retrial) {
|
||||||
$logger->notice('Giving up retrial because of database error ' . $errorno . ': ' . $error);
|
$logger->notice('Giving up retrial because of database error ' . $errorno . ': ' . $error);
|
||||||
|
@ -550,7 +544,6 @@ class Database implements IDatabase, IDatabaseLock
|
||||||
*/
|
*/
|
||||||
public function execute($sql)
|
public function execute($sql)
|
||||||
{
|
{
|
||||||
$conn = $this->driver;
|
|
||||||
$profiler = $this->profiler;
|
$profiler = $this->profiler;
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,6 @@ abstract class AbstractDriver implements IDriver
|
||||||
protected $dbPort;
|
protected $dbPort;
|
||||||
protected $dbCharset;
|
protected $dbCharset;
|
||||||
|
|
||||||
protected $serverInfo;
|
|
||||||
|
|
||||||
public function __construct($serverAddress, $user, $pass, $db, $charset = null)
|
public function __construct($serverAddress, $user, $pass, $db, $charset = null)
|
||||||
{
|
{
|
||||||
$this->isConnected = false;
|
$this->isConnected = false;
|
||||||
|
@ -45,8 +43,6 @@ abstract class AbstractDriver implements IDriver
|
||||||
$this->dbPass = trim($this->dbPass);
|
$this->dbPass = trim($this->dbPass);
|
||||||
$this->dbName = trim($this->dbName);
|
$this->dbName = trim($this->dbName);
|
||||||
$this->dbCharset = trim($this->dbCharset);
|
$this->dbCharset = trim($this->dbCharset);
|
||||||
|
|
||||||
$this->serverInfo = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace Friendica\Database\Driver;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DB connection exception
|
* A DB driver exception
|
||||||
*/
|
*/
|
||||||
class DriverException extends Exception
|
class DriverException extends Exception
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,7 +86,7 @@ class MySQLiDriver extends AbstractDriver implements IDriver
|
||||||
*/
|
*/
|
||||||
public function getServerInfo()
|
public function getServerInfo()
|
||||||
{
|
{
|
||||||
$this->serverInfo = $this->connection->server_info;
|
return $this->connection->server_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -86,7 +86,7 @@ class PDODriver extends AbstractDriver implements IDriver
|
||||||
*/
|
*/
|
||||||
function getServerInfo()
|
function getServerInfo()
|
||||||
{
|
{
|
||||||
$this->serverInfo = $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION);
|
return $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue