summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-08-10 21:41:32 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-08-10 21:41:32 +0200
commitbfb9a8e58e1a8d613a7eaf0c3422e079abfcacb9 (patch)
tree985841ed4957413e205a668e99071203325b505f /lib
parentc2856c05aa9cbdc3adddea127a8588183647ee0a (diff)
parente6eb74958fd9779362fbde788cbfac982783abc0 (diff)
downloadnextcloud-server-bfb9a8e58e1a8d613a7eaf0c3422e079abfcacb9.tar.gz
nextcloud-server-bfb9a8e58e1a8d613a7eaf0c3422e079abfcacb9.zip
Merge pull request #18175 from owncloud/automatic-db-prefix-query-builder
Automatic db prefix query builder
Diffstat (limited to 'lib')
-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
5 files changed, 52 insertions, 17 deletions
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'));