From 1c7d7288c4dfc3e67ccbe40f8f81be237abd8c73 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 9 Nov 2015 11:50:18 +0100 Subject: Add a method to select a field or value with alias --- lib/private/db/querybuilder/querybuilder.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/private') 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 @@ -300,6 +300,30 @@ class QueryBuilder implements IQueryBuilder { return $this; } + /** + * Specifies an item that is to be returned with a different name in the query result. + * + * + * $qb = $conn->getQueryBuilder() + * ->selectAlias('u.id', 'user_id') + * ->from('users', 'u') + * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); + * + * + * @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. * -- cgit v1.2.3