@@ -31,128 +31,128 @@ |
||
| 31 | 31 | * @since 12.0.0 |
| 32 | 32 | */ |
| 33 | 33 | interface IFunctionBuilder { |
| 34 | - /** |
|
| 35 | - * Calculates the MD5 hash of a given input |
|
| 36 | - * |
|
| 37 | - * @param mixed $input The input to be hashed |
|
| 38 | - * |
|
| 39 | - * @return IQueryFunction |
|
| 40 | - * @since 12.0.0 |
|
| 41 | - */ |
|
| 42 | - public function md5($input); |
|
| 34 | + /** |
|
| 35 | + * Calculates the MD5 hash of a given input |
|
| 36 | + * |
|
| 37 | + * @param mixed $input The input to be hashed |
|
| 38 | + * |
|
| 39 | + * @return IQueryFunction |
|
| 40 | + * @since 12.0.0 |
|
| 41 | + */ |
|
| 42 | + public function md5($input); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Combines two input strings |
|
| 46 | - * |
|
| 47 | - * @param mixed $x The first input string |
|
| 48 | - * @param mixed $y The seccond input string |
|
| 49 | - * |
|
| 50 | - * @return IQueryFunction |
|
| 51 | - * @since 12.0.0 |
|
| 52 | - */ |
|
| 53 | - public function concat($x, $y); |
|
| 44 | + /** |
|
| 45 | + * Combines two input strings |
|
| 46 | + * |
|
| 47 | + * @param mixed $x The first input string |
|
| 48 | + * @param mixed $y The seccond input string |
|
| 49 | + * |
|
| 50 | + * @return IQueryFunction |
|
| 51 | + * @since 12.0.0 |
|
| 52 | + */ |
|
| 53 | + public function concat($x, $y); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Takes a substring from the input string |
|
| 57 | - * |
|
| 58 | - * @param mixed $input The input string |
|
| 59 | - * @param mixed $start The start of the substring, note that counting starts at 1 |
|
| 60 | - * @param mixed $length The length of the substring |
|
| 61 | - * |
|
| 62 | - * @return IQueryFunction |
|
| 63 | - * @since 12.0.0 |
|
| 64 | - */ |
|
| 65 | - public function substring($input, $start, $length = null); |
|
| 55 | + /** |
|
| 56 | + * Takes a substring from the input string |
|
| 57 | + * |
|
| 58 | + * @param mixed $input The input string |
|
| 59 | + * @param mixed $start The start of the substring, note that counting starts at 1 |
|
| 60 | + * @param mixed $length The length of the substring |
|
| 61 | + * |
|
| 62 | + * @return IQueryFunction |
|
| 63 | + * @since 12.0.0 |
|
| 64 | + */ |
|
| 65 | + public function substring($input, $start, $length = null); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Takes the sum of all rows in a column |
|
| 69 | - * |
|
| 70 | - * @param mixed $field the column to sum |
|
| 71 | - * |
|
| 72 | - * @return IQueryFunction |
|
| 73 | - * @since 12.0.0 |
|
| 74 | - */ |
|
| 75 | - public function sum($field); |
|
| 67 | + /** |
|
| 68 | + * Takes the sum of all rows in a column |
|
| 69 | + * |
|
| 70 | + * @param mixed $field the column to sum |
|
| 71 | + * |
|
| 72 | + * @return IQueryFunction |
|
| 73 | + * @since 12.0.0 |
|
| 74 | + */ |
|
| 75 | + public function sum($field); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Transforms a string field or value to lower case |
|
| 79 | - * |
|
| 80 | - * @param mixed $field |
|
| 81 | - * @return IQueryFunction |
|
| 82 | - * @since 14.0.0 |
|
| 83 | - */ |
|
| 84 | - public function lower($field); |
|
| 77 | + /** |
|
| 78 | + * Transforms a string field or value to lower case |
|
| 79 | + * |
|
| 80 | + * @param mixed $field |
|
| 81 | + * @return IQueryFunction |
|
| 82 | + * @since 14.0.0 |
|
| 83 | + */ |
|
| 84 | + public function lower($field); |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @param mixed $x The first input field or number |
|
| 88 | - * @param mixed $y The second input field or number |
|
| 89 | - * @return IQueryFunction |
|
| 90 | - * @since 14.0.0 |
|
| 91 | - */ |
|
| 92 | - public function add($x, $y); |
|
| 86 | + /** |
|
| 87 | + * @param mixed $x The first input field or number |
|
| 88 | + * @param mixed $y The second input field or number |
|
| 89 | + * @return IQueryFunction |
|
| 90 | + * @since 14.0.0 |
|
| 91 | + */ |
|
| 92 | + public function add($x, $y); |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @param mixed $x The first input field or number |
|
| 96 | - * @param mixed $y The second input field or number |
|
| 97 | - * @return IQueryFunction |
|
| 98 | - * @since 14.0.0 |
|
| 99 | - */ |
|
| 100 | - public function subtract($x, $y); |
|
| 94 | + /** |
|
| 95 | + * @param mixed $x The first input field or number |
|
| 96 | + * @param mixed $y The second input field or number |
|
| 97 | + * @return IQueryFunction |
|
| 98 | + * @since 14.0.0 |
|
| 99 | + */ |
|
| 100 | + public function subtract($x, $y); |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @param mixed $count The input to be counted |
|
| 104 | - * @param string $alias Alias for the counter |
|
| 105 | - * |
|
| 106 | - * @return IQueryFunction |
|
| 107 | - * @since 14.0.0 |
|
| 108 | - */ |
|
| 109 | - public function count($count = '', $alias = ''); |
|
| 102 | + /** |
|
| 103 | + * @param mixed $count The input to be counted |
|
| 104 | + * @param string $alias Alias for the counter |
|
| 105 | + * |
|
| 106 | + * @return IQueryFunction |
|
| 107 | + * @since 14.0.0 |
|
| 108 | + */ |
|
| 109 | + public function count($count = '', $alias = ''); |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Takes the maximum of all rows in a column |
|
| 113 | - * |
|
| 114 | - * If you want to get the maximum value of multiple columns in the same row, use `greatest` instead |
|
| 115 | - * |
|
| 116 | - * @param mixed $field the column to maximum |
|
| 117 | - * |
|
| 118 | - * @return IQueryFunction |
|
| 119 | - * @since 18.0.0 |
|
| 120 | - */ |
|
| 121 | - public function max($field); |
|
| 111 | + /** |
|
| 112 | + * Takes the maximum of all rows in a column |
|
| 113 | + * |
|
| 114 | + * If you want to get the maximum value of multiple columns in the same row, use `greatest` instead |
|
| 115 | + * |
|
| 116 | + * @param mixed $field the column to maximum |
|
| 117 | + * |
|
| 118 | + * @return IQueryFunction |
|
| 119 | + * @since 18.0.0 |
|
| 120 | + */ |
|
| 121 | + public function max($field); |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Takes the minimum of all rows in a column |
|
| 125 | - * |
|
| 126 | - * If you want to get the minimum value of multiple columns in the same row, use `least` instead |
|
| 127 | - * |
|
| 128 | - * @param mixed $field the column to minimum |
|
| 129 | - * |
|
| 130 | - * @return IQueryFunction |
|
| 131 | - * @since 18.0.0 |
|
| 132 | - */ |
|
| 133 | - public function min($field); |
|
| 123 | + /** |
|
| 124 | + * Takes the minimum of all rows in a column |
|
| 125 | + * |
|
| 126 | + * If you want to get the minimum value of multiple columns in the same row, use `least` instead |
|
| 127 | + * |
|
| 128 | + * @param mixed $field the column to minimum |
|
| 129 | + * |
|
| 130 | + * @return IQueryFunction |
|
| 131 | + * @since 18.0.0 |
|
| 132 | + */ |
|
| 133 | + public function min($field); |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Takes the maximum of multiple values |
|
| 137 | - * |
|
| 138 | - * If you want to get the maximum value of all rows in a column, use `max` instead |
|
| 139 | - * |
|
| 140 | - * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 141 | - * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 142 | - * @return IQueryFunction |
|
| 143 | - * @since 18.0.0 |
|
| 144 | - */ |
|
| 145 | - public function greatest($x, $y); |
|
| 135 | + /** |
|
| 136 | + * Takes the maximum of multiple values |
|
| 137 | + * |
|
| 138 | + * If you want to get the maximum value of all rows in a column, use `max` instead |
|
| 139 | + * |
|
| 140 | + * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 141 | + * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 142 | + * @return IQueryFunction |
|
| 143 | + * @since 18.0.0 |
|
| 144 | + */ |
|
| 145 | + public function greatest($x, $y); |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Takes the minimum of multiple values |
|
| 149 | - * |
|
| 150 | - * If you want to get the minimum value of all rows in a column, use `min` instead |
|
| 151 | - * |
|
| 152 | - * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 153 | - * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 154 | - * @return IQueryFunction |
|
| 155 | - * @since 18.0.0 |
|
| 156 | - */ |
|
| 157 | - public function least($x, $y); |
|
| 147 | + /** |
|
| 148 | + * Takes the minimum of multiple values |
|
| 149 | + * |
|
| 150 | + * If you want to get the minimum value of all rows in a column, use `min` instead |
|
| 151 | + * |
|
| 152 | + * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 153 | + * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 154 | + * @return IQueryFunction |
|
| 155 | + * @since 18.0.0 |
|
| 156 | + */ |
|
| 157 | + public function least($x, $y); |
|
| 158 | 158 | } |
@@ -33,169 +33,169 @@ |
||
| 33 | 33 | * Propagate etags and mtimes within the storage |
| 34 | 34 | */ |
| 35 | 35 | class Propagator implements IPropagator { |
| 36 | - private $inBatch = false; |
|
| 37 | - |
|
| 38 | - private $batch = []; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var \OC\Files\Storage\Storage |
|
| 42 | - */ |
|
| 43 | - protected $storage; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var IDBConnection |
|
| 47 | - */ |
|
| 48 | - private $connection; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var array |
|
| 52 | - */ |
|
| 53 | - private $ignore = []; |
|
| 54 | - |
|
| 55 | - public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection, array $ignore = []) { |
|
| 56 | - $this->storage = $storage; |
|
| 57 | - $this->connection = $connection; |
|
| 58 | - $this->ignore = $ignore; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param string $internalPath |
|
| 64 | - * @param int $time |
|
| 65 | - * @param int $sizeDifference number of bytes the file has grown |
|
| 66 | - */ |
|
| 67 | - public function propagateChange($internalPath, $time, $sizeDifference = 0) { |
|
| 68 | - // Do not propogate changes in ignored paths |
|
| 69 | - foreach ($this->ignore as $ignore) { |
|
| 70 | - if (strpos($internalPath, $ignore) === 0) { |
|
| 71 | - return; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $storageId = (int)$this->storage->getStorageCache()->getNumericId(); |
|
| 76 | - |
|
| 77 | - $parents = $this->getParents($internalPath); |
|
| 78 | - |
|
| 79 | - if ($this->inBatch) { |
|
| 80 | - foreach ($parents as $parent) { |
|
| 81 | - $this->addToBatch($parent, $time, $sizeDifference); |
|
| 82 | - } |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $parentHashes = array_map('md5', $parents); |
|
| 87 | - $etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag |
|
| 88 | - |
|
| 89 | - $builder = $this->connection->getQueryBuilder(); |
|
| 90 | - $hashParams = array_map(function ($hash) use ($builder) { |
|
| 91 | - return $builder->expr()->literal($hash); |
|
| 92 | - }, $parentHashes); |
|
| 93 | - |
|
| 94 | - $builder->update('filecache') |
|
| 95 | - ->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT))) |
|
| 96 | - ->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR)) |
|
| 97 | - ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) |
|
| 98 | - ->andWhere($builder->expr()->in('path_hash', $hashParams)); |
|
| 99 | - |
|
| 100 | - $builder->execute(); |
|
| 101 | - |
|
| 102 | - if ($sizeDifference !== 0) { |
|
| 103 | - // we need to do size separably so we can ignore entries with uncalculated size |
|
| 104 | - $builder = $this->connection->getQueryBuilder(); |
|
| 105 | - $builder->update('filecache') |
|
| 106 | - ->set('size', $builder->func()->greatest( |
|
| 107 | - $builder->func()->add('size', $builder->createNamedParameter($sizeDifference)), |
|
| 108 | - $builder->createNamedParameter(-1, IQueryBuilder::PARAM_INT) |
|
| 109 | - )) |
|
| 110 | - ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) |
|
| 111 | - ->andWhere($builder->expr()->in('path_hash', $hashParams)) |
|
| 112 | - ->andWhere($builder->expr()->gt('size', $builder->expr()->literal(-1, IQueryBuilder::PARAM_INT))); |
|
| 113 | - |
|
| 114 | - $builder->execute(); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - protected function getParents($path) { |
|
| 119 | - $parts = explode('/', $path); |
|
| 120 | - $parent = ''; |
|
| 121 | - $parents = []; |
|
| 122 | - foreach ($parts as $part) { |
|
| 123 | - $parents[] = $parent; |
|
| 124 | - $parent = trim($parent . '/' . $part, '/'); |
|
| 125 | - } |
|
| 126 | - return $parents; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Mark the beginning of a propagation batch |
|
| 131 | - * |
|
| 132 | - * Note that not all cache setups support propagation in which case this will be a noop |
|
| 133 | - * |
|
| 134 | - * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent |
|
| 135 | - * before the batch is committed. |
|
| 136 | - */ |
|
| 137 | - public function beginBatch() { |
|
| 138 | - $this->inBatch = true; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - private function addToBatch($internalPath, $time, $sizeDifference) { |
|
| 142 | - if (!isset($this->batch[$internalPath])) { |
|
| 143 | - $this->batch[$internalPath] = [ |
|
| 144 | - 'hash' => md5($internalPath), |
|
| 145 | - 'time' => $time, |
|
| 146 | - 'size' => $sizeDifference |
|
| 147 | - ]; |
|
| 148 | - } else { |
|
| 149 | - $this->batch[$internalPath]['size'] += $sizeDifference; |
|
| 150 | - if ($time > $this->batch[$internalPath]['time']) { |
|
| 151 | - $this->batch[$internalPath]['time'] = $time; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Commit the active propagation batch |
|
| 158 | - */ |
|
| 159 | - public function commitBatch() { |
|
| 160 | - if (!$this->inBatch) { |
|
| 161 | - throw new \BadMethodCallException('Not in batch'); |
|
| 162 | - } |
|
| 163 | - $this->inBatch = false; |
|
| 164 | - |
|
| 165 | - $this->connection->beginTransaction(); |
|
| 166 | - |
|
| 167 | - $query = $this->connection->getQueryBuilder(); |
|
| 168 | - $storageId = (int)$this->storage->getStorageCache()->getNumericId(); |
|
| 169 | - |
|
| 170 | - $query->update('filecache') |
|
| 171 | - ->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time'))) |
|
| 172 | - ->set('etag', $query->expr()->literal(uniqid())) |
|
| 173 | - ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT))) |
|
| 174 | - ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))); |
|
| 175 | - |
|
| 176 | - $sizeQuery = $this->connection->getQueryBuilder(); |
|
| 177 | - $sizeQuery->update('filecache') |
|
| 178 | - ->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size'))) |
|
| 179 | - ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT))) |
|
| 180 | - ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))) |
|
| 181 | - ->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT))); |
|
| 182 | - |
|
| 183 | - foreach ($this->batch as $item) { |
|
| 184 | - $query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT); |
|
| 185 | - $query->setParameter('hash', $item['hash']); |
|
| 186 | - |
|
| 187 | - $query->execute(); |
|
| 188 | - |
|
| 189 | - if ($item['size']) { |
|
| 190 | - $sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT); |
|
| 191 | - $sizeQuery->setParameter('hash', $item['hash']); |
|
| 192 | - |
|
| 193 | - $sizeQuery->execute(); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $this->batch = []; |
|
| 198 | - |
|
| 199 | - $this->connection->commit(); |
|
| 200 | - } |
|
| 36 | + private $inBatch = false; |
|
| 37 | + |
|
| 38 | + private $batch = []; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var \OC\Files\Storage\Storage |
|
| 42 | + */ |
|
| 43 | + protected $storage; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var IDBConnection |
|
| 47 | + */ |
|
| 48 | + private $connection; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var array |
|
| 52 | + */ |
|
| 53 | + private $ignore = []; |
|
| 54 | + |
|
| 55 | + public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection, array $ignore = []) { |
|
| 56 | + $this->storage = $storage; |
|
| 57 | + $this->connection = $connection; |
|
| 58 | + $this->ignore = $ignore; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param string $internalPath |
|
| 64 | + * @param int $time |
|
| 65 | + * @param int $sizeDifference number of bytes the file has grown |
|
| 66 | + */ |
|
| 67 | + public function propagateChange($internalPath, $time, $sizeDifference = 0) { |
|
| 68 | + // Do not propogate changes in ignored paths |
|
| 69 | + foreach ($this->ignore as $ignore) { |
|
| 70 | + if (strpos($internalPath, $ignore) === 0) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $storageId = (int)$this->storage->getStorageCache()->getNumericId(); |
|
| 76 | + |
|
| 77 | + $parents = $this->getParents($internalPath); |
|
| 78 | + |
|
| 79 | + if ($this->inBatch) { |
|
| 80 | + foreach ($parents as $parent) { |
|
| 81 | + $this->addToBatch($parent, $time, $sizeDifference); |
|
| 82 | + } |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $parentHashes = array_map('md5', $parents); |
|
| 87 | + $etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag |
|
| 88 | + |
|
| 89 | + $builder = $this->connection->getQueryBuilder(); |
|
| 90 | + $hashParams = array_map(function ($hash) use ($builder) { |
|
| 91 | + return $builder->expr()->literal($hash); |
|
| 92 | + }, $parentHashes); |
|
| 93 | + |
|
| 94 | + $builder->update('filecache') |
|
| 95 | + ->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT))) |
|
| 96 | + ->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR)) |
|
| 97 | + ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) |
|
| 98 | + ->andWhere($builder->expr()->in('path_hash', $hashParams)); |
|
| 99 | + |
|
| 100 | + $builder->execute(); |
|
| 101 | + |
|
| 102 | + if ($sizeDifference !== 0) { |
|
| 103 | + // we need to do size separably so we can ignore entries with uncalculated size |
|
| 104 | + $builder = $this->connection->getQueryBuilder(); |
|
| 105 | + $builder->update('filecache') |
|
| 106 | + ->set('size', $builder->func()->greatest( |
|
| 107 | + $builder->func()->add('size', $builder->createNamedParameter($sizeDifference)), |
|
| 108 | + $builder->createNamedParameter(-1, IQueryBuilder::PARAM_INT) |
|
| 109 | + )) |
|
| 110 | + ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) |
|
| 111 | + ->andWhere($builder->expr()->in('path_hash', $hashParams)) |
|
| 112 | + ->andWhere($builder->expr()->gt('size', $builder->expr()->literal(-1, IQueryBuilder::PARAM_INT))); |
|
| 113 | + |
|
| 114 | + $builder->execute(); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + protected function getParents($path) { |
|
| 119 | + $parts = explode('/', $path); |
|
| 120 | + $parent = ''; |
|
| 121 | + $parents = []; |
|
| 122 | + foreach ($parts as $part) { |
|
| 123 | + $parents[] = $parent; |
|
| 124 | + $parent = trim($parent . '/' . $part, '/'); |
|
| 125 | + } |
|
| 126 | + return $parents; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Mark the beginning of a propagation batch |
|
| 131 | + * |
|
| 132 | + * Note that not all cache setups support propagation in which case this will be a noop |
|
| 133 | + * |
|
| 134 | + * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent |
|
| 135 | + * before the batch is committed. |
|
| 136 | + */ |
|
| 137 | + public function beginBatch() { |
|
| 138 | + $this->inBatch = true; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + private function addToBatch($internalPath, $time, $sizeDifference) { |
|
| 142 | + if (!isset($this->batch[$internalPath])) { |
|
| 143 | + $this->batch[$internalPath] = [ |
|
| 144 | + 'hash' => md5($internalPath), |
|
| 145 | + 'time' => $time, |
|
| 146 | + 'size' => $sizeDifference |
|
| 147 | + ]; |
|
| 148 | + } else { |
|
| 149 | + $this->batch[$internalPath]['size'] += $sizeDifference; |
|
| 150 | + if ($time > $this->batch[$internalPath]['time']) { |
|
| 151 | + $this->batch[$internalPath]['time'] = $time; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Commit the active propagation batch |
|
| 158 | + */ |
|
| 159 | + public function commitBatch() { |
|
| 160 | + if (!$this->inBatch) { |
|
| 161 | + throw new \BadMethodCallException('Not in batch'); |
|
| 162 | + } |
|
| 163 | + $this->inBatch = false; |
|
| 164 | + |
|
| 165 | + $this->connection->beginTransaction(); |
|
| 166 | + |
|
| 167 | + $query = $this->connection->getQueryBuilder(); |
|
| 168 | + $storageId = (int)$this->storage->getStorageCache()->getNumericId(); |
|
| 169 | + |
|
| 170 | + $query->update('filecache') |
|
| 171 | + ->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time'))) |
|
| 172 | + ->set('etag', $query->expr()->literal(uniqid())) |
|
| 173 | + ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT))) |
|
| 174 | + ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))); |
|
| 175 | + |
|
| 176 | + $sizeQuery = $this->connection->getQueryBuilder(); |
|
| 177 | + $sizeQuery->update('filecache') |
|
| 178 | + ->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size'))) |
|
| 179 | + ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT))) |
|
| 180 | + ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))) |
|
| 181 | + ->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT))); |
|
| 182 | + |
|
| 183 | + foreach ($this->batch as $item) { |
|
| 184 | + $query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT); |
|
| 185 | + $query->setParameter('hash', $item['hash']); |
|
| 186 | + |
|
| 187 | + $query->execute(); |
|
| 188 | + |
|
| 189 | + if ($item['size']) { |
|
| 190 | + $sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT); |
|
| 191 | + $sizeQuery->setParameter('hash', $item['hash']); |
|
| 192 | + |
|
| 193 | + $sizeQuery->execute(); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $this->batch = []; |
|
| 198 | + |
|
| 199 | + $this->connection->commit(); |
|
| 200 | + } |
|
| 201 | 201 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $storageId = (int)$this->storage->getStorageCache()->getNumericId(); |
|
| 75 | + $storageId = (int) $this->storage->getStorageCache()->getNumericId(); |
|
| 76 | 76 | |
| 77 | 77 | $parents = $this->getParents($internalPath); |
| 78 | 78 | |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | $etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag |
| 88 | 88 | |
| 89 | 89 | $builder = $this->connection->getQueryBuilder(); |
| 90 | - $hashParams = array_map(function ($hash) use ($builder) { |
|
| 90 | + $hashParams = array_map(function($hash) use ($builder) { |
|
| 91 | 91 | return $builder->expr()->literal($hash); |
| 92 | 92 | }, $parentHashes); |
| 93 | 93 | |
| 94 | 94 | $builder->update('filecache') |
| 95 | - ->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT))) |
|
| 95 | + ->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int) $time, IQueryBuilder::PARAM_INT))) |
|
| 96 | 96 | ->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR)) |
| 97 | 97 | ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) |
| 98 | 98 | ->andWhere($builder->expr()->in('path_hash', $hashParams)); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $parents = []; |
| 122 | 122 | foreach ($parts as $part) { |
| 123 | 123 | $parents[] = $parent; |
| 124 | - $parent = trim($parent . '/' . $part, '/'); |
|
| 124 | + $parent = trim($parent.'/'.$part, '/'); |
|
| 125 | 125 | } |
| 126 | 126 | return $parents; |
| 127 | 127 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | $this->connection->beginTransaction(); |
| 166 | 166 | |
| 167 | 167 | $query = $this->connection->getQueryBuilder(); |
| 168 | - $storageId = (int)$this->storage->getStorageCache()->getNumericId(); |
|
| 168 | + $storageId = (int) $this->storage->getStorageCache()->getNumericId(); |
|
| 169 | 169 | |
| 170 | 170 | $query->update('filecache') |
| 171 | 171 | ->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time'))) |
@@ -32,79 +32,79 @@ |
||
| 32 | 32 | use OCP\DB\QueryBuilder\IQueryFunction; |
| 33 | 33 | |
| 34 | 34 | class FunctionBuilder implements IFunctionBuilder { |
| 35 | - /** @var QuoteHelper */ |
|
| 36 | - protected $helper; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * ExpressionBuilder constructor. |
|
| 40 | - * |
|
| 41 | - * @param QuoteHelper $helper |
|
| 42 | - */ |
|
| 43 | - public function __construct(QuoteHelper $helper) { |
|
| 44 | - $this->helper = $helper; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function md5($input) { |
|
| 48 | - return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')'); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function concat($x, $y) { |
|
| 52 | - return new QueryFunction('CONCAT(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function substring($input, $start, $length = null) { |
|
| 56 | - if ($length) { |
|
| 57 | - return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')'); |
|
| 58 | - } else { |
|
| 59 | - return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')'); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function sum($field) { |
|
| 64 | - return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function lower($field) { |
|
| 68 | - return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function add($x, $y) { |
|
| 72 | - return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y)); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function subtract($x, $y) { |
|
| 76 | - return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y)); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function count($count = '', $alias = '') { |
|
| 80 | - $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : ''; |
|
| 81 | - $quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count); |
|
| 82 | - return new QueryFunction('COUNT(' . $quotedName . ')' . $alias); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function max($field) { |
|
| 86 | - return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function min($field) { |
|
| 90 | - return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 95 | - * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 96 | - * @return IQueryFunction |
|
| 97 | - */ |
|
| 98 | - public function greatest($x, $y) { |
|
| 99 | - return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 104 | - * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 105 | - * @return IQueryFunction |
|
| 106 | - */ |
|
| 107 | - public function least($x, $y) { |
|
| 108 | - return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 109 | - } |
|
| 35 | + /** @var QuoteHelper */ |
|
| 36 | + protected $helper; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * ExpressionBuilder constructor. |
|
| 40 | + * |
|
| 41 | + * @param QuoteHelper $helper |
|
| 42 | + */ |
|
| 43 | + public function __construct(QuoteHelper $helper) { |
|
| 44 | + $this->helper = $helper; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function md5($input) { |
|
| 48 | + return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')'); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function concat($x, $y) { |
|
| 52 | + return new QueryFunction('CONCAT(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function substring($input, $start, $length = null) { |
|
| 56 | + if ($length) { |
|
| 57 | + return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')'); |
|
| 58 | + } else { |
|
| 59 | + return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')'); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function sum($field) { |
|
| 64 | + return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function lower($field) { |
|
| 68 | + return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function add($x, $y) { |
|
| 72 | + return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y)); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function subtract($x, $y) { |
|
| 76 | + return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y)); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function count($count = '', $alias = '') { |
|
| 80 | + $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : ''; |
|
| 81 | + $quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count); |
|
| 82 | + return new QueryFunction('COUNT(' . $quotedName . ')' . $alias); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function max($field) { |
|
| 86 | + return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function min($field) { |
|
| 90 | + return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 95 | + * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 96 | + * @return IQueryFunction |
|
| 97 | + */ |
|
| 98 | + public function greatest($x, $y) { |
|
| 99 | + return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 104 | + * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 105 | + * @return IQueryFunction |
|
| 106 | + */ |
|
| 107 | + public function least($x, $y) { |
|
| 108 | + return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 109 | + } |
|
| 110 | 110 | } |
@@ -45,49 +45,49 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function md5($input) { |
| 48 | - return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')'); |
|
| 48 | + return new QueryFunction('MD5('.$this->helper->quoteColumnName($input).')'); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | public function concat($x, $y) { |
| 52 | - return new QueryFunction('CONCAT(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 52 | + return new QueryFunction('CONCAT('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public function substring($input, $start, $length = null) { |
| 56 | 56 | if ($length) { |
| 57 | - return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')'); |
|
| 57 | + return new QueryFunction('SUBSTR('.$this->helper->quoteColumnName($input).', '.$this->helper->quoteColumnName($start).', '.$this->helper->quoteColumnName($length).')'); |
|
| 58 | 58 | } else { |
| 59 | - return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')'); |
|
| 59 | + return new QueryFunction('SUBSTR('.$this->helper->quoteColumnName($input).', '.$this->helper->quoteColumnName($start).')'); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function sum($field) { |
| 64 | - return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 64 | + return new QueryFunction('SUM('.$this->helper->quoteColumnName($field).')'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | public function lower($field) { |
| 68 | - return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 68 | + return new QueryFunction('LOWER('.$this->helper->quoteColumnName($field).')'); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | public function add($x, $y) { |
| 72 | - return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y)); |
|
| 72 | + return new QueryFunction($this->helper->quoteColumnName($x).' + '.$this->helper->quoteColumnName($y)); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function subtract($x, $y) { |
| 76 | - return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y)); |
|
| 76 | + return new QueryFunction($this->helper->quoteColumnName($x).' - '.$this->helper->quoteColumnName($y)); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | public function count($count = '', $alias = '') { |
| 80 | - $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : ''; |
|
| 80 | + $alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : ''; |
|
| 81 | 81 | $quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count); |
| 82 | - return new QueryFunction('COUNT(' . $quotedName . ')' . $alias); |
|
| 82 | + return new QueryFunction('COUNT('.$quotedName.')'.$alias); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | public function max($field) { |
| 86 | - return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 86 | + return new QueryFunction('MAX('.$this->helper->quoteColumnName($field).')'); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | public function min($field) { |
| 90 | - return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')'); |
|
| 90 | + return new QueryFunction('MIN('.$this->helper->quoteColumnName($field).')'); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @return IQueryFunction |
| 97 | 97 | */ |
| 98 | 98 | public function greatest($x, $y) { |
| 99 | - return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 99 | + return new QueryFunction('GREATEST('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,6 +105,6 @@ discard block |
||
| 105 | 105 | * @return IQueryFunction |
| 106 | 106 | */ |
| 107 | 107 | public function least($x, $y) { |
| 108 | - return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 108 | + return new QueryFunction('LEAST('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')'); |
|
| 109 | 109 | } |
| 110 | 110 | } |
@@ -29,47 +29,47 @@ |
||
| 29 | 29 | use OCP\DB\QueryBuilder\IQueryFunction; |
| 30 | 30 | |
| 31 | 31 | class OCIFunctionBuilder extends FunctionBuilder { |
| 32 | - public function md5($input) { |
|
| 33 | - return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(' . $this->helper->quoteColumnName($input) .')))'); |
|
| 34 | - } |
|
| 32 | + public function md5($input) { |
|
| 33 | + return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(' . $this->helper->quoteColumnName($input) .')))'); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * As per https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions060.htm |
|
| 38 | - * Oracle uses the first value to cast the rest or the values. So when the |
|
| 39 | - * first value is a literal, plain value or column, instead of doing the |
|
| 40 | - * math, it will cast the expression to int and continue with a "0". So when |
|
| 41 | - * the second parameter is a function or column, we have to put that as |
|
| 42 | - * first parameter. |
|
| 43 | - * |
|
| 44 | - * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 45 | - * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 46 | - * @return IQueryFunction |
|
| 47 | - */ |
|
| 48 | - public function greatest($x, $y) { |
|
| 49 | - if (is_string($y) || $y instanceof IQueryFunction) { |
|
| 50 | - return parent::greatest($y, $x); |
|
| 51 | - } |
|
| 36 | + /** |
|
| 37 | + * As per https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions060.htm |
|
| 38 | + * Oracle uses the first value to cast the rest or the values. So when the |
|
| 39 | + * first value is a literal, plain value or column, instead of doing the |
|
| 40 | + * math, it will cast the expression to int and continue with a "0". So when |
|
| 41 | + * the second parameter is a function or column, we have to put that as |
|
| 42 | + * first parameter. |
|
| 43 | + * |
|
| 44 | + * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 45 | + * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 46 | + * @return IQueryFunction |
|
| 47 | + */ |
|
| 48 | + public function greatest($x, $y) { |
|
| 49 | + if (is_string($y) || $y instanceof IQueryFunction) { |
|
| 50 | + return parent::greatest($y, $x); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return parent::greatest($x, $y); |
|
| 54 | - } |
|
| 53 | + return parent::greatest($x, $y); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * As per https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions060.htm |
|
| 58 | - * Oracle uses the first value to cast the rest or the values. So when the |
|
| 59 | - * first value is a literal, plain value or column, instead of doing the |
|
| 60 | - * math, it will cast the expression to int and continue with a "0". So when |
|
| 61 | - * the second parameter is a function or column, we have to put that as |
|
| 62 | - * first parameter. |
|
| 63 | - * |
|
| 64 | - * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 65 | - * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 66 | - * @return IQueryFunction |
|
| 67 | - */ |
|
| 68 | - public function least($x, $y) { |
|
| 69 | - if (is_string($y) || $y instanceof IQueryFunction) { |
|
| 70 | - return parent::least($y, $x); |
|
| 71 | - } |
|
| 56 | + /** |
|
| 57 | + * As per https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions060.htm |
|
| 58 | + * Oracle uses the first value to cast the rest or the values. So when the |
|
| 59 | + * first value is a literal, plain value or column, instead of doing the |
|
| 60 | + * math, it will cast the expression to int and continue with a "0". So when |
|
| 61 | + * the second parameter is a function or column, we have to put that as |
|
| 62 | + * first parameter. |
|
| 63 | + * |
|
| 64 | + * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 65 | + * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 66 | + * @return IQueryFunction |
|
| 67 | + */ |
|
| 68 | + public function least($x, $y) { |
|
| 69 | + if (is_string($y) || $y instanceof IQueryFunction) { |
|
| 70 | + return parent::least($y, $x); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - return parent::least($x, $y); |
|
| 74 | - } |
|
| 73 | + return parent::least($x, $y); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | |
| 31 | 31 | class OCIFunctionBuilder extends FunctionBuilder { |
| 32 | 32 | public function md5($input) { |
| 33 | - return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(' . $this->helper->quoteColumnName($input) .')))'); |
|
| 33 | + return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw('.$this->helper->quoteColumnName($input).')))'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -30,25 +30,25 @@ |
||
| 30 | 30 | use OCP\DB\QueryBuilder\IQueryFunction; |
| 31 | 31 | |
| 32 | 32 | class SqliteFunctionBuilder extends FunctionBuilder { |
| 33 | - public function concat($x, $y) { |
|
| 34 | - return new QueryFunction('(' . $this->helper->quoteColumnName($x) . ' || ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 35 | - } |
|
| 33 | + public function concat($x, $y) { |
|
| 34 | + return new QueryFunction('(' . $this->helper->quoteColumnName($x) . ' || ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 39 | - * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 40 | - * @return IQueryFunction |
|
| 41 | - */ |
|
| 42 | - public function greatest($x, $y) { |
|
| 43 | - return new QueryFunction('MAX(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 39 | + * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 40 | + * @return IQueryFunction |
|
| 41 | + */ |
|
| 42 | + public function greatest($x, $y) { |
|
| 43 | + return new QueryFunction('MAX(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 48 | - * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 49 | - * @return IQueryFunction |
|
| 50 | - */ |
|
| 51 | - public function least($x, $y) { |
|
| 52 | - return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * @param string|ILiteral|IParameter|IQueryFunction $x |
|
| 48 | + * @param string|ILiteral|IParameter|IQueryFunction $y |
|
| 49 | + * @return IQueryFunction |
|
| 50 | + */ |
|
| 51 | + public function least($x, $y) { |
|
| 52 | + return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | class SqliteFunctionBuilder extends FunctionBuilder { |
| 33 | 33 | public function concat($x, $y) { |
| 34 | - return new QueryFunction('(' . $this->helper->quoteColumnName($x) . ' || ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 34 | + return new QueryFunction('('.$this->helper->quoteColumnName($x).' || '.$this->helper->quoteColumnName($y).')'); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @return IQueryFunction |
| 41 | 41 | */ |
| 42 | 42 | public function greatest($x, $y) { |
| 43 | - return new QueryFunction('MAX(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 43 | + return new QueryFunction('MAX('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -49,6 +49,6 @@ discard block |
||
| 49 | 49 | * @return IQueryFunction |
| 50 | 50 | */ |
| 51 | 51 | public function least($x, $y) { |
| 52 | - return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); |
|
| 52 | + return new QueryFunction('MIN('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')'); |
|
| 53 | 53 | } |
| 54 | 54 | } |