Merge pull request #21498 from owncloud/cleanup-OC_DB
Cleanup OC_DB methods
This commit is contained in:
commit
1cc6fddead
|
@ -25,12 +25,6 @@
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
$installedVersion = $config->getAppValue('files_trashbin', 'installed_version');
|
$installedVersion = $config->getAppValue('files_trashbin', 'installed_version');
|
||||||
|
|
||||||
if (version_compare($installedVersion, '0.6', '<')) {
|
|
||||||
//size of the trash bin could be incorrect, remove it for all users to
|
|
||||||
//enforce a recalculation during next usage.
|
|
||||||
\OC_DB::dropTable('files_trashsize');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version_compare($installedVersion, '0.6.4', '<')) {
|
if (version_compare($installedVersion, '0.6.4', '<')) {
|
||||||
$isExpirationEnabled = $config->getSystemValue('trashbin_auto_expire', true);
|
$isExpirationEnabled = $config->getSystemValue('trashbin_auto_expire', true);
|
||||||
$oldObligation = $config->getSystemValue('trashbin_retention_obligation', null);
|
$oldObligation = $config->getSystemValue('trashbin_retention_obligation', null);
|
||||||
|
|
|
@ -20,11 +20,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$installedVersion=OCP\Config::getAppValue('files_versions', 'installed_version');
|
|
||||||
// move versions to new directory
|
|
||||||
if (version_compare($installedVersion, '1.0.4', '<')) {
|
|
||||||
\OC_DB::dropTable("files_versions");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cron job for deleting expired trash items
|
// Cron job for deleting expired trash items
|
||||||
\OC::$server->getJobList()->add('OCA\Files_Versions\BackgroundJob\ExpireVersions');
|
\OC::$server->getJobList()->add('OCA\Files_Versions\BackgroundJob\ExpireVersions');
|
||||||
|
|
|
@ -166,7 +166,7 @@ class ConvertType extends Command {
|
||||||
$this->validateInput($input, $output);
|
$this->validateInput($input, $output);
|
||||||
$this->readPassword($input, $output);
|
$this->readPassword($input, $output);
|
||||||
|
|
||||||
$fromDB = \OC_DB::getConnection();
|
$fromDB = \OC::$server->getDatabaseConnection();
|
||||||
$toDB = $this->getToDBConnection($input, $output);
|
$toDB = $this->getToDBConnection($input, $output);
|
||||||
|
|
||||||
if ($input->getOption('clear-schema')) {
|
if ($input->getOption('clear-schema')) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ class GenerateChangeScript extends Command {
|
||||||
|
|
||||||
$file = $input->getArgument('schema-xml');
|
$file = $input->getArgument('schema-xml');
|
||||||
|
|
||||||
$schemaManager = new \OC\DB\MDB2SchemaManager(\OC_DB::getConnection());
|
$schemaManager = new \OC\DB\MDB2SchemaManager(\OC::$server->getDatabaseConnection());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $schemaManager->updateDbFromStructure($file, true);
|
$result = $schemaManager->updateDbFromStructure($file, true);
|
||||||
|
|
|
@ -35,13 +35,6 @@
|
||||||
*/
|
*/
|
||||||
class OC_DB {
|
class OC_DB {
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \OCP\IDBConnection
|
|
||||||
*/
|
|
||||||
static public function getConnection() {
|
|
||||||
return \OC::$server->getDatabaseConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get MDB2 schema manager
|
* get MDB2 schema manager
|
||||||
*
|
*
|
||||||
|
@ -157,42 +150,6 @@ class OC_DB {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* gets last value of autoincrement
|
|
||||||
* @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix
|
|
||||||
* @return string id
|
|
||||||
* @throws \OC\DatabaseException
|
|
||||||
*
|
|
||||||
* \Doctrine\DBAL\Connection lastInsertId
|
|
||||||
*
|
|
||||||
* Call this method right after the insert command or other functions may
|
|
||||||
* cause trouble!
|
|
||||||
*/
|
|
||||||
public static function insertid($table=null) {
|
|
||||||
return \OC::$server->getDatabaseConnection()->lastInsertId($table);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start a transaction
|
|
||||||
*/
|
|
||||||
public static function beginTransaction() {
|
|
||||||
return \OC::$server->getDatabaseConnection()->beginTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commit the database changes done during a transaction that is in progress
|
|
||||||
*/
|
|
||||||
public static function commit() {
|
|
||||||
return \OC::$server->getDatabaseConnection()->commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rollback the database changes done during a transaction that is in progress
|
|
||||||
*/
|
|
||||||
public static function rollback() {
|
|
||||||
return \OC::$server->getDatabaseConnection()->rollback();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saves database schema to xml file
|
* saves database schema to xml file
|
||||||
* @param string $file name of file
|
* @param string $file name of file
|
||||||
|
@ -253,15 +210,6 @@ class OC_DB {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* drop a table - the database prefix will be prepended
|
|
||||||
* @param string $tableName the table to drop
|
|
||||||
*/
|
|
||||||
public static function dropTable($tableName) {
|
|
||||||
$connection = \OC::$server->getDatabaseConnection();
|
|
||||||
$connection->dropTable($tableName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove all tables defined in a database structure xml file
|
* remove all tables defined in a database structure xml file
|
||||||
* @param string $file the xml file describing the tables
|
* @param string $file the xml file describing the tables
|
||||||
|
@ -271,15 +219,6 @@ class OC_DB {
|
||||||
$schemaManager->removeDBStructure($file);
|
$schemaManager->removeDBStructure($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* check if a result is an error, works with Doctrine
|
|
||||||
* @param mixed $result
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isError($result) {
|
|
||||||
//Doctrine returns false on error (and throws an exception)
|
|
||||||
return $result === false;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* check if a result is an error and throws an exception, works with \Doctrine\DBAL\DBALException
|
* check if a result is an error and throws an exception, works with \Doctrine\DBAL\DBALException
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
|
@ -288,20 +227,16 @@ class OC_DB {
|
||||||
* @throws \OC\DatabaseException
|
* @throws \OC\DatabaseException
|
||||||
*/
|
*/
|
||||||
public static function raiseExceptionOnError($result, $message = null) {
|
public static function raiseExceptionOnError($result, $message = null) {
|
||||||
if(self::isError($result)) {
|
if($result === false) {
|
||||||
if ($message === null) {
|
if ($message === null) {
|
||||||
$message = self::getErrorMessage();
|
$message = self::getErrorMessage();
|
||||||
} else {
|
} else {
|
||||||
$message .= ', Root cause:' . self::getErrorMessage();
|
$message .= ', Root cause:' . self::getErrorMessage();
|
||||||
}
|
}
|
||||||
throw new \OC\DatabaseException($message, self::getErrorCode());
|
throw new \OC\DatabaseException($message, \OC::$server->getDatabaseConnection()->errorCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getErrorCode() {
|
|
||||||
$connection = \OC::$server->getDatabaseConnection();
|
|
||||||
return $connection->errorCode();
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* returns the error code and message as a string for logging
|
* returns the error code and message as a string for logging
|
||||||
* works with DoctrineException
|
* works with DoctrineException
|
||||||
|
|
|
@ -336,7 +336,7 @@ class Scanner extends BasicEmitter {
|
||||||
$newChildren = $this->getNewChildren($path);
|
$newChildren = $this->getNewChildren($path);
|
||||||
|
|
||||||
if ($this->useTransactions) {
|
if ($this->useTransactions) {
|
||||||
\OC_DB::beginTransaction();
|
\OC::$server->getDatabaseConnection()->beginTransaction();
|
||||||
}
|
}
|
||||||
$exceptionOccurred = false;
|
$exceptionOccurred = false;
|
||||||
foreach ($newChildren as $file) {
|
foreach ($newChildren as $file) {
|
||||||
|
@ -361,7 +361,7 @@ class Scanner extends BasicEmitter {
|
||||||
$exceptionOccurred = true;
|
$exceptionOccurred = true;
|
||||||
} catch (\OCP\Lock\LockedException $e) {
|
} catch (\OCP\Lock\LockedException $e) {
|
||||||
if ($this->useTransactions) {
|
if ($this->useTransactions) {
|
||||||
\OC_DB::rollback();
|
\OC::$server->getDatabaseConnection()->rollback();
|
||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,7 @@ class Scanner extends BasicEmitter {
|
||||||
$this->removeFromCache($child);
|
$this->removeFromCache($child);
|
||||||
}
|
}
|
||||||
if ($this->useTransactions) {
|
if ($this->useTransactions) {
|
||||||
\OC_DB::commit();
|
\OC::$server->getDatabaseConnection()->commit();
|
||||||
}
|
}
|
||||||
if ($exceptionOccurred) {
|
if ($exceptionOccurred) {
|
||||||
// It might happen that the parallel scan process has already
|
// It might happen that the parallel scan process has already
|
||||||
|
|
|
@ -58,10 +58,10 @@ class Storage {
|
||||||
if ($row = self::getStorageById($this->storageId)) {
|
if ($row = self::getStorageById($this->storageId)) {
|
||||||
$this->numericId = $row['numeric_id'];
|
$this->numericId = $row['numeric_id'];
|
||||||
} else {
|
} else {
|
||||||
$connection = \OC_DB::getConnection();
|
$connection = \OC::$server->getDatabaseConnection();
|
||||||
$available = $isAvailable ? 1 : 0;
|
$available = $isAvailable ? 1 : 0;
|
||||||
if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) {
|
if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) {
|
||||||
$this->numericId = \OC_DB::insertid('*PREFIX*storages');
|
$this->numericId = $connection->lastInsertId('*PREFIX*storages');
|
||||||
} else {
|
} else {
|
||||||
if ($row = self::getStorageById($this->storageId)) {
|
if ($row = self::getStorageById($this->storageId)) {
|
||||||
$this->numericId = $row['numeric_id'];
|
$this->numericId = $row['numeric_id'];
|
||||||
|
|
|
@ -136,10 +136,11 @@ class Repair extends BasicEmitter {
|
||||||
* @return array of RepairStep instances
|
* @return array of RepairStep instances
|
||||||
*/
|
*/
|
||||||
public static function getBeforeUpgradeRepairSteps() {
|
public static function getBeforeUpgradeRepairSteps() {
|
||||||
|
$connection = \OC::$server->getDatabaseConnection();
|
||||||
$steps = [
|
$steps = [
|
||||||
new InnoDB(),
|
new InnoDB(),
|
||||||
new Collation(\OC::$server->getConfig(), \OC_DB::getConnection()),
|
new Collation(\OC::$server->getConfig(), $connection),
|
||||||
new SqliteAutoincrement(\OC_DB::getConnection()),
|
new SqliteAutoincrement($connection),
|
||||||
new SearchLuceneTables(),
|
new SearchLuceneTables(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ class InnoDB extends BasicEmitter implements \OC\RepairStep {
|
||||||
* Fix mime types
|
* Fix mime types
|
||||||
*/
|
*/
|
||||||
public function run() {
|
public function run() {
|
||||||
$connection = \OC_DB::getConnection();
|
$connection = \OC::$server->getDatabaseConnection();
|
||||||
if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
|
if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
|
||||||
$this->emit('\OC\Repair', 'info', array('Not a mysql database -> nothing to do'));
|
$this->emit('\OC\Repair', 'info', array('Not a mysql database -> nothing to do'));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -52,10 +52,10 @@ class SearchLuceneTables extends BasicEmitter implements \OC\RepairStep {
|
||||||
* search_lucene will then reindex the fileids without a status when the next indexing job is executed
|
* search_lucene will then reindex the fileids without a status when the next indexing job is executed
|
||||||
*/
|
*/
|
||||||
public function run() {
|
public function run() {
|
||||||
if (\OC_DB::tableExists('lucene_status')) {
|
$connection = \OC::$server->getDatabaseConnection();
|
||||||
|
if ($connection->tableExists('lucene_status')) {
|
||||||
$this->emit('\OC\Repair', 'info', array('removing duplicate entries from lucene_status'));
|
$this->emit('\OC\Repair', 'info', array('removing duplicate entries from lucene_status'));
|
||||||
|
|
||||||
$connection = \OC_DB::getConnection();
|
|
||||||
$query = $connection->prepare('
|
$query = $connection->prepare('
|
||||||
DELETE FROM `*PREFIX*lucene_status`
|
DELETE FROM `*PREFIX*lucene_status`
|
||||||
WHERE `fileid` IN (
|
WHERE `fileid` IN (
|
||||||
|
|
|
@ -242,8 +242,8 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
$this->registerService('SystemConfig', function ($c) use ($config) {
|
$this->registerService('SystemConfig', function ($c) use ($config) {
|
||||||
return new \OC\SystemConfig($config);
|
return new \OC\SystemConfig($config);
|
||||||
});
|
});
|
||||||
$this->registerService('AppConfig', function ($c) {
|
$this->registerService('AppConfig', function (Server $c) {
|
||||||
return new \OC\AppConfig(\OC_DB::getConnection());
|
return new \OC\AppConfig($c->getDatabaseConnection());
|
||||||
});
|
});
|
||||||
$this->registerService('L10NFactory', function ($c) {
|
$this->registerService('L10NFactory', function ($c) {
|
||||||
return new \OC\L10N\Factory();
|
return new \OC\L10N\Factory();
|
||||||
|
|
|
@ -436,7 +436,7 @@ class Share extends Constants {
|
||||||
|
|
||||||
// TODO: inject connection, hopefully one day in the future when this
|
// TODO: inject connection, hopefully one day in the future when this
|
||||||
// class isn't static anymore...
|
// class isn't static anymore...
|
||||||
$conn = \OC_DB::getConnection();
|
$conn = \OC::$server->getDatabaseConnection();
|
||||||
$result = $conn->executeQuery(
|
$result = $conn->executeQuery(
|
||||||
'SELECT ' . $select . ' FROM `*PREFIX*share` ' . $where,
|
'SELECT ' . $select . ' FROM `*PREFIX*share` ' . $where,
|
||||||
$arguments,
|
$arguments,
|
||||||
|
@ -491,7 +491,7 @@ class Share extends Constants {
|
||||||
public static function getShareByToken($token, $checkPasswordProtection = true) {
|
public static function getShareByToken($token, $checkPasswordProtection = true) {
|
||||||
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1);
|
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1);
|
||||||
$result = $query->execute(array($token));
|
$result = $query->execute(array($token));
|
||||||
if (\OC_DB::isError($result)) {
|
if ($result === false) {
|
||||||
\OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage() . ', token=' . $token, \OCP\Util::ERROR);
|
\OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage() . ', token=' . $token, \OCP\Util::ERROR);
|
||||||
}
|
}
|
||||||
$row = $result->fetchRow();
|
$row = $result->fetchRow();
|
||||||
|
@ -1722,7 +1722,7 @@ class Share extends Constants {
|
||||||
$root = strlen($root);
|
$root = strlen($root);
|
||||||
$query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit);
|
$query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit);
|
||||||
$result = $query->execute($queryArgs);
|
$result = $query->execute($queryArgs);
|
||||||
if (\OC_DB::isError($result)) {
|
if ($result === false) {
|
||||||
\OCP\Util::writeLog('OCP\Share',
|
\OCP\Util::writeLog('OCP\Share',
|
||||||
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=',
|
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=',
|
||||||
\OCP\Util::ERROR);
|
\OCP\Util::ERROR);
|
||||||
|
@ -1786,7 +1786,7 @@ class Share extends Constants {
|
||||||
if (isset($row['parent'])) {
|
if (isset($row['parent'])) {
|
||||||
$query = \OC_DB::prepare('SELECT `file_target` FROM `*PREFIX*share` WHERE `id` = ?');
|
$query = \OC_DB::prepare('SELECT `file_target` FROM `*PREFIX*share` WHERE `id` = ?');
|
||||||
$parentResult = $query->execute(array($row['parent']));
|
$parentResult = $query->execute(array($row['parent']));
|
||||||
if (\OC_DB::isError($result)) {
|
if ($result === false) {
|
||||||
\OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' .
|
\OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' .
|
||||||
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where,
|
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where,
|
||||||
\OCP\Util::ERROR);
|
\OCP\Util::ERROR);
|
||||||
|
@ -2191,7 +2191,7 @@ class Share extends Constants {
|
||||||
if ($isGroupShare) {
|
if ($isGroupShare) {
|
||||||
$id = self::insertShare($queriesToExecute['groupShare']);
|
$id = self::insertShare($queriesToExecute['groupShare']);
|
||||||
// Save this id, any extra rows for this group share will need to reference it
|
// Save this id, any extra rows for this group share will need to reference it
|
||||||
$parent = \OC_DB::insertid('*PREFIX*share');
|
$parent = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share');
|
||||||
unset($queriesToExecute['groupShare']);
|
unset($queriesToExecute['groupShare']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ class Tags implements \OCP\ITags {
|
||||||
$entries = array();
|
$entries = array();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$conn = \OC_DB::getConnection();
|
$conn = \OC::$server->getDatabaseConnection();
|
||||||
$chunks = array_chunk($objIds, 900, false);
|
$chunks = array_chunk($objIds, 900, false);
|
||||||
foreach ($chunks as $chunk) {
|
foreach ($chunks as $chunk) {
|
||||||
$result = $conn->executeQuery(
|
$result = $conn->executeQuery(
|
||||||
|
|
|
@ -210,7 +210,7 @@ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend {
|
||||||
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)');
|
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)');
|
||||||
$result = $query->execute(array($uid));
|
$result = $query->execute(array($uid));
|
||||||
|
|
||||||
if (OC_DB::isError($result)) {
|
if ($result === false) {
|
||||||
\OCP\Util::writeLog('core', OC_DB::getErrorMessage(), \OCP\Util::ERROR);
|
\OCP\Util::writeLog('core', OC_DB::getErrorMessage(), \OCP\Util::ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend {
|
||||||
public function countUsers() {
|
public function countUsers() {
|
||||||
$query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`');
|
$query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`');
|
||||||
$result = $query->execute();
|
$result = $query->execute();
|
||||||
if (OC_DB::isError($result)) {
|
if ($result === false) {
|
||||||
\OCP\Util::writeLog('core', OC_DB::getErrorMessage(), \OCP\Util::ERROR);
|
\OCP\Util::writeLog('core', OC_DB::getErrorMessage(), \OCP\Util::ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -461,7 +461,7 @@ class Test_App extends \Test\TestCase {
|
||||||
$appConfig = $this->getMock(
|
$appConfig = $this->getMock(
|
||||||
'\OC\AppConfig',
|
'\OC\AppConfig',
|
||||||
array('getValues'),
|
array('getValues'),
|
||||||
array(\OC_DB::getConnection()),
|
array(\OC::$server->getDatabaseConnection()),
|
||||||
'',
|
'',
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -488,8 +488,8 @@ class Test_App extends \Test\TestCase {
|
||||||
* Restore the original app config service.
|
* Restore the original app config service.
|
||||||
*/
|
*/
|
||||||
private function restoreAppConfig() {
|
private function restoreAppConfig() {
|
||||||
\OC::$server->registerService('AppConfig', function ($c) {
|
\OC::$server->registerService('AppConfig', function (\OC\Server $c) {
|
||||||
return new \OC\AppConfig(\OC_DB::getConnection());
|
return new \OC\AppConfig($c->getDatabaseConnection());
|
||||||
});
|
});
|
||||||
\OC::$server->registerService('AppManager', function (\OC\Server $c) {
|
\OC::$server->registerService('AppManager', function (\OC\Server $c) {
|
||||||
return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory());
|
return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory());
|
||||||
|
|
|
@ -111,11 +111,11 @@ class Test_DB extends \Test\TestCase {
|
||||||
public function testLastInsertId() {
|
public function testLastInsertId() {
|
||||||
$query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)');
|
$query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)');
|
||||||
$result1 = OC_DB::executeAudited($query, array('insertid 1','uri_1'));
|
$result1 = OC_DB::executeAudited($query, array('insertid 1','uri_1'));
|
||||||
$id1 = OC_DB::insertid('*PREFIX*'.$this->table2);
|
$id1 = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*'.$this->table2);
|
||||||
|
|
||||||
// we don't know the id we should expect, so insert another row
|
// we don't know the id we should expect, so insert another row
|
||||||
$result2 = OC_DB::executeAudited($query, array('insertid 2','uri_2'));
|
$result2 = OC_DB::executeAudited($query, array('insertid 2','uri_2'));
|
||||||
$id2 = OC_DB::insertid('*PREFIX*'.$this->table2);
|
$id2 = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*'.$this->table2);
|
||||||
// now we can check if the two ids are in correct order
|
// now we can check if the two ids are in correct order
|
||||||
$this->assertGreaterThan($id1, $id2);
|
$this->assertGreaterThan($id1, $id2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Connection extends \Test\TestCase {
|
||||||
protected static function dropTestTable()
|
protected static function dropTestTable()
|
||||||
{
|
{
|
||||||
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') !== 'oci') {
|
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') !== 'oci') {
|
||||||
\OC_DB::dropTable('table');
|
\OC::$server->getDatabaseConnection()->dropTable('table');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class MDB2SchemaManager extends \Test\TestCase {
|
||||||
// do not drop the table for Oracle as it will create a bogus transaction
|
// do not drop the table for Oracle as it will create a bogus transaction
|
||||||
// that will break the following test suites requiring transactions
|
// that will break the following test suites requiring transactions
|
||||||
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') !== 'oci') {
|
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') !== 'oci') {
|
||||||
\OC_DB::dropTable('table');
|
\OC::$server->getDatabaseConnection()->dropTable('table');
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
|
@ -32,7 +32,7 @@ class MDB2SchemaManager extends \Test\TestCase {
|
||||||
|
|
||||||
public function testAutoIncrement() {
|
public function testAutoIncrement() {
|
||||||
|
|
||||||
$connection = \OC_DB::getConnection();
|
$connection = \OC::$server->getDatabaseConnection();
|
||||||
if ($connection->getDatabasePlatform() instanceof OraclePlatform) {
|
if ($connection->getDatabasePlatform() instanceof OraclePlatform) {
|
||||||
$this->markTestSkipped('Adding auto increment columns in Oracle is not supported.');
|
$this->markTestSkipped('Adding auto increment columns in Oracle is not supported.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Migrator extends \Test\TestCase {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->config = \OC::$server->getConfig();
|
$this->config = \OC::$server->getConfig();
|
||||||
$this->connection = \OC_DB::getConnection();
|
$this->connection = \OC::$server->getDatabaseConnection();
|
||||||
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
|
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
|
||||||
$this->markTestSkipped('DB migration tests are not supported on OCI');
|
$this->markTestSkipped('DB migration tests are not supported on OCI');
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ class TestMySqlMigration extends \Test\TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->connection = \OC_DB::getConnection();
|
$this->connection = \OC::$server->getDatabaseConnection();
|
||||||
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
|
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
|
||||||
$this->markTestSkipped("Test only relevant on MySql");
|
$this->markTestSkipped("Test only relevant on MySql");
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ class TestSqliteMigration extends \Test\TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->connection = \OC_DB::getConnection();
|
$this->connection = \OC::$server->getDatabaseConnection();
|
||||||
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
|
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
|
||||||
$this->markTestSkipped("Test only relevant on Sqlite");
|
$this->markTestSkipped("Test only relevant on Sqlite");
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Test_DBSchema extends \Test\TestCase {
|
||||||
* @medium
|
* @medium
|
||||||
*/
|
*/
|
||||||
public function testSchema() {
|
public function testSchema() {
|
||||||
$platform = \OC_DB::getConnection()->getDatabasePlatform();
|
$platform = \OC::$server->getDatabaseConnection()->getDatabasePlatform();
|
||||||
$this->doTestSchemaCreating();
|
$this->doTestSchemaCreating();
|
||||||
$this->doTestSchemaChanging();
|
$this->doTestSchemaChanging();
|
||||||
$this->doTestSchemaDumping();
|
$this->doTestSchemaDumping();
|
||||||
|
@ -94,7 +94,7 @@ class Test_DBSchema extends \Test\TestCase {
|
||||||
* @param string $table
|
* @param string $table
|
||||||
*/
|
*/
|
||||||
public function assertTableNotExist($table) {
|
public function assertTableNotExist($table) {
|
||||||
$platform = \OC_DB::getConnection()->getDatabasePlatform();
|
$platform = \OC::$server->getDatabaseConnection()->getDatabasePlatform();
|
||||||
if ($platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
|
if ($platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
|
||||||
// sqlite removes the tables after closing the DB
|
// sqlite removes the tables after closing the DB
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
|
|
|
@ -48,7 +48,7 @@ class TestRepairCollation extends \Test\TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->connection = \OC_DB::getConnection();
|
$this->connection = \OC::$server->getDatabaseConnection();
|
||||||
$this->config = \OC::$server->getConfig();
|
$this->config = \OC::$server->getConfig();
|
||||||
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
|
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
|
||||||
$this->markTestSkipped("Test only relevant on MySql");
|
$this->markTestSkipped("Test only relevant on MySql");
|
||||||
|
|
|
@ -28,7 +28,7 @@ class RepairInnoDB extends \Test\TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->connection = \OC_DB::getConnection();
|
$this->connection = \OC::$server->getDatabaseConnection();
|
||||||
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
|
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
|
||||||
$this->markTestSkipped("Test only relevant on MySql");
|
$this->markTestSkipped("Test only relevant on MySql");
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ class RepairLegacyStorages extends TestCase {
|
||||||
$numRows = $this->connection->executeUpdate($sql, array($storageId));
|
$numRows = $this->connection->executeUpdate($sql, array($storageId));
|
||||||
$this->assertEquals(1, $numRows);
|
$this->assertEquals(1, $numRows);
|
||||||
|
|
||||||
return \OC_DB::insertid('*PREFIX*storages');
|
return \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*storages');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -38,7 +38,7 @@ class RepairSqliteAutoincrement extends \Test\TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->connection = \OC_DB::getConnection();
|
$this->connection = \OC::$server->getDatabaseConnection();
|
||||||
$this->config = \OC::$server->getConfig();
|
$this->config = \OC::$server->getConfig();
|
||||||
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
|
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
|
||||||
$this->markTestSkipped("Test only relevant on Sqlite");
|
$this->markTestSkipped("Test only relevant on Sqlite");
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Test_Tags extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown() {
|
protected function tearDown() {
|
||||||
$conn = \OC_DB::getConnection();
|
$conn = \OC::$server->getDatabaseConnection();
|
||||||
$conn->executeQuery('DELETE FROM `*PREFIX*vcategory_to_object`');
|
$conn->executeQuery('DELETE FROM `*PREFIX*vcategory_to_object`');
|
||||||
$conn->executeQuery('DELETE FROM `*PREFIX*vcategory`');
|
$conn->executeQuery('DELETE FROM `*PREFIX*vcategory`');
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ class Test_Tags extends \Test\TestCase {
|
||||||
$tagId = $tagData[0]['id'];
|
$tagId = $tagData[0]['id'];
|
||||||
$tagType = $tagData[0]['type'];
|
$tagType = $tagData[0]['type'];
|
||||||
|
|
||||||
$conn = \OC_DB::getConnection();
|
$conn = \OC::$server->getDatabaseConnection();
|
||||||
$statement = $conn->prepare(
|
$statement = $conn->prepare(
|
||||||
'INSERT INTO `*PREFIX*vcategory_to_object` ' .
|
'INSERT INTO `*PREFIX*vcategory_to_object` ' .
|
||||||
'(`objid`, `categoryid`, `type`) VALUES ' .
|
'(`objid`, `categoryid`, `type`) VALUES ' .
|
||||||
|
|
Loading…
Reference in New Issue