1
0

IFunctionBuilder.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCP\DB\QueryBuilder;
  26. /**
  27. * This class provides a builder for sql some functions
  28. *
  29. * @since 12.0.0
  30. */
  31. interface IFunctionBuilder {
  32. /**
  33. * Calculates the MD5 hash of a given input
  34. *
  35. * @param string|ILiteral|IParameter|IQueryFunction $input The input to be hashed
  36. *
  37. * @return IQueryFunction
  38. * @since 12.0.0
  39. */
  40. public function md5($input): IQueryFunction;
  41. /**
  42. * Combines two input strings
  43. *
  44. * @param string|ILiteral|IParameter|IQueryFunction $x Expressions or literal strings
  45. * @param string|ILiteral|IParameter|IQueryFunction ...$exprs Expressions or literal strings
  46. *
  47. * @return IQueryFunction
  48. * @since 12.0.0
  49. */
  50. public function concat($x, ...$expr): IQueryFunction;
  51. /**
  52. * Returns a string which is the concatenation of all non-NULL values of X
  53. *
  54. * Usage examples:
  55. *
  56. * groupConcat('column') -- with comma as separator (default separator)
  57. *
  58. * groupConcat('column', ';') -- with different separator
  59. *
  60. * @param string|IQueryFunction $expr The expression to group
  61. * @param string|null $separator The separator
  62. * @return IQueryFunction
  63. * @since 24.0.0
  64. */
  65. public function groupConcat($expr, ?string $separator = ','): IQueryFunction;
  66. /**
  67. * Takes a substring from the input string
  68. *
  69. * @param string|ILiteral|IParameter|IQueryFunction $input The input string
  70. * @param string|ILiteral|IParameter|IQueryFunction $start The start of the substring, note that counting starts at 1
  71. * @param null|ILiteral|IParameter|IQueryFunction $length The length of the substring
  72. *
  73. * @return IQueryFunction
  74. * @since 12.0.0
  75. */
  76. public function substring($input, $start, $length = null): IQueryFunction;
  77. /**
  78. * Takes the sum of all rows in a column
  79. *
  80. * @param string|ILiteral|IParameter|IQueryFunction $field the column to sum
  81. *
  82. * @return IQueryFunction
  83. * @since 12.0.0
  84. */
  85. public function sum($field): IQueryFunction;
  86. /**
  87. * Transforms a string field or value to lower case
  88. *
  89. * @param string|ILiteral|IParameter|IQueryFunction $field
  90. * @return IQueryFunction
  91. * @since 14.0.0
  92. */
  93. public function lower($field): IQueryFunction;
  94. /**
  95. * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
  96. * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
  97. * @return IQueryFunction
  98. * @since 14.0.0
  99. */
  100. public function add($x, $y): IQueryFunction;
  101. /**
  102. * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
  103. * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
  104. * @return IQueryFunction
  105. * @since 14.0.0
  106. */
  107. public function subtract($x, $y): IQueryFunction;
  108. /**
  109. * @param string|ILiteral|IParameter|IQueryFunction $count The input to be counted
  110. * @param string $alias Alias for the counter
  111. *
  112. * @return IQueryFunction
  113. * @since 14.0.0
  114. */
  115. public function count($count = '', $alias = ''): IQueryFunction;
  116. /**
  117. * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
  118. * @param string $alias Alias for the length
  119. *
  120. * @return IQueryFunction
  121. * @since 24.0.0
  122. */
  123. public function octetLength($field, $alias = ''): IQueryFunction;
  124. /**
  125. * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
  126. * @param string $alias Alias for the length
  127. *
  128. * @return IQueryFunction
  129. * @since 24.0.0
  130. */
  131. public function charLength($field, $alias = ''): IQueryFunction;
  132. /**
  133. * Takes the maximum of all rows in a column
  134. *
  135. * If you want to get the maximum value of multiple columns in the same row, use `greatest` instead
  136. *
  137. * @param string|ILiteral|IParameter|IQueryFunction $field the column to maximum
  138. *
  139. * @return IQueryFunction
  140. * @since 18.0.0
  141. */
  142. public function max($field): IQueryFunction;
  143. /**
  144. * Takes the minimum of all rows in a column
  145. *
  146. * If you want to get the minimum value of multiple columns in the same row, use `least` instead
  147. *
  148. * @param string|ILiteral|IParameter|IQueryFunction $field the column to minimum
  149. *
  150. * @return IQueryFunction
  151. * @since 18.0.0
  152. */
  153. public function min($field): IQueryFunction;
  154. /**
  155. * Takes the maximum of multiple values
  156. *
  157. * If you want to get the maximum value of all rows in a column, use `max` instead
  158. *
  159. * @param string|ILiteral|IParameter|IQueryFunction $x
  160. * @param string|ILiteral|IParameter|IQueryFunction $y
  161. * @return IQueryFunction
  162. * @since 18.0.0
  163. */
  164. public function greatest($x, $y): IQueryFunction;
  165. /**
  166. * Takes the minimum of multiple values
  167. *
  168. * If you want to get the minimum value of all rows in a column, use `min` instead
  169. *
  170. * @param string|ILiteral|IParameter|IQueryFunction $x
  171. * @param string|ILiteral|IParameter|IQueryFunction $y
  172. * @return IQueryFunction
  173. * @since 18.0.0
  174. */
  175. public function least($x, $y): IQueryFunction;
  176. }