summaryrefslogtreecommitdiffstats
path: root/lib/private/db
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-10-23 13:48:33 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2014-10-23 13:48:33 +0200
commit6c1871da06d127abdf7ce2fd5d3beb7683fe42a0 (patch)
tree1c21a9a3d136ba1dc8391e12a37cdfe3ffe0bda8 /lib/private/db
parent7c14a173619cce5c3f637888865e0786a727f5c8 (diff)
parent0dcb83203910a8de5bcfaca8cbad9fef1845a2ea (diff)
downloadnextcloud-server-6c1871da06d127abdf7ce2fd5d3beb7683fe42a0.tar.gz
nextcloud-server-6c1871da06d127abdf7ce2fd5d3beb7683fe42a0.zip
Merge pull request #10985 from owncloud/db-cleanup
Cleanup database handling
Diffstat (limited to 'lib/private/db')
-rw-r--r--lib/private/db/connection.php28
-rw-r--r--lib/private/db/connectionfactory.php50
-rw-r--r--lib/private/db/connectionwrapper.php99
-rw-r--r--lib/private/db/mdb2schemamanager.php5
4 files changed, 43 insertions, 139 deletions
diff --git a/lib/private/db/connection.php b/lib/private/db/connection.php
index b7981fcd691..a6cdf858899 100644
--- a/lib/private/db/connection.php
+++ b/lib/private/db/connection.php
@@ -11,8 +11,9 @@ use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\Common\EventManager;
+use OCP\IDBConnection;
-class Connection extends \Doctrine\DBAL\Connection {
+class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
/**
* @var string $tablePrefix
*/
@@ -24,13 +25,6 @@ class Connection extends \Doctrine\DBAL\Connection {
protected $adapter;
/**
- * @var \Doctrine\DBAL\Driver\Statement[] $preparedQueries
- */
- protected $preparedQueries = array();
-
- protected $cachingQueryStatementEnabled = true;
-
- /**
* Initializes a new instance of the Connection class.
*
* @param array $params The connection parameters.
@@ -69,9 +63,6 @@ class Connection extends \Doctrine\DBAL\Connection {
$platform = $this->getDatabasePlatform();
$statement = $platform->modifyLimitQuery($statement, $limit, $offset);
} else {
- if (isset($this->preparedQueries[$statement]) && $this->cachingQueryStatementEnabled) {
- return $this->preparedQueries[$statement];
- }
$origStatement = $statement;
}
$statement = $this->replaceTablePrefix($statement);
@@ -80,11 +71,7 @@ class Connection extends \Doctrine\DBAL\Connection {
if(\OC_Config::getValue( 'log_query', false)) {
\OC_Log::write('core', 'DB prepare : '.$statement, \OC_Log::DEBUG);
}
- $result = parent::prepare($statement);
- if (is_null($limit) && $this->cachingQueryStatementEnabled) {
- $this->preparedQueries[$origStatement] = $result;
- }
- return $result;
+ return parent::prepare($statement);
}
/**
@@ -185,13 +172,4 @@ class Connection extends \Doctrine\DBAL\Connection {
protected function replaceTablePrefix($statement) {
return str_replace( '*PREFIX*', $this->tablePrefix, $statement );
}
-
- public function enableQueryStatementCaching() {
- $this->cachingQueryStatementEnabled = true;
- }
-
- public function disableQueryStatementCaching() {
- $this->cachingQueryStatementEnabled = false;
- $this->preparedQueries = array();
- }
}
diff --git a/lib/private/db/connectionfactory.php b/lib/private/db/connectionfactory.php
index 589a1c0affd..1f676f1fca2 100644
--- a/lib/private/db/connectionfactory.php
+++ b/lib/private/db/connectionfactory.php
@@ -98,19 +98,6 @@ class ConnectionFactory {
new \Doctrine\DBAL\Configuration(),
$eventManager
);
- switch ($normalizedType) {
- case 'sqlite3':
- // Sqlite doesn't handle query caching and schema changes
- // TODO: find a better way to handle this
- /** @var $connection \OC\DB\Connection */
- $connection->disableQueryStatementCaching();
- break;
- case 'oci':
- // oracle seems to have issues with cached statements which have been closed
- /** @var $connection \OC\DB\Connection */
- $connection->disableQueryStatementCaching();
- break;
- }
return $connection;
}
@@ -131,4 +118,41 @@ class ConnectionFactory {
$normalizedType = $this->normalizeType($type);
return isset($this->defaultConnectionParams[$normalizedType]);
}
+
+ /**
+ * Create the connection parameters for the config
+ *
+ * @param \OCP\IConfig $config
+ * @return array
+ */
+ public function createConnectionParams($config) {
+ $type = $config->getSystemValue('dbtype', 'sqlite');
+
+ $connectionParams = array(
+ 'user' => $config->getSystemValue('dbuser', ''),
+ 'password' => $config->getSystemValue('dbpassword', ''),
+ );
+ $name = $config->getSystemValue('dbname', 'owncloud');
+
+ if ($this->normalizeType($type) === 'sqlite3') {
+ $datadir = $config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data');
+ $connectionParams['path'] = $datadir . '/' . $name . '.db';
+ } else {
+ $host = $config->getSystemValue('dbhost', '');
+ if (strpos($host, ':')) {
+ // Host variable may carry a port or socket.
+ list($host, $portOrSocket) = explode(':', $host, 2);
+ if (ctype_digit($portOrSocket)) {
+ $connectionParams['port'] = $portOrSocket;
+ } else {
+ $connectionParams['unix_socket'] = $portOrSocket;
+ }
+ }
+ $connectionParams['host'] = $host;
+ $connectionParams['dbname'] = $name;
+ }
+
+ $connectionParams['tablePrefix'] = $config->getSystemValue('dbtableprefix', 'oc_');
+ return $connectionParams;
+ }
}
diff --git a/lib/private/db/connectionwrapper.php b/lib/private/db/connectionwrapper.php
deleted file mode 100644
index 132e76666ab..00000000000
--- a/lib/private/db/connectionwrapper.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 Thomas Müller <deepdiver@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace OC\DB;
-
-
-class ConnectionWrapper implements \OCP\IDBConnection {
-
- private $connection;
-
- public function __construct(Connection $conn) {
- $this->connection = $conn;
- }
-
- /**
- * Used to the owncloud database access away
- * @param string $sql the sql query with ? placeholder for params
- * @param int $limit the maximum number of rows
- * @param int $offset from which row we want to start
- * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
- */
- public function prepare($sql, $limit = null, $offset = null)
- {
- return $this->connection->prepare($sql, $limit, $offset);
- }
-
- /**
- * Used to get the id of the just inserted element
- * @param string $table the name of the table where we inserted the item
- * @return string the id of the inserted element
- */
- public function lastInsertId($table = null)
- {
- return $this->connection->lastInsertId($table);
- }
-
- /**
- * Insert a row if a matching row doesn't exists.
- * @param string $table The table name (will replace *PREFIX*) to perform the replace on.
- * @param array $input
- *
- * The input array if in the form:
- *
- * array ( 'id' => array ( 'value' => 6,
- * 'key' => true
- * ),
- * 'name' => array ('value' => 'Stoyan'),
- * 'family' => array ('value' => 'Stefanov'),
- * 'birth_date' => array ('value' => '1975-06-20')
- * );
- * @return bool
- *
- */
- public function insertIfNotExist($table, $input)
- {
- return $this->connection->insertIfNotExist($table, $input);
- }
-
- /**
- * Start a transaction
- * @return bool TRUE on success or FALSE on failure
- */
- public function beginTransaction()
- {
- return $this->connection->beginTransaction();
- }
-
- /**
- * Commit the database changes done during a transaction that is in progress
- * @return bool TRUE on success or FALSE on failure
- */
- public function commit()
- {
- return $this->connection->commit();
- }
-
- /**
- * Rollback the database changes done during a transaction that is in progress
- * @return bool TRUE on success or FALSE on failure
- */
- public function rollBack()
- {
- return $this->connection->rollBack();
- }
-
- /**
- * Gets the error code and message as a string for logging
- * @return string
- */
- public function getError()
- {
- return $this->connection->getError();
- }
-}
diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php
index ea1e512002d..3c367f144db 100644
--- a/lib/private/db/mdb2schemamanager.php
+++ b/lib/private/db/mdb2schemamanager.php
@@ -21,7 +21,7 @@ class MDB2SchemaManager {
protected $conn;
/**
- * @param \OC\DB\Connection $conn
+ * @param \OCP\IDBConnection $conn
*/
public function __construct($conn) {
$this->conn = $conn;
@@ -155,7 +155,8 @@ class MDB2SchemaManager {
$this->conn->commit();
if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) {
- \OC_DB::reconnect();
+ $this->conn->close();
+ $this->conn->connect();
}
return true;
}