aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-12-08 18:00:42 +0100
committerRobin Appelman <icewind@owncloud.com>2014-12-09 17:26:53 +0100
commit778d8dbafd982a018c7425f660f59c7ecaa97d2b (patch)
tree725d73330483bc04ceb1c4032b0a440cb1e7d3c6 /lib
parent8af3991d0cf129316b177731686af547fe39a698 (diff)
downloadnextcloud-server-778d8dbafd982a018c7425f660f59c7ecaa97d2b.tar.gz
nextcloud-server-778d8dbafd982a018c7425f660f59c7ecaa97d2b.zip
Add tableExists to public db api
Diffstat (limited to 'lib')
-rw-r--r--lib/private/db.php39
-rw-r--r--lib/private/db/connection.php12
-rw-r--r--lib/public/idbconnection.php10
3 files changed, 23 insertions, 38 deletions
diff --git a/lib/private/db.php b/lib/private/db.php
index 9387cc48457..dc25092e276 100644
--- a/lib/private/db.php
+++ b/lib/private/db.php
@@ -325,42 +325,7 @@ class OC_DB {
* @throws \OC\DatabaseException
*/
public static function tableExists($table) {
-
- $table = OC_Config::getValue('dbtableprefix', 'oc_' ) . trim($table);
-
- $dbType = OC_Config::getValue( 'dbtype', 'sqlite' );
- switch ($dbType) {
- case 'sqlite':
- case 'sqlite3':
- $sql = "SELECT name FROM sqlite_master "
- . "WHERE type = 'table' AND name = ? "
- . "UNION ALL SELECT name FROM sqlite_temp_master "
- . "WHERE type = 'table' AND name = ?";
- $result = \OC_DB::executeAudited($sql, array($table, $table));
- break;
- case 'mysql':
- $sql = 'SHOW TABLES LIKE ?';
- $result = \OC_DB::executeAudited($sql, array($table));
- break;
- case 'pgsql':
- $sql = 'SELECT tablename AS table_name, schemaname AS schema_name '
- . 'FROM pg_tables WHERE schemaname NOT LIKE \'pg_%\' '
- . 'AND schemaname != \'information_schema\' '
- . 'AND tablename = ?';
- $result = \OC_DB::executeAudited($sql, array($table));
- break;
- case 'oci':
- $sql = 'SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = ?';
- $result = \OC_DB::executeAudited($sql, array($table));
- break;
- case 'mssql':
- $sql = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ?';
- $result = \OC_DB::executeAudited($sql, array($table));
- break;
- default:
- throw new \OC\DatabaseException("Unknown database type: $dbType");
- }
-
- return $result->fetchOne() === $table;
+ $connection = \OC::$server->getDatabaseConnection();
+ return $connection->tableExists($table);
}
}
diff --git a/lib/private/db/connection.php b/lib/private/db/connection.php
index e2d90c8fc82..9de7a719ff5 100644
--- a/lib/private/db/connection.php
+++ b/lib/private/db/connection.php
@@ -177,6 +177,18 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
}
}
+ /**
+ * Check if a table exists
+ *
+ * @param string $table table name without the prefix
+ * @return bool
+ */
+ public function tableExists($table){
+ $table = $this->tablePrefix . trim($table);
+ $schema = $this->getSchemaManager();
+ return $schema->tablesExist(array($table));
+ }
+
// internal use
/**
* @param string $statement
diff --git a/lib/public/idbconnection.php b/lib/public/idbconnection.php
index bc563d20b42..32310fe755f 100644
--- a/lib/public/idbconnection.php
+++ b/lib/public/idbconnection.php
@@ -162,7 +162,15 @@ interface IDBConnection {
/**
* Drop a table from the database if it exists
*
- * @param string $table
+ * @param string $table table name without the prefix
*/
public function dropTable($table);
+
+ /**
+ * Check if a table exists
+ *
+ * @param string $table table name without the prefix
+ * @return bool
+ */
+ public function tableExists($table);
}