summaryrefslogtreecommitdiffstats
path: root/lib/private/db
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-10-22 14:54:42 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-10-22 14:54:42 +0200
commitb7fa644a546a775c5b4b7c4e35da39df11be1c66 (patch)
tree94e1d531fd8e64a2ff6fb440a217d773a7ce3ca5 /lib/private/db
parent31e489b44d22bbb7b255a95485a2417760a96c5c (diff)
parentf7097faf82604a6d8b89eed9d1d5ea3d0843e4f8 (diff)
downloadnextcloud-server-b7fa644a546a775c5b4b7c4e35da39df11be1c66.tar.gz
nextcloud-server-b7fa644a546a775c5b4b7c4e35da39df11be1c66.zip
Merge pull request #9586 from owncloud/enhanced-sql-script-generation-oracle-master
Special treatment for Oracle
Diffstat (limited to 'lib/private/db')
-rw-r--r--lib/private/db/mdb2schemamanager.php13
-rw-r--r--lib/private/db/migrator.php29
-rw-r--r--lib/private/db/oraclemigrator.php14
-rw-r--r--lib/private/db/sqlitemigrator.php6
4 files changed, 49 insertions, 13 deletions
diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php
index a07c421b9b8..ea1e512002d 100644
--- a/lib/private/db/mdb2schemamanager.php
+++ b/lib/private/db/mdb2schemamanager.php
@@ -58,20 +58,21 @@ class MDB2SchemaManager {
* @return \OC\DB\Migrator
*/
public function getMigrator() {
+ $random = \OC::$server->getSecureRandom()->getMediumStrengthGenerator();
$platform = $this->conn->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
$config = \OC::$server->getConfig();
- return new SQLiteMigrator($this->conn, $config);
+ return new SQLiteMigrator($this->conn, $random, $config);
} else if ($platform instanceof OraclePlatform) {
- return new OracleMigrator($this->conn);
+ return new OracleMigrator($this->conn, $random);
} else if ($platform instanceof MySqlPlatform) {
- return new MySQLMigrator($this->conn);
+ return new MySQLMigrator($this->conn, $random);
} else if ($platform instanceof SQLServerPlatform) {
- return new MsSqlMigrator($this->conn);
+ return new MsSqlMigrator($this->conn, $random);
} else if ($platform instanceof PostgreSqlPlatform) {
- return new Migrator($this->conn);
+ return new Migrator($this->conn, $random);
} else {
- return new NoCheckMigrator($this->conn);
+ return new NoCheckMigrator($this->conn, $random);
}
}
diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php
index d05f8455551..31c648a9b65 100644
--- a/lib/private/db/migrator.php
+++ b/lib/private/db/migrator.php
@@ -14,18 +14,27 @@ use \Doctrine\DBAL\Schema\Table;
use \Doctrine\DBAL\Schema\Schema;
use \Doctrine\DBAL\Schema\SchemaConfig;
use \Doctrine\DBAL\Schema\Comparator;
+use OCP\Security\ISecureRandom;
class Migrator {
+
/**
* @var \Doctrine\DBAL\Connection $connection
*/
protected $connection;
/**
+ * @var ISecureRandom
+ */
+ private $random;
+
+ /**
* @param \Doctrine\DBAL\Connection $connection
+ * @param ISecureRandom $random
*/
- public function __construct(\Doctrine\DBAL\Connection $connection) {
+ public function __construct(\Doctrine\DBAL\Connection $connection, ISecureRandom $random) {
$this->connection = $connection;
+ $this->random = $random;
}
/**
@@ -45,8 +54,7 @@ class Migrator {
$script = '';
$sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform());
foreach ($sqls as $sql) {
- $script .= $sql . ';';
- $script .= PHP_EOL;
+ $script .= $this->convertStatementToScript($sql);
}
return $script;
@@ -84,7 +92,7 @@ class Migrator {
* @return string
*/
protected function generateTemporaryTableName($name) {
- return 'oc_' . $name . '_' . \OCP\Util::generateRandomBytes(13);
+ return 'oc_' . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
}
/**
@@ -135,7 +143,7 @@ class Migrator {
$indexName = $index->getName();
} else {
// avoid conflicts in index names
- $indexName = 'oc_' . \OCP\Util::generateRandomBytes(13);
+ $indexName = 'oc_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
}
$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
}
@@ -201,4 +209,15 @@ class Migrator {
protected function dropTable($name) {
$this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name));
}
+
+ /**
+ * @param $statement
+ * @return string
+ */
+ protected function convertStatementToScript($statement) {
+ $script = $statement . ';';
+ $script .= PHP_EOL;
+ $script .= PHP_EOL;
+ return $script;
+ }
}
diff --git a/lib/private/db/oraclemigrator.php b/lib/private/db/oraclemigrator.php
index 1a8df2def9c..b80295cbd60 100644
--- a/lib/private/db/oraclemigrator.php
+++ b/lib/private/db/oraclemigrator.php
@@ -37,4 +37,18 @@ class OracleMigrator extends NoCheckMigrator {
protected function generateTemporaryTableName($name) {
return 'oc_' . uniqid();
}
+
+ /**
+ * @param $statement
+ * @return string
+ */
+ protected function convertStatementToScript($statement) {
+ if (substr($statement, -1) === ';') {
+ return $statement . PHP_EOL . '/' . PHP_EOL;
+ }
+ $script = $statement . ';';
+ $script .= PHP_EOL;
+ $script .= PHP_EOL;
+ return $script;
+ }
}
diff --git a/lib/private/db/sqlitemigrator.php b/lib/private/db/sqlitemigrator.php
index 18e9d19d5ee..848e4986571 100644
--- a/lib/private/db/sqlitemigrator.php
+++ b/lib/private/db/sqlitemigrator.php
@@ -10,6 +10,7 @@ namespace OC\DB;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema;
+use OCP\Security\ISecureRandom;
class SQLiteMigrator extends Migrator {
@@ -20,10 +21,11 @@ class SQLiteMigrator extends Migrator {
/**
* @param \Doctrine\DBAL\Connection $connection
+ * @param ISecureRandom $random
* @param \OCP\IConfig $config
*/
- public function __construct(\Doctrine\DBAL\Connection $connection, \OCP\IConfig $config) {
- parent::__construct($connection);
+ public function __construct(\Doctrine\DBAL\Connection $connection, ISecureRandom $random, \OCP\IConfig $config) {
+ parent::__construct($connection, $random);
$this->config = $config;
}