Add dropTable to IDBConnection

This commit is contained in:
Robin Appelman 2014-12-08 14:35:57 +01:00
parent 26861a98c5
commit 8af3991d0c
3 changed files with 21 additions and 10 deletions

View File

@ -263,16 +263,7 @@ class OC_DB {
*/
public static function dropTable($tableName) {
$connection = \OC::$server->getDatabaseConnection();
$tableName = OC_Config::getValue('dbtableprefix', 'oc_' ) . trim($tableName);
$connection->beginTransaction();
$platform = $connection->getDatabasePlatform();
$sql = $platform->getDropTableSQL($platform->quoteIdentifier($tableName));
$connection->executeQuery($sql);
$connection->commit();
$connection->dropTable($tableName);
}
/**

View File

@ -164,6 +164,19 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
return $msg;
}
/**
* Drop a table from the database if it exists
*
* @param string $table table name without the prefix
*/
public function dropTable($table) {
$table = $this->tablePrefix . trim($table);
$schema = $this->getSchemaManager();
if($schema->tablesExist(array($table))) {
$schema->dropTable($table);
}
}
// internal use
/**
* @param string $statement

View File

@ -158,4 +158,11 @@ interface IDBConnection {
* @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
*/
public function getDatabasePlatform();
/**
* Drop a table from the database if it exists
*
* @param string $table
*/
public function dropTable($table);
}