diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-11-09 11:50:18 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-11-23 13:28:31 +0100 |
commit | 1c7d7288c4dfc3e67ccbe40f8f81be237abd8c73 (patch) | |
tree | 39ea1eebe807ab7dccac57142881c2d0747e1cd7 /lib/private/db | |
parent | f85282c90af5dd07bbbf2e80342ba969d2b8b688 (diff) | |
download | nextcloud-server-1c7d7288c4dfc3e67ccbe40f8f81be237abd8c73.tar.gz nextcloud-server-1c7d7288c4dfc3e67ccbe40f8f81be237abd8c73.zip |
Add a method to select a field or value with alias
Diffstat (limited to 'lib/private/db')
-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> |