aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/encryption/lib/migration.php6
-rw-r--r--apps/encryption/tests/lib/MigrationTest.php34
-rw-r--r--apps/files_trashbin/command/cleanup.php2
-rw-r--r--apps/files_trashbin/tests/command/cleanuptest.php2
-rw-r--r--lib/private/db/querybuilder/querybuilder.php42
-rw-r--r--lib/private/share/share.php4
-rw-r--r--lib/public/db/querybuilder/iquerybuilder.php9
-rw-r--r--lib/repair/cleantags.php12
-rw-r--r--lib/repair/filletags.php2
-rw-r--r--tests/lib/db/querybuilder/querybuildertest.php98
-rw-r--r--tests/lib/repair/cleantags.php34
-rw-r--r--tests/lib/share/share.php4
12 files changed, 157 insertions, 92 deletions
diff --git a/apps/encryption/lib/migration.php b/apps/encryption/lib/migration.php
index d22c571fd40..5396a7db627 100644
--- a/apps/encryption/lib/migration.php
+++ b/apps/encryption/lib/migration.php
@@ -72,7 +72,7 @@ class Migration {
// only update during the first run
if ($this->installedVersion !== '-1') {
$query = $this->connection->getQueryBuilder();
- $query->update('*PREFIX*filecache')
+ $query->update('filecache')
->set('size', 'unencrypted_size')
->where($query->expr()->eq('encrypted', $query->createParameter('encrypted')))
->setParameter('encrypted', 1);
@@ -163,7 +163,7 @@ class Migration {
$oldAppValues = $this->connection->getQueryBuilder();
$oldAppValues->select('*')
- ->from('*PREFIX*appconfig')
+ ->from('appconfig')
->where($oldAppValues->expr()->eq('appid', $oldAppValues->createParameter('appid')))
->setParameter('appid', 'files_encryption');
$appSettings = $oldAppValues->execute();
@@ -178,7 +178,7 @@ class Migration {
$oldPreferences = $this->connection->getQueryBuilder();
$oldPreferences->select('*')
- ->from('*PREFIX*preferences')
+ ->from('preferences')
->where($oldPreferences->expr()->eq('appid', $oldPreferences->createParameter('appid')))
->setParameter('appid', 'files_encryption');
$preferenceSettings = $oldPreferences->execute();
diff --git a/apps/encryption/tests/lib/MigrationTest.php b/apps/encryption/tests/lib/MigrationTest.php
index 5bc3b89b5b9..bb1f0a310a2 100644
--- a/apps/encryption/tests/lib/MigrationTest.php
+++ b/apps/encryption/tests/lib/MigrationTest.php
@@ -291,12 +291,12 @@ class MigrationTest extends \Test\TestCase {
/** @var \OCP\IDBConnection $connection */
$connection = \OC::$server->getDatabaseConnection();
$query = $connection->getQueryBuilder();
- $query->delete('*PREFIX*appconfig')
+ $query->delete('appconfig')
->where($query->expr()->eq('appid', $query->createParameter('appid')))
->setParameter('appid', 'encryption');
$query->execute();
$query = $connection->getQueryBuilder();
- $query->delete('*PREFIX*preferences')
+ $query->delete('preferences')
->where($query->expr()->eq('appid', $query->createParameter('appid')))
->setParameter('appid', 'encryption');
$query->execute();
@@ -309,10 +309,10 @@ class MigrationTest extends \Test\TestCase {
$this->invokePrivate($m, 'installedVersion', ['0.7']);
$m->updateDB();
- $this->verifyDB('*PREFIX*appconfig', 'files_encryption', 0);
- $this->verifyDB('*PREFIX*preferences', 'files_encryption', 0);
- $this->verifyDB('*PREFIX*appconfig', 'encryption', 3);
- $this->verifyDB('*PREFIX*preferences', 'encryption', 1);
+ $this->verifyDB('appconfig', 'files_encryption', 0);
+ $this->verifyDB('preferences', 'files_encryption', 0);
+ $this->verifyDB('appconfig', 'encryption', 3);
+ $this->verifyDB('preferences', 'encryption', 1);
}
@@ -329,17 +329,17 @@ class MigrationTest extends \Test\TestCase {
$this->invokePrivate($m, 'installedVersion', ['0.7']);
$m->updateDB();
- $this->verifyDB('*PREFIX*appconfig', 'files_encryption', 0);
- $this->verifyDB('*PREFIX*preferences', 'files_encryption', 0);
- $this->verifyDB('*PREFIX*appconfig', 'encryption', 3);
- $this->verifyDB('*PREFIX*preferences', 'encryption', 1);
+ $this->verifyDB('appconfig', 'files_encryption', 0);
+ $this->verifyDB('preferences', 'files_encryption', 0);
+ $this->verifyDB('appconfig', 'encryption', 3);
+ $this->verifyDB('preferences', 'encryption', 1);
// check if the existing values where overwritten correctly
/** @var \OC\DB\Connection $connection */
$connection = \OC::$server->getDatabaseConnection();
$query = $connection->getQueryBuilder();
$query->select('configvalue')
- ->from('*PREFIX*appconfig')
+ ->from('appconfig')
->where($query->expr()->andX(
$query->expr()->eq('appid', $query->createParameter('appid')),
$query->expr()->eq('configkey', $query->createParameter('configkey'))
@@ -353,7 +353,7 @@ class MigrationTest extends \Test\TestCase {
$query = $connection->getQueryBuilder();
$query->select('configvalue')
- ->from('*PREFIX*preferences')
+ ->from('preferences')
->where($query->expr()->andX(
$query->expr()->eq('appid', $query->createParameter('appid')),
$query->expr()->eq('configkey', $query->createParameter('configkey')),
@@ -399,7 +399,7 @@ class MigrationTest extends \Test\TestCase {
$connection = \OC::$server->getDatabaseConnection();
$query = $connection->getQueryBuilder();
$query->select('*')
- ->from('*PREFIX*filecache');
+ ->from('filecache');
$result = $query->execute();
$entries = $result->fetchAll();
foreach($entries as $entry) {
@@ -417,15 +417,15 @@ class MigrationTest extends \Test\TestCase {
/** @var \OCP\IDBConnection $connection */
$connection = \OC::$server->getDatabaseConnection();
$query = $connection->getQueryBuilder();
- $query->delete('*PREFIX*filecache');
+ $query->delete('filecache');
$query->execute();
$query = $connection->getQueryBuilder();
$result = $query->select('fileid')
- ->from('*PREFIX*filecache')
+ ->from('filecache')
->setMaxResults(1)->execute()->fetchAll();
$this->assertEmpty($result);
$query = $connection->getQueryBuilder();
- $query->insert('*PREFIX*filecache')
+ $query->insert('filecache')
->values(
array(
'storage' => $query->createParameter('storage'),
@@ -447,7 +447,7 @@ class MigrationTest extends \Test\TestCase {
}
$query = $connection->getQueryBuilder();
$result = $query->select('fileid')
- ->from('*PREFIX*filecache')
+ ->from('filecache')
->execute()->fetchAll();
$this->assertSame(19, count($result));
}
diff --git a/apps/files_trashbin/command/cleanup.php b/apps/files_trashbin/command/cleanup.php
index 0cc94912339..60717abac18 100644
--- a/apps/files_trashbin/command/cleanup.php
+++ b/apps/files_trashbin/command/cleanup.php
@@ -108,7 +108,7 @@ class CleanUp extends Command {
if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) {
$this->rootFolder->get('/' . $uid . '/files_trashbin')->delete();
$query = $this->dbConnection->getQueryBuilder();
- $query->delete('*PREFIX*files_trash')
+ $query->delete('files_trash')
->where($query->expr()->eq('user', $query->createParameter('uid')))
->setParameter('uid', $uid);
$query->execute();
diff --git a/apps/files_trashbin/tests/command/cleanuptest.php b/apps/files_trashbin/tests/command/cleanuptest.php
index a7400e901fa..d4cccee448e 100644
--- a/apps/files_trashbin/tests/command/cleanuptest.php
+++ b/apps/files_trashbin/tests/command/cleanuptest.php
@@ -43,7 +43,7 @@ class CleanUpTest extends TestCase {
protected $dbConnection;
/** @var string */
- protected $trashTable = '*PREFIX*files_trash';
+ protected $trashTable = 'files_trash';
/** @var string */
protected $user0 = 'user0';
diff --git a/lib/private/db/querybuilder/querybuilder.php b/lib/private/db/querybuilder/querybuilder.php
index 1a1408876f1..1d97faf77cc 100644
--- a/lib/private/db/querybuilder/querybuilder.php
+++ b/lib/private/db/querybuilder/querybuilder.php
@@ -37,6 +37,9 @@ class QueryBuilder implements IQueryBuilder {
/** @var QuoteHelper */
private $helper;
+ /** @var bool */
+ private $automaticTablePrefix = true;
+
/**
* Initializes a new QueryBuilder.
*
@@ -49,6 +52,17 @@ class QueryBuilder implements IQueryBuilder {
}
/**
+ * Enable/disable automatic prefixing of table names with the oc_ prefix
+ *
+ * @param bool $enabled If set to true table names will be prefixed with the
+ * owncloud database prefix automatically.
+ * @since 8.2.0
+ */
+ public function automaticTablePrefix($enabled) {
+ $this->automaticTablePrefix = (bool) $enabled;
+ }
+
+ /**
* Gets an ExpressionBuilder used for object-oriented construction of query expressions.
* This producer method is intended for convenient inline usage. Example:
*
@@ -329,7 +343,7 @@ class QueryBuilder implements IQueryBuilder {
*/
public function delete($delete = null, $alias = null) {
$this->queryBuilder->delete(
- $this->helper->quoteColumnName($delete),
+ $this->getTableName($delete),
$alias
);
@@ -354,7 +368,7 @@ class QueryBuilder implements IQueryBuilder {
*/
public function update($update = null, $alias = null) {
$this->queryBuilder->update(
- $this->helper->quoteColumnName($update),
+ $this->getTableName($update),
$alias
);
@@ -382,7 +396,7 @@ class QueryBuilder implements IQueryBuilder {
*/
public function insert($insert = null) {
$this->queryBuilder->insert(
- $this->helper->quoteColumnName($insert)
+ $this->getTableName($insert)
);
return $this;
@@ -405,7 +419,7 @@ class QueryBuilder implements IQueryBuilder {
*/
public function from($from, $alias = null) {
$this->queryBuilder->from(
- $this->helper->quoteColumnName($from),
+ $this->getTableName($from),
$alias
);
@@ -432,7 +446,7 @@ class QueryBuilder implements IQueryBuilder {
public function join($fromAlias, $join, $alias, $condition = null) {
$this->queryBuilder->join(
$fromAlias,
- $this->helper->quoteColumnName($join),
+ $this->getTableName($join),
$alias,
$condition
);
@@ -460,7 +474,7 @@ class QueryBuilder implements IQueryBuilder {
public function innerJoin($fromAlias, $join, $alias, $condition = null) {
$this->queryBuilder->innerJoin(
$fromAlias,
- $this->helper->quoteColumnName($join),
+ $this->getTableName($join),
$alias,
$condition
);
@@ -488,7 +502,7 @@ class QueryBuilder implements IQueryBuilder {
public function leftJoin($fromAlias, $join, $alias, $condition = null) {
$this->queryBuilder->leftJoin(
$fromAlias,
- $this->helper->quoteColumnName($join),
+ $this->getTableName($join),
$alias,
$condition
);
@@ -516,7 +530,7 @@ class QueryBuilder implements IQueryBuilder {
public function rightJoin($fromAlias, $join, $alias, $condition = null) {
$this->queryBuilder->rightJoin(
$fromAlias,
- $this->helper->quoteColumnName($join),
+ $this->getTableName($join),
$alias,
$condition
);
@@ -984,4 +998,16 @@ class QueryBuilder implements IQueryBuilder {
public function createFunction($call) {
return new QueryFunction($call);
}
+
+ /**
+ * @param string $table
+ * @return string
+ */
+ private function getTableName($table) {
+ if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) {
+ return $this->helper->quoteColumnName($table);
+ }
+
+ return $this->helper->quoteColumnName('*PREFIX*' . $table);
+ }
}
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 40fcc59f219..9aea4677b5b 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -1218,7 +1218,7 @@ class Share extends Constants {
$qb = $connection->getQueryBuilder();
$qb->select('uid_owner')
- ->from('*PREFIX*share')
+ ->from('share')
->where($qb->expr()->eq('id', $qb->createParameter('shareId')))
->setParameter(':shareId', $shareId);
$result = $qb->execute();
@@ -1269,7 +1269,7 @@ class Share extends Constants {
self::verifyPassword($password);
$qb = $connection->getQueryBuilder();
- $qb->update('*PREFIX*share')
+ $qb->update('share')
->set('share_with', $qb->createParameter('pass'))
->where($qb->expr()->eq('id', $qb->createParameter('shareId')))
->setParameter(':pass', is_null($password) ? null : \OC::$server->getHasher()->hash($password))
diff --git a/lib/public/db/querybuilder/iquerybuilder.php b/lib/public/db/querybuilder/iquerybuilder.php
index 09d5d199bef..3fc07af1a47 100644
--- a/lib/public/db/querybuilder/iquerybuilder.php
+++ b/lib/public/db/querybuilder/iquerybuilder.php
@@ -27,6 +27,15 @@ namespace OCP\DB\QueryBuilder;
*/
interface IQueryBuilder {
/**
+ * Enable/disable automatic prefixing of table names with the oc_ prefix
+ *
+ * @param bool $enabled If set to true table names will be prefixed with the
+ * owncloud database prefix automatically.
+ * @since 8.2.0
+ */
+ public function automaticTablePrefix($enabled);
+
+ /**
* Gets an ExpressionBuilder used for object-oriented construction of query expressions.
* This producer method is intended for convenient inline usage. Example:
*
diff --git a/lib/repair/cleantags.php b/lib/repair/cleantags.php
index 2bda1047081..d16a49fbca7 100644
--- a/lib/repair/cleantags.php
+++ b/lib/repair/cleantags.php
@@ -65,8 +65,8 @@ class CleanTags extends BasicEmitter implements RepairStep {
protected function deleteOrphanFileEntries() {
$this->deleteOrphanEntries(
'%d tags for delete files have been removed.',
- '*PREFIX*vcategory_to_object', 'objid',
- '*PREFIX*filecache', 'fileid', 'path_hash'
+ 'vcategory_to_object', 'objid',
+ 'filecache', 'fileid', 'path_hash'
);
}
@@ -76,8 +76,8 @@ class CleanTags extends BasicEmitter implements RepairStep {
protected function deleteOrphanTagEntries() {
$this->deleteOrphanEntries(
'%d tag entries for deleted tags have been removed.',
- '*PREFIX*vcategory_to_object', 'categoryid',
- '*PREFIX*vcategory', 'id', 'uid'
+ 'vcategory_to_object', 'categoryid',
+ 'vcategory', 'id', 'uid'
);
}
@@ -87,8 +87,8 @@ class CleanTags extends BasicEmitter implements RepairStep {
protected function deleteOrphanCategoryEntries() {
$this->deleteOrphanEntries(
'%d tags with no entries have been removed.',
- '*PREFIX*vcategory', 'id',
- '*PREFIX*vcategory_to_object', 'categoryid', 'type'
+ 'vcategory', 'id',
+ 'vcategory_to_object', 'categoryid', 'type'
);
}
diff --git a/lib/repair/filletags.php b/lib/repair/filletags.php
index f1bb2c896c4..40072209982 100644
--- a/lib/repair/filletags.php
+++ b/lib/repair/filletags.php
@@ -42,7 +42,7 @@ class FillETags extends BasicEmitter implements \OC\RepairStep {
public function run() {
$qb = $this->connection->getQueryBuilder();
- $qb->update('*PREFIX*filecache')
+ $qb->update('filecache')
->set('etag', $qb->expr()->literal('xxx'))
->where($qb->expr()->eq('etag', $qb->expr()->literal('')))
->orWhere($qb->expr()->isNull('etag'));
diff --git a/tests/lib/db/querybuilder/querybuildertest.php b/tests/lib/db/querybuilder/querybuildertest.php
index 02e516b7386..75e62ba944e 100644
--- a/tests/lib/db/querybuilder/querybuildertest.php
+++ b/tests/lib/db/querybuilder/querybuildertest.php
@@ -253,8 +253,8 @@ class QueryBuilderTest extends \Test\TestCase {
public function dataDelete() {
return [
- ['data', null, ['table' => '`data`', 'alias' => null], '`data`'],
- ['data', 't', ['table' => '`data`', 'alias' => 't'], '`data` t'],
+ ['data', null, ['table' => '`*PREFIX*data`', 'alias' => null], '`*PREFIX*data`'],
+ ['data', 't', ['table' => '`*PREFIX*data`', 'alias' => 't'], '`*PREFIX*data` t'],
];
}
@@ -282,8 +282,8 @@ class QueryBuilderTest extends \Test\TestCase {
public function dataUpdate() {
return [
- ['data', null, ['table' => '`data`', 'alias' => null], '`data`'],
- ['data', 't', ['table' => '`data`', 'alias' => 't'], '`data` t'],
+ ['data', null, ['table' => '`*PREFIX*data`', 'alias' => null], '`*PREFIX*data`'],
+ ['data', 't', ['table' => '`*PREFIX*data`', 'alias' => 't'], '`*PREFIX*data` t'],
];
}
@@ -311,7 +311,7 @@ class QueryBuilderTest extends \Test\TestCase {
public function dataInsert() {
return [
- ['data', ['table' => '`data`'], '`data`'],
+ ['data', ['table' => '`*PREFIX*data`'], '`*PREFIX*data`'],
];
}
@@ -338,16 +338,16 @@ class QueryBuilderTest extends \Test\TestCase {
public function dataFrom() {
return [
- ['data', null, null, null, [['table' => '`data`', 'alias' => null]], '`data`'],
- ['data', 't', null, null, [['table' => '`data`', 'alias' => 't']], '`data` t'],
+ ['data', null, null, null, [['table' => '`*PREFIX*data`', 'alias' => null]], '`*PREFIX*data`'],
+ ['data', 't', null, null, [['table' => '`*PREFIX*data`', 'alias' => 't']], '`*PREFIX*data` t'],
['data1', null, 'data2', null, [
- ['table' => '`data1`', 'alias' => null],
- ['table' => '`data2`', 'alias' => null]
- ], '`data1`, `data2`'],
+ ['table' => '`*PREFIX*data1`', 'alias' => null],
+ ['table' => '`*PREFIX*data2`', 'alias' => null]
+ ], '`*PREFIX*data1`, `*PREFIX*data2`'],
['data', 't1', 'data', 't2', [
- ['table' => '`data`', 'alias' => 't1'],
- ['table' => '`data`', 'alias' => 't2']
- ], '`data` t1, `data` t2'],
+ ['table' => '`*PREFIX*data`', 'alias' => 't1'],
+ ['table' => '`*PREFIX*data`', 'alias' => 't2']
+ ], '`*PREFIX*data` t1, `*PREFIX*data` t2'],
];
}
@@ -382,18 +382,18 @@ class QueryBuilderTest extends \Test\TestCase {
return [
[
'd1', 'data2', null, null,
- ['d1' => [['joinType' => 'inner', 'joinTable' => '`data2`', 'joinAlias' => null, 'joinCondition' => null]]],
- '`data1` d1 INNER JOIN `data2` ON '
+ ['d1' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]],
+ '`*PREFIX*data1` d1 INNER JOIN `*PREFIX*data2` ON '
],
[
'd1', 'data2', 'd2', null,
- ['d1' => [['joinType' => 'inner', 'joinTable' => '`data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]],
- '`data1` d1 INNER JOIN `data2` d2 ON '
+ ['d1' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]],
+ '`*PREFIX*data1` d1 INNER JOIN `*PREFIX*data2` d2 ON '
],
[
'd1', 'data2', 'd2', 'd1.`field1` = d2.`field2`',
- ['d1' => [['joinType' => 'inner', 'joinTable' => '`data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]],
- '`data1` d1 INNER JOIN `data2` d2 ON d1.`field1` = d2.`field2`'
+ ['d1' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]],
+ '`*PREFIX*data1` d1 INNER JOIN `*PREFIX*data2` d2 ON d1.`field1` = d2.`field2`'
],
];
@@ -463,18 +463,18 @@ class QueryBuilderTest extends \Test\TestCase {
return [
[
'd1', 'data2', null, null,
- ['d1' => [['joinType' => 'left', 'joinTable' => '`data2`', 'joinAlias' => null, 'joinCondition' => null]]],
- '`data1` d1 LEFT JOIN `data2` ON '
+ ['d1' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]],
+ '`*PREFIX*data1` d1 LEFT JOIN `*PREFIX*data2` ON '
],
[
'd1', 'data2', 'd2', null,
- ['d1' => [['joinType' => 'left', 'joinTable' => '`data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]],
- '`data1` d1 LEFT JOIN `data2` d2 ON '
+ ['d1' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]],
+ '`*PREFIX*data1` d1 LEFT JOIN `*PREFIX*data2` d2 ON '
],
[
'd1', 'data2', 'd2', 'd1.`field1` = d2.`field2`',
- ['d1' => [['joinType' => 'left', 'joinTable' => '`data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]],
- '`data1` d1 LEFT JOIN `data2` d2 ON d1.`field1` = d2.`field2`'
+ ['d1' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]],
+ '`*PREFIX*data1` d1 LEFT JOIN `*PREFIX*data2` d2 ON d1.`field1` = d2.`field2`'
],
];
}
@@ -513,18 +513,18 @@ class QueryBuilderTest extends \Test\TestCase {
return [
[
'd1', 'data2', null, null,
- ['d1' => [['joinType' => 'right', 'joinTable' => '`data2`', 'joinAlias' => null, 'joinCondition' => null]]],
- '`data1` d1 RIGHT JOIN `data2` ON '
+ ['d1' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]],
+ '`*PREFIX*data1` d1 RIGHT JOIN `*PREFIX*data2` ON '
],
[
'd1', 'data2', 'd2', null,
- ['d1' => [['joinType' => 'right', 'joinTable' => '`data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]],
- '`data1` d1 RIGHT JOIN `data2` d2 ON '
+ ['d1' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => null]]],
+ '`*PREFIX*data1` d1 RIGHT JOIN `*PREFIX*data2` d2 ON '
],
[
'd1', 'data2', 'd2', 'd1.`field1` = d2.`field2`',
- ['d1' => [['joinType' => 'right', 'joinTable' => '`data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]],
- '`data1` d1 RIGHT JOIN `data2` d2 ON d1.`field1` = d2.`field2`'
+ ['d1' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => 'd2', 'joinCondition' => 'd1.`field1` = d2.`field2`']]],
+ '`*PREFIX*data1` d1 RIGHT JOIN `*PREFIX*data2` d2 ON d1.`field1` = d2.`field2`'
],
];
}
@@ -591,7 +591,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
$this->assertSame(
- 'UPDATE `data` SET ' . $expectedQuery,
+ 'UPDATE `*PREFIX*data` SET ' . $expectedQuery,
$this->queryBuilder->getSQL()
);
}
@@ -774,7 +774,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
$this->assertSame(
- 'INSERT INTO `data` ' . $expectedQuery,
+ 'INSERT INTO `*PREFIX*data` ' . $expectedQuery,
$this->queryBuilder->getSQL()
);
}
@@ -799,7 +799,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
$this->assertSame(
- 'INSERT INTO `data` ' . $expectedQuery,
+ 'INSERT INTO `*PREFIX*data` ' . $expectedQuery,
$this->queryBuilder->getSQL()
);
}
@@ -996,4 +996,34 @@ class QueryBuilderTest extends \Test\TestCase {
$this->queryBuilder->getSQL()
);
}
+
+ public function dataGetTableName() {
+ return [
+ ['*PREFIX*table', null, '`*PREFIX*table`'],
+ ['*PREFIX*table', true, '`*PREFIX*table`'],
+ ['*PREFIX*table', false, '`*PREFIX*table`'],
+
+ ['table', null, '`*PREFIX*table`'],
+ ['table', true, '`*PREFIX*table`'],
+ ['table', false, '`table`'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetTableName
+ *
+ * @param string $tableName
+ * @param bool $automatic
+ * @param string $expected
+ */
+ public function testGetTableName($tableName, $automatic, $expected) {
+ if ($automatic !== null) {
+ $this->queryBuilder->automaticTablePrefix($automatic);
+ }
+
+ $this->assertSame(
+ $expected,
+ $this->invokePrivate($this->queryBuilder, 'getTableName', [$tableName])
+ );
+ }
}
diff --git a/tests/lib/repair/cleantags.php b/tests/lib/repair/cleantags.php
index 2f6d0879642..a511daa03d6 100644
--- a/tests/lib/repair/cleantags.php
+++ b/tests/lib/repair/cleantags.php
@@ -40,13 +40,13 @@ class CleanTags extends \Test\TestCase {
protected function cleanUpTables() {
$qb = $this->connection->getQueryBuilder();
- $qb->delete('*PREFIX*vcategory')
+ $qb->delete('vcategory')
->execute();
- $qb->delete('*PREFIX*vcategory_to_object')
+ $qb->delete('vcategory_to_object')
->execute();
- $qb->delete('*PREFIX*filecache')
+ $qb->delete('filecache')
->execute();
}
@@ -61,20 +61,20 @@ class CleanTags extends \Test\TestCase {
$this->addTagEntry(9999999, $cat3, 'contacts'); // Retained
$this->addTagEntry($this->getFileID(), $cat3 + 1, 'files'); // Deleted: Category is NULL
- $this->assertEntryCount('*PREFIX*vcategory_to_object', 4, 'Assert tag entries count before repair step');
- $this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count before repair step');
+ $this->assertEntryCount('vcategory_to_object', 4, 'Assert tag entries count before repair step');
+ $this->assertEntryCount('vcategory', 4, 'Assert tag categories count before repair step');
self::invokePrivate($this->repair, 'deleteOrphanFileEntries');
- $this->assertEntryCount('*PREFIX*vcategory_to_object', 3, 'Assert tag entries count after cleaning file entries');
- $this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count after cleaning file entries');
+ $this->assertEntryCount('vcategory_to_object', 3, 'Assert tag entries count after cleaning file entries');
+ $this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning file entries');
self::invokePrivate($this->repair, 'deleteOrphanTagEntries');
- $this->assertEntryCount('*PREFIX*vcategory_to_object', 2, 'Assert tag entries count after cleaning tag entries');
- $this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count after cleaning tag entries');
+ $this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning tag entries');
+ $this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning tag entries');
self::invokePrivate($this->repair, 'deleteOrphanCategoryEntries');
- $this->assertEntryCount('*PREFIX*vcategory_to_object', 2, 'Assert tag entries count after cleaning category entries');
- $this->assertEntryCount('*PREFIX*vcategory', 2, 'Assert tag categories count after cleaning category entries');
+ $this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning category entries');
+ $this->assertEntryCount('vcategory', 2, 'Assert tag categories count after cleaning category entries');
}
/**
@@ -100,7 +100,7 @@ class CleanTags extends \Test\TestCase {
*/
protected function addTagCategory($category, $type) {
$qb = $this->connection->getQueryBuilder();
- $qb->insert('*PREFIX*vcategory')
+ $qb->insert('vcategory')
->values([
'uid' => $qb->createNamedParameter('TestRepairCleanTags'),
'category' => $qb->createNamedParameter($category),
@@ -108,7 +108,7 @@ class CleanTags extends \Test\TestCase {
])
->execute();
- return (int) $this->getLastInsertID('*PREFIX*vcategory', 'id');
+ return (int) $this->getLastInsertID('vcategory', 'id');
}
/**
@@ -119,7 +119,7 @@ class CleanTags extends \Test\TestCase {
*/
protected function addTagEntry($objectId, $category, $type) {
$qb = $this->connection->getQueryBuilder();
- $qb->insert('*PREFIX*vcategory_to_object')
+ $qb->insert('vcategory_to_object')
->values([
'objid' => $qb->createNamedParameter($objectId, \PDO::PARAM_INT),
'categoryid' => $qb->createNamedParameter($category, \PDO::PARAM_INT),
@@ -141,21 +141,21 @@ class CleanTags extends \Test\TestCase {
// We create a new file entry and delete it after the test again
$fileName = $this->getUniqueID('TestRepairCleanTags', 12);
- $qb->insert('*PREFIX*filecache')
+ $qb->insert('filecache')
->values([
'path' => $qb->createNamedParameter($fileName),
'path_hash' => $qb->createNamedParameter(md5($fileName)),
])
->execute();
$fileName = $this->getUniqueID('TestRepairCleanTags', 12);
- $qb->insert('*PREFIX*filecache')
+ $qb->insert('filecache')
->values([
'path' => $qb->createNamedParameter($fileName),
'path_hash' => $qb->createNamedParameter(md5($fileName)),
])
->execute();
- $this->createdFile = (int) $this->getLastInsertID('*PREFIX*filecache', 'fileid');
+ $this->createdFile = (int) $this->getLastInsertID('filecache', 'fileid');
return $this->createdFile;
}
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index b6d3e16826d..ef0d9822085 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -1288,7 +1288,7 @@ class Test_Share extends \Test\TestCase {
// Find the share ID in the db
$qb = $connection->getQueryBuilder();
$qb->select('id')
- ->from('*PREFIX*share')
+ ->from('share')
->where($qb->expr()->eq('item_type', $qb->createParameter('type')))
->andWhere($qb->expr()->eq('item_source', $qb->createParameter('source')))
->andWhere($qb->expr()->eq('uid_owner', $qb->createParameter('owner')))
@@ -1309,7 +1309,7 @@ class Test_Share extends \Test\TestCase {
// Fetch the hash from the database
$qb = $connection->getQueryBuilder();
$qb->select('share_with')
- ->from('*PREFIX*share')
+ ->from('share')
->where($qb->expr()->eq('id', $qb->createParameter('id')))
->setParameter('id', $id);
$hash = $qb->execute()->fetch()['share_with'];