summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-12-08 13:51:45 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-12-08 13:51:45 +0100
commit45fe8271ab1efb90ad0394bec0285f83b1ccd55c (patch)
treebd73ff50105f9ac125b7a8c02d1a367725d0005c /lib/private
parent85409b6701ffd46806f4a53b69dce0fa6a09d2a9 (diff)
parent9f9884930609addad3e37325731fb5406dd3aa44 (diff)
downloadnextcloud-server-45fe8271ab1efb90ad0394bec0285f83b1ccd55c.tar.gz
nextcloud-server-45fe8271ab1efb90ad0394bec0285f83b1ccd55c.zip
Merge pull request #21030 from owncloud/querybuilder-new-features
Querybuilder new features
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/db/querybuilder/querybuilder.php56
-rw-r--r--lib/private/db/querybuilder/quotehelper.php2
2 files changed, 56 insertions, 2 deletions
diff --git a/lib/private/db/querybuilder/querybuilder.php b/lib/private/db/querybuilder/querybuilder.php
index 02d8ee4344d..741da4efc27 100644
--- a/lib/private/db/querybuilder/querybuilder.php
+++ b/lib/private/db/querybuilder/querybuilder.php
@@ -325,6 +325,28 @@ class QueryBuilder implements IQueryBuilder {
}
/**
+ * Specifies an item that is to be returned uniquely in the query result.
+ *
+ * <code>
+ * $qb = $conn->getQueryBuilder()
+ * ->selectDistinct('type')
+ * ->from('users');
+ * </code>
+ *
+ * @param mixed $select The selection expressions.
+ *
+ * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance.
+ */
+ public function selectDistinct($select) {
+
+ $this->queryBuilder->addSelect(
+ 'DISTINCT ' . $this->helper->quoteColumnName($select)
+ );
+
+ return $this;
+ }
+
+ /**
* Adds an item that is to be returned in the query result.
*
* <code>
@@ -1024,14 +1046,46 @@ class QueryBuilder implements IQueryBuilder {
}
/**
+ * Used to get the id of the last inserted element
+ * @return int
+ * @throws \BadMethodCallException When being called before an insert query has been run.
+ */
+ public function getLastInsertId() {
+ $from = $this->getQueryPart('from');
+
+ if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && !empty($from)) {
+ return (int) $this->connection->lastInsertId($from['table']);
+ }
+
+ throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.');
+ }
+
+ /**
+ * Returns the table name quoted and with database prefix as needed by the implementation
+ *
* @param string $table
* @return string
*/
- private function getTableName($table) {
+ public function getTableName($table) {
if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) {
return $this->helper->quoteColumnName($table);
}
return $this->helper->quoteColumnName('*PREFIX*' . $table);
}
+
+ /**
+ * Returns the column name quoted and with table alias prefix as needed by the implementation
+ *
+ * @param string $column
+ * @param string $tableAlias
+ * @return string
+ */
+ public function getColumnName($column, $tableAlias = '') {
+ if ($tableAlias !== '') {
+ $tableAlias .= '.';
+ }
+
+ return $this->helper->quoteColumnName($tableAlias . $column);
+ }
}
diff --git a/lib/private/db/querybuilder/quotehelper.php b/lib/private/db/querybuilder/quotehelper.php
index 4b62fee6a6c..5ceb76bbf93 100644
--- a/lib/private/db/querybuilder/quotehelper.php
+++ b/lib/private/db/querybuilder/quotehelper.php
@@ -61,7 +61,7 @@ class QuoteHelper {
}
if (substr_count($string, '.')) {
- list($alias, $columnName) = explode('.', $string);
+ list($alias, $columnName) = explode('.', $string, 2);
if ($columnName === '*') {
return $string;