Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/Comments/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public function getLastCommentDateByActor(

$query = $this->dbConn->getQueryBuilder();
$query->select('actor_id')
->selectAlias($query->createFunction('MAX(' . $query->getColumnName('creation_timestamp') . ')'), 'last_comment')
->selectAlias($query->func()->max('creation_timestamp'), 'last_comment')
->from('comments')
->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType)))
->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
use Override;

class FunctionBuilder implements IFunctionBuilder {
/** @var IDBConnection|Connection */
Expand Down Expand Up @@ -105,4 +106,9 @@ public function greatest($x, $y): IQueryFunction {
public function least($x, $y): IQueryFunction {
return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
}

#[Override]
public function now(): IQueryFunction {
return new QueryFunction('NOW()');
}
}
2 changes: 1 addition & 1 deletion lib/private/DB/QueryBuilder/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ public function addGroupBy(...$groupBy) {
* </code>
*
* @param string $column The column into which the value should be inserted.
* @param IParameter|string $value The value that should be inserted into the column.
* @param IParameter|IQueryFunction|string $value The value that should be inserted into the column.
*
* @return $this This QueryBuilder instance.
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/CacheQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function __construct(
public function selectTagUsage(): self {
$this
->select('systemtag.name', 'systemtag.id', 'systemtag.visibility', 'systemtag.editable', 'systemtag.etag', 'systemtag.color')
->selectAlias($this->createFunction('COUNT(filecache.fileid)'), 'number_files')
->selectAlias($this->createFunction('MAX(filecache.fileid)'), 'ref_file_id')
->selectAlias($this->func()->count('filecache.fileid'), 'number_files')
->selectAlias($this->func()->max('filecache.fileid'), 'ref_file_id')
->from('filecache', 'filecache')
->leftJoin('filecache', 'systemtag_object_mapping', 'systemtagmap', $this->expr()->andX(
$this->expr()->eq('filecache.fileid', $this->expr()->castColumn('systemtagmap.objectid', IQueryBuilder::PARAM_INT)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function store(IFilesMetadata $filesMetadata): void {
->setValue('file_id', $qb->createNamedParameter($filesMetadata->getFileId(), IQueryBuilder::PARAM_INT))
->setValue('json', $qb->createNamedParameter(json_encode($filesMetadata->jsonSerialize())))
->setValue('sync_token', $qb->createNamedParameter($this->generateSyncToken()))
->setValue('last_update', (string)$qb->createFunction('NOW()'));
->setValue('last_update', $qb->func()->now());
$qb->executeStatement();
}

Expand Down Expand Up @@ -159,7 +159,7 @@ public function updateMetadata(IFilesMetadata $filesMetadata): int {
->hintShardKey('files_metadata', $this->getStorageId($filesMetadata))
->set('json', $qb->createNamedParameter(json_encode($filesMetadata->jsonSerialize())))
->set('sync_token', $qb->createNamedParameter($this->generateSyncToken()))
->set('last_update', $qb->createFunction('NOW()'))
->set('last_update', $qb->func()->now())
->where(
$expr->andX(
$expr->eq('file_id', $qb->createNamedParameter($filesMetadata->getFileId(), IQueryBuilder::PARAM_INT)),
Expand Down
6 changes: 6 additions & 0 deletions lib/public/DB/QueryBuilder/IFunctionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,10 @@ public function greatest($x, $y): IQueryFunction;
* @since 18.0.0
*/
public function least($x, $y): IQueryFunction;

/**
* Get the current date and time as a UNIX timestamp.
* @since 34.0.0
*/
public function now(): IQueryFunction;
}
7 changes: 4 additions & 3 deletions lib/public/DB/QueryBuilder/IQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ public function addGroupBy(...$groupBy);
* </code>
*
* @param string $column The column into which the value should be inserted.
* @param IParameter|string $value The value that should be inserted into the column.
* @param IParameter|IQueryFunction|string $value The value that should be inserted into the column.
*
* @return $this This QueryBuilder instance.
* @since 8.2.0
Expand Down Expand Up @@ -1001,9 +1001,10 @@ public function createPositionalParameter($value, $type = self::PARAM_STR);
public function createParameter($name);

/**
* Creates a new function
* Creates a new function.
*
* Attention: Column names inside the call have to be quoted before hand
* @warning Column names inside the call have to be quoted beforehand. In most
* case you can use the IFunctionBuilder instead.
*
* Example:
* <code>
Expand Down
Loading