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 | |
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')
-rw-r--r-- | lib/private/db/querybuilder/querybuilder.php | 24 | ||||
-rw-r--r-- | lib/public/db/querybuilder/iquerybuilder.php | 18 |
2 files changed, 42 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> diff --git a/lib/public/db/querybuilder/iquerybuilder.php b/lib/public/db/querybuilder/iquerybuilder.php index 3fc07af1a47..beb922b7feb 100644 --- a/lib/public/db/querybuilder/iquerybuilder.php +++ b/lib/public/db/querybuilder/iquerybuilder.php @@ -239,6 +239,24 @@ interface IQueryBuilder { public function select($select = null); /** + * 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. + * @since 8.2.1 + */ + public function selectAlias($select, $alias); + + /** * Adds an item that is to be returned in the query result. * * <code> |