diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-26 16:19:20 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-26 16:19:20 +0100 |
commit | 19d5059109c631523fc4c5726115799cd36caeaf (patch) | |
tree | 432a31105ca95a541864cfe7fe9f901dcaba234e /lib/private | |
parent | 49b76114bedcd689fbc2a27ab9eaed3b84615d79 (diff) | |
parent | 1c7d7288c4dfc3e67ccbe40f8f81be237abd8c73 (diff) | |
download | nextcloud-server-19d5059109c631523fc4c5726115799cd36caeaf.tar.gz nextcloud-server-19d5059109c631523fc4c5726115799cd36caeaf.zip |
Merge pull request #20393 from owncloud/querybuilder-select-with-alias
Add a method to select a field or value with alias
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/db/querybuilder/querybuilder.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/private/db/querybuilder/querybuilder.php b/lib/private/db/querybuilder/querybuilder.php index 1d97faf77cc..02d8ee4344d 100644 --- a/lib/private/db/querybuilder/querybuilder.php +++ b/lib/private/db/querybuilder/querybuilder.php @@ -301,6 +301,30 @@ class QueryBuilder implements IQueryBuilder { } /** + * Specifies an item that is to be returned with a different name in the query result. + * + * <code> + * $qb = $conn->getQueryBuilder() + * ->selectAlias('u.id', 'user_id') + * ->from('users', 'u') + * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); + * </code> + * + * @param mixed $select The selection expressions. + * @param string $alias The column alias used in the constructed query. + * + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. + */ + public function selectAlias($select, $alias) { + + $this->queryBuilder->addSelect( + $this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias) + ); + + return $this; + } + + /** * Adds an item that is to be returned in the query result. * * <code> |