@@ -13,56 +13,56 @@ |
||
| 13 | 13 | trait SetFields |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - use Objects; |
|
| 16 | + use Objects; |
|
| 17 | 17 | |
| 18 | - private $setValues; |
|
| 18 | + private $setValues; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param $fieldName |
|
| 22 | - * @param $fieldValue |
|
| 23 | - * @return $this |
|
| 24 | - */ |
|
| 25 | - public function setField($fieldName, $fieldValue) |
|
| 26 | - { |
|
| 27 | - $valuePdoString = $this->queryStructure->bindParam($fieldName, $fieldValue); |
|
| 28 | - $this->queryStructure->setElement(QueryStructure::SET_FIELDS, "$fieldName = $valuePdoString"); |
|
| 20 | + /** |
|
| 21 | + * @param $fieldName |
|
| 22 | + * @param $fieldValue |
|
| 23 | + * @return $this |
|
| 24 | + */ |
|
| 25 | + public function setField($fieldName, $fieldValue) |
|
| 26 | + { |
|
| 27 | + $valuePdoString = $this->queryStructure->bindParam($fieldName, $fieldValue); |
|
| 28 | + $this->queryStructure->setElement(QueryStructure::SET_FIELDS, "$fieldName = $valuePdoString"); |
|
| 29 | 29 | |
| 30 | - return $this; |
|
| 31 | - } |
|
| 30 | + return $this; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param string $expression |
|
| 35 | - * @return $this |
|
| 36 | - */ |
|
| 37 | - public function setFieldByExpression($expression) |
|
| 38 | - { |
|
| 39 | - $this->queryStructure->setElement(QueryStructure::SET_FIELDS, $expression); |
|
| 33 | + /** |
|
| 34 | + * @param string $expression |
|
| 35 | + * @return $this |
|
| 36 | + */ |
|
| 37 | + public function setFieldByExpression($expression) |
|
| 38 | + { |
|
| 39 | + $this->queryStructure->setElement(QueryStructure::SET_FIELDS, $expression); |
|
| 40 | 40 | |
| 41 | - return $this; |
|
| 42 | - } |
|
| 41 | + return $this; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Set fields by associative array ( fieldName => fieldValue ) |
|
| 46 | - * @param array $updateFieldsArray |
|
| 47 | - * @return $this |
|
| 48 | - */ |
|
| 49 | - public function setFieldsByArray(array $updateFieldsArray) |
|
| 50 | - { |
|
| 51 | - foreach ($updateFieldsArray as $fieldName => $fieldValue) |
|
| 52 | - $this->setField($fieldName, $fieldValue); |
|
| 44 | + /** |
|
| 45 | + * Set fields by associative array ( fieldName => fieldValue ) |
|
| 46 | + * @param array $updateFieldsArray |
|
| 47 | + * @return $this |
|
| 48 | + */ |
|
| 49 | + public function setFieldsByArray(array $updateFieldsArray) |
|
| 50 | + { |
|
| 51 | + foreach ($updateFieldsArray as $fieldName => $fieldValue) |
|
| 52 | + $this->setField($fieldName, $fieldValue); |
|
| 53 | 53 | |
| 54 | - return $this; |
|
| 55 | - } |
|
| 54 | + return $this; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - private function getSettingFieldsSyntax() |
|
| 61 | - { |
|
| 62 | - if (!count($this->queryStructure->getElement(QueryStructure::SET_FIELDS))) |
|
| 63 | - return ''; |
|
| 57 | + /** |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + private function getSettingFieldsSyntax() |
|
| 61 | + { |
|
| 62 | + if (!count($this->queryStructure->getElement(QueryStructure::SET_FIELDS))) |
|
| 63 | + return ''; |
|
| 64 | 64 | |
| 65 | - return 'SET ' . implode(', ', $this->queryStructure->getElement(QueryStructure::SET_FIELDS)); |
|
| 66 | - } |
|
| 65 | + return 'SET ' . implode(', ', $this->queryStructure->getElement(QueryStructure::SET_FIELDS)); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -15,68 +15,68 @@ |
||
| 15 | 15 | trait OrderBy |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - use Objects; |
|
| 18 | + use Objects; |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param $column |
|
| 23 | - * @param array $allowedColumns |
|
| 24 | - * @return $this |
|
| 25 | - * @throws QueryException |
|
| 26 | - */ |
|
| 27 | - public function orderBy($column, array $allowedColumns = []) |
|
| 28 | - { |
|
| 29 | - $column = trim($column); |
|
| 21 | + /** |
|
| 22 | + * @param $column |
|
| 23 | + * @param array $allowedColumns |
|
| 24 | + * @return $this |
|
| 25 | + * @throws QueryException |
|
| 26 | + */ |
|
| 27 | + public function orderBy($column, array $allowedColumns = []) |
|
| 28 | + { |
|
| 29 | + $column = trim($column); |
|
| 30 | 30 | |
| 31 | - if (!$this->validateColumn($column, $allowedColumns)) |
|
| 32 | - throw new QueryException('Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 31 | + if (!$this->validateColumn($column, $allowedColumns)) |
|
| 32 | + throw new QueryException('Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 33 | 33 | |
| 34 | - $this->queryStructure->setElement(QueryStructure::ORDER_BY, $column); |
|
| 34 | + $this->queryStructure->setElement(QueryStructure::ORDER_BY, $column); |
|
| 35 | 35 | |
| 36 | - return $this; |
|
| 37 | - } |
|
| 36 | + return $this; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param $column |
|
| 42 | - * @param array $allowedColumns |
|
| 43 | - * @return $this |
|
| 44 | - * @throws QueryException |
|
| 45 | - */ |
|
| 46 | - public function orderByDesc($column, array $allowedColumns = []) |
|
| 47 | - { |
|
| 48 | - $column = trim($column); |
|
| 40 | + /** |
|
| 41 | + * @param $column |
|
| 42 | + * @param array $allowedColumns |
|
| 43 | + * @return $this |
|
| 44 | + * @throws QueryException |
|
| 45 | + */ |
|
| 46 | + public function orderByDesc($column, array $allowedColumns = []) |
|
| 47 | + { |
|
| 48 | + $column = trim($column); |
|
| 49 | 49 | |
| 50 | - if (!$this->validateColumn($column, $allowedColumns)) |
|
| 51 | - throw new QueryException('Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 50 | + if (!$this->validateColumn($column, $allowedColumns)) |
|
| 51 | + throw new QueryException('Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 52 | 52 | |
| 53 | - $this->queryStructure->setElement(QueryStructure::ORDER_BY, $column . ' DESC'); |
|
| 53 | + $this->queryStructure->setElement(QueryStructure::ORDER_BY, $column . ' DESC'); |
|
| 54 | 54 | |
| 55 | - return $this; |
|
| 56 | - } |
|
| 55 | + return $this; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param $expression |
|
| 61 | - * @return $this |
|
| 62 | - */ |
|
| 63 | - public function orderByExpression($expression) |
|
| 64 | - { |
|
| 65 | - $this->queryStructure->setElement(QueryStructure::ORDER_BY, $expression); |
|
| 59 | + /** |
|
| 60 | + * @param $expression |
|
| 61 | + * @return $this |
|
| 62 | + */ |
|
| 63 | + public function orderByExpression($expression) |
|
| 64 | + { |
|
| 65 | + $this->queryStructure->setElement(QueryStructure::ORDER_BY, $expression); |
|
| 66 | 66 | |
| 67 | - return $this; |
|
| 68 | - } |
|
| 67 | + return $this; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - private function getOrderBySyntax() |
|
| 75 | - { |
|
| 76 | - if (count($this->queryStructure->getElement(QueryStructure::ORDER_BY))) |
|
| 77 | - return 'ORDER BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::ORDER_BY), ', '); |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + private function getOrderBySyntax() |
|
| 75 | + { |
|
| 76 | + if (count($this->queryStructure->getElement(QueryStructure::ORDER_BY))) |
|
| 77 | + return 'ORDER BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::ORDER_BY), ', '); |
|
| 78 | 78 | |
| 79 | - return ''; |
|
| 80 | - } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -14,125 +14,125 @@ |
||
| 14 | 14 | trait Join |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - use Objects; |
|
| 18 | - |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @param $tableJoin |
|
| 22 | - * @param $onLeft |
|
| 23 | - * @param null $onRight |
|
| 24 | - * @return $this |
|
| 25 | - */ |
|
| 26 | - public function innerJoin($tableJoin, $onLeft, $onRight = null) |
|
| 27 | - { |
|
| 28 | - return $this->makeJoin('INNER JOIN', $tableJoin, $onLeft, $onRight); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @param $tableJoin |
|
| 33 | - * @param $onLeft |
|
| 34 | - * @param null $onRight |
|
| 35 | - * @return $this |
|
| 36 | - */ |
|
| 37 | - public function leftJoin($tableJoin, $onLeft, $onRight = null) |
|
| 38 | - { |
|
| 39 | - return $this->makeJoin('LEFT JOIN', $tableJoin, $onLeft, $onRight); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param $tableJoin |
|
| 44 | - * @param $onLeft |
|
| 45 | - * @param null $onRight |
|
| 46 | - * @return $this |
|
| 47 | - */ |
|
| 48 | - public function leftOuterJoin($tableJoin, $onLeft, $onRight = null) |
|
| 49 | - { |
|
| 50 | - return $this->makeJoin('LEFT OUTER JOIN', $tableJoin, $onLeft, $onRight); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param $tableJoin |
|
| 55 | - * @param $onLeft |
|
| 56 | - * @param null $onRight |
|
| 57 | - * @return $this |
|
| 58 | - */ |
|
| 59 | - public function rightJoin($tableJoin, $onLeft, $onRight = null) |
|
| 60 | - { |
|
| 61 | - return $this->makeJoin('RIGHT JOIN', $tableJoin, $onLeft, $onRight); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param $tableJoin |
|
| 66 | - * @param $onLeft |
|
| 67 | - * @param null $onRight |
|
| 68 | - * @return $this |
|
| 69 | - */ |
|
| 70 | - public function rightOuterJoin($tableJoin, $onLeft, $onRight = null) |
|
| 71 | - { |
|
| 72 | - return $this->makeJoin('RIGHT OUTER JOIN', $tableJoin, $onLeft, $onRight); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param $tableJoin |
|
| 77 | - * @param $onLeft |
|
| 78 | - * @param null $onRight |
|
| 79 | - * @return $this |
|
| 80 | - */ |
|
| 81 | - public function fullJoin($tableJoin, $onLeft, $onRight = null) |
|
| 82 | - { |
|
| 83 | - return $this->makeJoin('FULL JOIN', $tableJoin, $onLeft, $onRight); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param $tableJoin |
|
| 88 | - * @param $onLeft |
|
| 89 | - * @param null $onRight |
|
| 90 | - * @return $this |
|
| 91 | - */ |
|
| 92 | - public function fullOuterJoin($tableJoin, $onLeft, $onRight = null) |
|
| 93 | - { |
|
| 94 | - return $this->makeJoin('FULL OUTER JOIN', $tableJoin, $onLeft, $onRight); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param $stringJoin |
|
| 99 | - * @return $this |
|
| 100 | - */ |
|
| 101 | - public function join($stringJoin) |
|
| 102 | - { |
|
| 103 | - $this->queryStructure->setElement(QueryStructure::JOIN, $stringJoin); |
|
| 104 | - |
|
| 105 | - return $this; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param $typeJoin |
|
| 110 | - * @param $tableJoin |
|
| 111 | - * @param $onLeft |
|
| 112 | - * @param null $onRight |
|
| 113 | - * @return $this |
|
| 114 | - */ |
|
| 115 | - private function makeJoin($typeJoin, $tableJoin, $onLeft, $onRight = null) |
|
| 116 | - { |
|
| 117 | - $join = $typeJoin . ' ' . $tableJoin; |
|
| 118 | - |
|
| 119 | - if (is_null($onRight)) |
|
| 120 | - $join .= " USING ( $onLeft )"; else |
|
| 121 | - $join .= " ON $onLeft = $onRight"; |
|
| 122 | - |
|
| 123 | - $this->queryStructure->setElement(QueryStructure::JOIN, $join); |
|
| 124 | - |
|
| 125 | - return $this; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - private function getJoinSyntax() |
|
| 132 | - { |
|
| 133 | - $joinString = implode(' ', $this->queryStructure->getElement(QueryStructure::JOIN)); |
|
| 134 | - |
|
| 135 | - return QueryHelper::clearMultipleSpaces($joinString); |
|
| 136 | - } |
|
| 17 | + use Objects; |
|
| 18 | + |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @param $tableJoin |
|
| 22 | + * @param $onLeft |
|
| 23 | + * @param null $onRight |
|
| 24 | + * @return $this |
|
| 25 | + */ |
|
| 26 | + public function innerJoin($tableJoin, $onLeft, $onRight = null) |
|
| 27 | + { |
|
| 28 | + return $this->makeJoin('INNER JOIN', $tableJoin, $onLeft, $onRight); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @param $tableJoin |
|
| 33 | + * @param $onLeft |
|
| 34 | + * @param null $onRight |
|
| 35 | + * @return $this |
|
| 36 | + */ |
|
| 37 | + public function leftJoin($tableJoin, $onLeft, $onRight = null) |
|
| 38 | + { |
|
| 39 | + return $this->makeJoin('LEFT JOIN', $tableJoin, $onLeft, $onRight); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param $tableJoin |
|
| 44 | + * @param $onLeft |
|
| 45 | + * @param null $onRight |
|
| 46 | + * @return $this |
|
| 47 | + */ |
|
| 48 | + public function leftOuterJoin($tableJoin, $onLeft, $onRight = null) |
|
| 49 | + { |
|
| 50 | + return $this->makeJoin('LEFT OUTER JOIN', $tableJoin, $onLeft, $onRight); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param $tableJoin |
|
| 55 | + * @param $onLeft |
|
| 56 | + * @param null $onRight |
|
| 57 | + * @return $this |
|
| 58 | + */ |
|
| 59 | + public function rightJoin($tableJoin, $onLeft, $onRight = null) |
|
| 60 | + { |
|
| 61 | + return $this->makeJoin('RIGHT JOIN', $tableJoin, $onLeft, $onRight); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param $tableJoin |
|
| 66 | + * @param $onLeft |
|
| 67 | + * @param null $onRight |
|
| 68 | + * @return $this |
|
| 69 | + */ |
|
| 70 | + public function rightOuterJoin($tableJoin, $onLeft, $onRight = null) |
|
| 71 | + { |
|
| 72 | + return $this->makeJoin('RIGHT OUTER JOIN', $tableJoin, $onLeft, $onRight); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param $tableJoin |
|
| 77 | + * @param $onLeft |
|
| 78 | + * @param null $onRight |
|
| 79 | + * @return $this |
|
| 80 | + */ |
|
| 81 | + public function fullJoin($tableJoin, $onLeft, $onRight = null) |
|
| 82 | + { |
|
| 83 | + return $this->makeJoin('FULL JOIN', $tableJoin, $onLeft, $onRight); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param $tableJoin |
|
| 88 | + * @param $onLeft |
|
| 89 | + * @param null $onRight |
|
| 90 | + * @return $this |
|
| 91 | + */ |
|
| 92 | + public function fullOuterJoin($tableJoin, $onLeft, $onRight = null) |
|
| 93 | + { |
|
| 94 | + return $this->makeJoin('FULL OUTER JOIN', $tableJoin, $onLeft, $onRight); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param $stringJoin |
|
| 99 | + * @return $this |
|
| 100 | + */ |
|
| 101 | + public function join($stringJoin) |
|
| 102 | + { |
|
| 103 | + $this->queryStructure->setElement(QueryStructure::JOIN, $stringJoin); |
|
| 104 | + |
|
| 105 | + return $this; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param $typeJoin |
|
| 110 | + * @param $tableJoin |
|
| 111 | + * @param $onLeft |
|
| 112 | + * @param null $onRight |
|
| 113 | + * @return $this |
|
| 114 | + */ |
|
| 115 | + private function makeJoin($typeJoin, $tableJoin, $onLeft, $onRight = null) |
|
| 116 | + { |
|
| 117 | + $join = $typeJoin . ' ' . $tableJoin; |
|
| 118 | + |
|
| 119 | + if (is_null($onRight)) |
|
| 120 | + $join .= " USING ( $onLeft )"; else |
|
| 121 | + $join .= " ON $onLeft = $onRight"; |
|
| 122 | + |
|
| 123 | + $this->queryStructure->setElement(QueryStructure::JOIN, $join); |
|
| 124 | + |
|
| 125 | + return $this; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + private function getJoinSyntax() |
|
| 132 | + { |
|
| 133 | + $joinString = implode(' ', $this->queryStructure->getElement(QueryStructure::JOIN)); |
|
| 134 | + |
|
| 135 | + return QueryHelper::clearMultipleSpaces($joinString); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | } |
| 139 | 139 | \ No newline at end of file |
@@ -18,52 +18,52 @@ |
||
| 18 | 18 | trait TableValidation |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - private function validateTable($table) |
|
| 22 | - { |
|
| 23 | - switch (gettype($table)) { |
|
| 24 | - |
|
| 25 | - case QueryStructure::ELEMENT_TYPE_STRING: |
|
| 26 | - $table = $this->validateTableName($table); |
|
| 27 | - break; |
|
| 28 | - case QueryStructure::ELEMENT_TYPE_OBJECT: |
|
| 29 | - $table = $this->validateTableSubQuery($table); |
|
| 30 | - break; |
|
| 31 | - default: |
|
| 32 | - throw new QueryException('Invalid table type parameter: ' . gettype($table), QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT); |
|
| 33 | - |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - return $table; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param $table |
|
| 41 | - * @return mixed|string |
|
| 42 | - * @throws QueryException |
|
| 43 | - */ |
|
| 44 | - private function validateTableName($table) |
|
| 45 | - { |
|
| 46 | - $table = trim($table); |
|
| 47 | - |
|
| 48 | - if ('' === $table) |
|
| 49 | - throw new QueryException('Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT); |
|
| 50 | - |
|
| 51 | - if (DbConfig::getInstance()->useTablePrefix()) |
|
| 52 | - $table = str_ireplace('::', DbConfig::getInstance()->getTablePrefix(), $table); |
|
| 53 | - |
|
| 54 | - return $table; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - private function validateTableSubQuery($table) |
|
| 58 | - { |
|
| 59 | - if ($this->statement !== QueryStatement::QUERY_STATEMENT_SELECT) |
|
| 60 | - throw new QueryException('Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT); |
|
| 61 | - |
|
| 62 | - if (!is_a($table, QuerySelect::class)) |
|
| 63 | - throw new QueryException('Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT); |
|
| 64 | - |
|
| 65 | - return $table; |
|
| 66 | - } |
|
| 21 | + private function validateTable($table) |
|
| 22 | + { |
|
| 23 | + switch (gettype($table)) { |
|
| 24 | + |
|
| 25 | + case QueryStructure::ELEMENT_TYPE_STRING: |
|
| 26 | + $table = $this->validateTableName($table); |
|
| 27 | + break; |
|
| 28 | + case QueryStructure::ELEMENT_TYPE_OBJECT: |
|
| 29 | + $table = $this->validateTableSubQuery($table); |
|
| 30 | + break; |
|
| 31 | + default: |
|
| 32 | + throw new QueryException('Invalid table type parameter: ' . gettype($table), QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT); |
|
| 33 | + |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + return $table; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param $table |
|
| 41 | + * @return mixed|string |
|
| 42 | + * @throws QueryException |
|
| 43 | + */ |
|
| 44 | + private function validateTableName($table) |
|
| 45 | + { |
|
| 46 | + $table = trim($table); |
|
| 47 | + |
|
| 48 | + if ('' === $table) |
|
| 49 | + throw new QueryException('Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT); |
|
| 50 | + |
|
| 51 | + if (DbConfig::getInstance()->useTablePrefix()) |
|
| 52 | + $table = str_ireplace('::', DbConfig::getInstance()->getTablePrefix(), $table); |
|
| 53 | + |
|
| 54 | + return $table; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + private function validateTableSubQuery($table) |
|
| 58 | + { |
|
| 59 | + if ($this->statement !== QueryStatement::QUERY_STATEMENT_SELECT) |
|
| 60 | + throw new QueryException('Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT); |
|
| 61 | + |
|
| 62 | + if (!is_a($table, QuerySelect::class)) |
|
| 63 | + throw new QueryException('Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT); |
|
| 64 | + |
|
| 65 | + return $table; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | } |
| 70 | 70 | \ No newline at end of file |
@@ -13,349 +13,349 @@ |
||
| 13 | 13 | trait Where |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - use Objects; |
|
| 17 | - |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @param $field |
|
| 21 | - * @param $value |
|
| 22 | - * @param $glue |
|
| 23 | - * @return $this |
|
| 24 | - */ |
|
| 25 | - public function whereEqual($field, $value, $glue = 'AND') |
|
| 26 | - { |
|
| 27 | - return $this->where(array($field, $value, '='), $glue); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param $field |
|
| 32 | - * @param $value |
|
| 33 | - * @return $this |
|
| 34 | - */ |
|
| 35 | - public function orWhereEqual($field, $value) |
|
| 36 | - { |
|
| 37 | - return $this->where(array($field, $value, '='), 'OR'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param $field |
|
| 42 | - * @param $value |
|
| 43 | - * @param string $glue |
|
| 44 | - * @return $this |
|
| 45 | - */ |
|
| 46 | - public function whereNotEqual($field, $value, $glue = 'AND') |
|
| 47 | - { |
|
| 48 | - return $this->where(array($field, $value, '<>'), $glue); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @param $field |
|
| 53 | - * @param $value |
|
| 54 | - * @return $this |
|
| 55 | - */ |
|
| 56 | - public function orWhereNotEqual($field, $value) |
|
| 57 | - { |
|
| 58 | - return $this->where(array($field, $value, '<>'), 'OR'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param $field |
|
| 63 | - * @param $value |
|
| 64 | - * @param string $glue |
|
| 65 | - * @return $this |
|
| 66 | - */ |
|
| 67 | - public function whereLessThan($field, $value, $glue = 'AND') |
|
| 68 | - { |
|
| 69 | - return $this->where(array($field, $value, '<'), $glue); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param $field |
|
| 74 | - * @param $value |
|
| 75 | - * @return $this |
|
| 76 | - */ |
|
| 77 | - public function orWhereLessThan($field, $value) |
|
| 78 | - { |
|
| 79 | - return $this->where(array($field, $value, '<'), 'OR'); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param $field |
|
| 84 | - * @param $value |
|
| 85 | - * @param string $glue |
|
| 86 | - * @return $this |
|
| 87 | - */ |
|
| 88 | - public function whereLessThanOrEqual($field, $value, $glue = 'AND') |
|
| 89 | - { |
|
| 90 | - return $this->where(array($field, $value, '<='), $glue); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param $field |
|
| 95 | - * @param $value |
|
| 96 | - * @return $this |
|
| 97 | - */ |
|
| 98 | - public function orWhereLessThanOrEqual($field, $value) |
|
| 99 | - { |
|
| 100 | - return $this->where(array($field, $value, '<='), 'OR'); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param $field |
|
| 105 | - * @param $value |
|
| 106 | - * @param string $glue |
|
| 107 | - * @return $this |
|
| 108 | - */ |
|
| 109 | - public function whereGreaterThan($field, $value, $glue = 'AND') |
|
| 110 | - { |
|
| 111 | - return $this->where(array($field, $value, '>'), $glue); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param $field |
|
| 116 | - * @param $value |
|
| 117 | - * @return $this |
|
| 118 | - */ |
|
| 119 | - public function orWhereGreaterThan($field, $value) |
|
| 120 | - { |
|
| 121 | - return $this->where(array($field, $value, '>'), 'OR'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param $field |
|
| 126 | - * @param $value |
|
| 127 | - * @param string $glue |
|
| 128 | - * @return $this |
|
| 129 | - */ |
|
| 130 | - public function whereGreaterThanOrEqual($field, $value, $glue = 'AND') |
|
| 131 | - { |
|
| 132 | - return $this->where(array($field, $value, '>='), $glue); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @param $field |
|
| 137 | - * @param $value |
|
| 138 | - * @return $this |
|
| 139 | - */ |
|
| 140 | - public function orWhereGreaterThanOrEqual($field, $value) |
|
| 141 | - { |
|
| 142 | - return $this->where(array($field, $value, '>='), 'OR'); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param $field |
|
| 147 | - * @param $value |
|
| 148 | - * @param string $glue |
|
| 149 | - * @return $this |
|
| 150 | - */ |
|
| 151 | - public function whereLike($field, $value, $glue = 'AND') |
|
| 152 | - { |
|
| 153 | - return $this->where(array($field, $value, 'LIKE'), $glue); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @param $field |
|
| 158 | - * @param $value |
|
| 159 | - * @return $this |
|
| 160 | - */ |
|
| 161 | - public function orWhereLike($field, $value) |
|
| 162 | - { |
|
| 163 | - return $this->where(array($field, $value, 'LIKE'), 'OR'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param $field |
|
| 168 | - * @param $value |
|
| 169 | - * @param string $glue |
|
| 170 | - * @return $this |
|
| 171 | - */ |
|
| 172 | - public function whereNotLike($field, $value, $glue = 'AND') |
|
| 173 | - { |
|
| 174 | - return $this->where(array($field, $value, 'NOT LIKE'), $glue); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param $field |
|
| 179 | - * @param $value |
|
| 180 | - * @return $this |
|
| 181 | - */ |
|
| 182 | - public function orWhereNotLike($field, $value) |
|
| 183 | - { |
|
| 184 | - return $this->where(array($field, $value, 'NOT LIKE'), 'OR'); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @param $field |
|
| 189 | - * @param $min |
|
| 190 | - * @param $max |
|
| 191 | - * @param string $glue |
|
| 192 | - * @return $this |
|
| 193 | - */ |
|
| 194 | - public function whereBetween($field, $min, $max, $glue = 'AND') |
|
| 195 | - { |
|
| 196 | - return $this->where(array($field, array($min, $max), 'BETWEEN'), $glue); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param $field |
|
| 201 | - * @param $min |
|
| 202 | - * @param $max |
|
| 203 | - * @return $this |
|
| 204 | - */ |
|
| 205 | - public function orWhereBetween($field, $min, $max) |
|
| 206 | - { |
|
| 207 | - return $this->where(array($field, array($min, $max), 'BETWEEN'), 'OR'); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param $field |
|
| 212 | - * @param $min |
|
| 213 | - * @param $max |
|
| 214 | - * @param string $glue |
|
| 215 | - * @return $this |
|
| 216 | - */ |
|
| 217 | - public function whereNotBetween($field, $min, $max, $glue = 'AND') |
|
| 218 | - { |
|
| 219 | - return $this->where(array($field, array($min, $max), 'NOT BETWEEN'), $glue); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @param $field |
|
| 224 | - * @param $min |
|
| 225 | - * @param $max |
|
| 226 | - * @return $this |
|
| 227 | - */ |
|
| 228 | - public function orWhereNotBetween($field, $min, $max) |
|
| 229 | - { |
|
| 230 | - return $this->where(array($field, array($min, $max), 'NOT BETWEEN'), 'OR'); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @param $field |
|
| 235 | - * @param $value |
|
| 236 | - * @param string $glue |
|
| 237 | - * @return $this |
|
| 238 | - */ |
|
| 239 | - public function whereIn($field, $value, $glue = 'AND') |
|
| 240 | - { |
|
| 241 | - return $this->where(array($field, $value, 'IN'), $glue); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @param $field |
|
| 246 | - * @param $value |
|
| 247 | - * @return $this |
|
| 248 | - */ |
|
| 249 | - public function orWhereIn($field, $value) |
|
| 250 | - { |
|
| 251 | - return $this->where(array($field, $value, 'IN'), 'OR'); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param $field |
|
| 256 | - * @param $value |
|
| 257 | - * @param string $glue |
|
| 258 | - * @return $this |
|
| 259 | - */ |
|
| 260 | - public function whereNotIn($field, $value, $glue = 'AND') |
|
| 261 | - { |
|
| 262 | - return $this->where(array($field, $value, 'NOT IN'), $glue); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @param $field |
|
| 267 | - * @param $value |
|
| 268 | - * @return $this |
|
| 269 | - */ |
|
| 270 | - public function orWhereNotIn($field, $value) |
|
| 271 | - { |
|
| 272 | - return $this->where(array($field, $value, 'NOT IN'), 'OR'); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @param $whereString |
|
| 277 | - * @param array $bindParams |
|
| 278 | - * @param string $glue |
|
| 279 | - * @return $this |
|
| 280 | - */ |
|
| 281 | - public function whereExpression($whereString, array $bindParams = [], $glue = 'AND') |
|
| 282 | - { |
|
| 283 | - $whereString = $this->queryStructure->bindParamsExpression($whereString, $bindParams); |
|
| 284 | - |
|
| 285 | - return $this->where($whereString, $glue); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @param $whereString |
|
| 290 | - * @param array $bindParams |
|
| 291 | - * @return $this |
|
| 292 | - */ |
|
| 293 | - public function orWhereExpression($whereString, array $bindParams = []) |
|
| 294 | - { |
|
| 295 | - $whereString = $this->queryStructure->bindParamsExpression($whereString, $bindParams); |
|
| 296 | - |
|
| 297 | - return $this->where($whereString, 'OR'); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @return $this |
|
| 302 | - */ |
|
| 303 | - public function whereInvertResult() |
|
| 304 | - { |
|
| 305 | - $this->queryStructure->setElement(QueryStructure::WHERE_INVERT, 1); |
|
| 306 | - |
|
| 307 | - return $this; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @param string $glue |
|
| 312 | - * @return $this |
|
| 313 | - */ |
|
| 314 | - public function whereGroup($glue = 'AND') |
|
| 315 | - { |
|
| 316 | - $this->queryStructure->setElement(QueryStructure::WHERE, array('glue' => $glue, 'body' => '(', 'type' => 'start_where_group')); |
|
| 317 | - |
|
| 318 | - return $this; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * @return $this |
|
| 323 | - */ |
|
| 324 | - public function orWhereGroup() |
|
| 325 | - { |
|
| 326 | - return $this->whereGroup('OR'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * @return $this |
|
| 331 | - */ |
|
| 332 | - public function whereGroupEnd() |
|
| 333 | - { |
|
| 334 | - $this->queryStructure->setElement(QueryStructure::WHERE, array('glue' => '', 'body' => ')', 'type' => 'end_where_group')); |
|
| 335 | - |
|
| 336 | - return $this; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @return $this |
|
| 341 | - */ |
|
| 342 | - public function ignoreWhereTrigger() |
|
| 343 | - { |
|
| 344 | - $this->queryStructure->setElement(QueryStructure::WHERE_TRIGGER, 0); |
|
| 345 | - |
|
| 346 | - return $this; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @param string|array $param |
|
| 352 | - * @param string $glue |
|
| 353 | - * @return $this |
|
| 354 | - */ |
|
| 355 | - private function where($param, $glue = 'AND') |
|
| 356 | - { |
|
| 357 | - return $this->/** @scrutinizer ignore-call */ |
|
| 358 | - createCondition($param, $glue, QueryStructure::WHERE); |
|
| 359 | - } |
|
| 16 | + use Objects; |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @param $field |
|
| 21 | + * @param $value |
|
| 22 | + * @param $glue |
|
| 23 | + * @return $this |
|
| 24 | + */ |
|
| 25 | + public function whereEqual($field, $value, $glue = 'AND') |
|
| 26 | + { |
|
| 27 | + return $this->where(array($field, $value, '='), $glue); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param $field |
|
| 32 | + * @param $value |
|
| 33 | + * @return $this |
|
| 34 | + */ |
|
| 35 | + public function orWhereEqual($field, $value) |
|
| 36 | + { |
|
| 37 | + return $this->where(array($field, $value, '='), 'OR'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param $field |
|
| 42 | + * @param $value |
|
| 43 | + * @param string $glue |
|
| 44 | + * @return $this |
|
| 45 | + */ |
|
| 46 | + public function whereNotEqual($field, $value, $glue = 'AND') |
|
| 47 | + { |
|
| 48 | + return $this->where(array($field, $value, '<>'), $glue); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @param $field |
|
| 53 | + * @param $value |
|
| 54 | + * @return $this |
|
| 55 | + */ |
|
| 56 | + public function orWhereNotEqual($field, $value) |
|
| 57 | + { |
|
| 58 | + return $this->where(array($field, $value, '<>'), 'OR'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param $field |
|
| 63 | + * @param $value |
|
| 64 | + * @param string $glue |
|
| 65 | + * @return $this |
|
| 66 | + */ |
|
| 67 | + public function whereLessThan($field, $value, $glue = 'AND') |
|
| 68 | + { |
|
| 69 | + return $this->where(array($field, $value, '<'), $glue); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param $field |
|
| 74 | + * @param $value |
|
| 75 | + * @return $this |
|
| 76 | + */ |
|
| 77 | + public function orWhereLessThan($field, $value) |
|
| 78 | + { |
|
| 79 | + return $this->where(array($field, $value, '<'), 'OR'); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param $field |
|
| 84 | + * @param $value |
|
| 85 | + * @param string $glue |
|
| 86 | + * @return $this |
|
| 87 | + */ |
|
| 88 | + public function whereLessThanOrEqual($field, $value, $glue = 'AND') |
|
| 89 | + { |
|
| 90 | + return $this->where(array($field, $value, '<='), $glue); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param $field |
|
| 95 | + * @param $value |
|
| 96 | + * @return $this |
|
| 97 | + */ |
|
| 98 | + public function orWhereLessThanOrEqual($field, $value) |
|
| 99 | + { |
|
| 100 | + return $this->where(array($field, $value, '<='), 'OR'); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param $field |
|
| 105 | + * @param $value |
|
| 106 | + * @param string $glue |
|
| 107 | + * @return $this |
|
| 108 | + */ |
|
| 109 | + public function whereGreaterThan($field, $value, $glue = 'AND') |
|
| 110 | + { |
|
| 111 | + return $this->where(array($field, $value, '>'), $glue); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param $field |
|
| 116 | + * @param $value |
|
| 117 | + * @return $this |
|
| 118 | + */ |
|
| 119 | + public function orWhereGreaterThan($field, $value) |
|
| 120 | + { |
|
| 121 | + return $this->where(array($field, $value, '>'), 'OR'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param $field |
|
| 126 | + * @param $value |
|
| 127 | + * @param string $glue |
|
| 128 | + * @return $this |
|
| 129 | + */ |
|
| 130 | + public function whereGreaterThanOrEqual($field, $value, $glue = 'AND') |
|
| 131 | + { |
|
| 132 | + return $this->where(array($field, $value, '>='), $glue); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @param $field |
|
| 137 | + * @param $value |
|
| 138 | + * @return $this |
|
| 139 | + */ |
|
| 140 | + public function orWhereGreaterThanOrEqual($field, $value) |
|
| 141 | + { |
|
| 142 | + return $this->where(array($field, $value, '>='), 'OR'); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param $field |
|
| 147 | + * @param $value |
|
| 148 | + * @param string $glue |
|
| 149 | + * @return $this |
|
| 150 | + */ |
|
| 151 | + public function whereLike($field, $value, $glue = 'AND') |
|
| 152 | + { |
|
| 153 | + return $this->where(array($field, $value, 'LIKE'), $glue); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @param $field |
|
| 158 | + * @param $value |
|
| 159 | + * @return $this |
|
| 160 | + */ |
|
| 161 | + public function orWhereLike($field, $value) |
|
| 162 | + { |
|
| 163 | + return $this->where(array($field, $value, 'LIKE'), 'OR'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param $field |
|
| 168 | + * @param $value |
|
| 169 | + * @param string $glue |
|
| 170 | + * @return $this |
|
| 171 | + */ |
|
| 172 | + public function whereNotLike($field, $value, $glue = 'AND') |
|
| 173 | + { |
|
| 174 | + return $this->where(array($field, $value, 'NOT LIKE'), $glue); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param $field |
|
| 179 | + * @param $value |
|
| 180 | + * @return $this |
|
| 181 | + */ |
|
| 182 | + public function orWhereNotLike($field, $value) |
|
| 183 | + { |
|
| 184 | + return $this->where(array($field, $value, 'NOT LIKE'), 'OR'); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @param $field |
|
| 189 | + * @param $min |
|
| 190 | + * @param $max |
|
| 191 | + * @param string $glue |
|
| 192 | + * @return $this |
|
| 193 | + */ |
|
| 194 | + public function whereBetween($field, $min, $max, $glue = 'AND') |
|
| 195 | + { |
|
| 196 | + return $this->where(array($field, array($min, $max), 'BETWEEN'), $glue); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param $field |
|
| 201 | + * @param $min |
|
| 202 | + * @param $max |
|
| 203 | + * @return $this |
|
| 204 | + */ |
|
| 205 | + public function orWhereBetween($field, $min, $max) |
|
| 206 | + { |
|
| 207 | + return $this->where(array($field, array($min, $max), 'BETWEEN'), 'OR'); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param $field |
|
| 212 | + * @param $min |
|
| 213 | + * @param $max |
|
| 214 | + * @param string $glue |
|
| 215 | + * @return $this |
|
| 216 | + */ |
|
| 217 | + public function whereNotBetween($field, $min, $max, $glue = 'AND') |
|
| 218 | + { |
|
| 219 | + return $this->where(array($field, array($min, $max), 'NOT BETWEEN'), $glue); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @param $field |
|
| 224 | + * @param $min |
|
| 225 | + * @param $max |
|
| 226 | + * @return $this |
|
| 227 | + */ |
|
| 228 | + public function orWhereNotBetween($field, $min, $max) |
|
| 229 | + { |
|
| 230 | + return $this->where(array($field, array($min, $max), 'NOT BETWEEN'), 'OR'); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @param $field |
|
| 235 | + * @param $value |
|
| 236 | + * @param string $glue |
|
| 237 | + * @return $this |
|
| 238 | + */ |
|
| 239 | + public function whereIn($field, $value, $glue = 'AND') |
|
| 240 | + { |
|
| 241 | + return $this->where(array($field, $value, 'IN'), $glue); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @param $field |
|
| 246 | + * @param $value |
|
| 247 | + * @return $this |
|
| 248 | + */ |
|
| 249 | + public function orWhereIn($field, $value) |
|
| 250 | + { |
|
| 251 | + return $this->where(array($field, $value, 'IN'), 'OR'); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param $field |
|
| 256 | + * @param $value |
|
| 257 | + * @param string $glue |
|
| 258 | + * @return $this |
|
| 259 | + */ |
|
| 260 | + public function whereNotIn($field, $value, $glue = 'AND') |
|
| 261 | + { |
|
| 262 | + return $this->where(array($field, $value, 'NOT IN'), $glue); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @param $field |
|
| 267 | + * @param $value |
|
| 268 | + * @return $this |
|
| 269 | + */ |
|
| 270 | + public function orWhereNotIn($field, $value) |
|
| 271 | + { |
|
| 272 | + return $this->where(array($field, $value, 'NOT IN'), 'OR'); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @param $whereString |
|
| 277 | + * @param array $bindParams |
|
| 278 | + * @param string $glue |
|
| 279 | + * @return $this |
|
| 280 | + */ |
|
| 281 | + public function whereExpression($whereString, array $bindParams = [], $glue = 'AND') |
|
| 282 | + { |
|
| 283 | + $whereString = $this->queryStructure->bindParamsExpression($whereString, $bindParams); |
|
| 284 | + |
|
| 285 | + return $this->where($whereString, $glue); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @param $whereString |
|
| 290 | + * @param array $bindParams |
|
| 291 | + * @return $this |
|
| 292 | + */ |
|
| 293 | + public function orWhereExpression($whereString, array $bindParams = []) |
|
| 294 | + { |
|
| 295 | + $whereString = $this->queryStructure->bindParamsExpression($whereString, $bindParams); |
|
| 296 | + |
|
| 297 | + return $this->where($whereString, 'OR'); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @return $this |
|
| 302 | + */ |
|
| 303 | + public function whereInvertResult() |
|
| 304 | + { |
|
| 305 | + $this->queryStructure->setElement(QueryStructure::WHERE_INVERT, 1); |
|
| 306 | + |
|
| 307 | + return $this; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @param string $glue |
|
| 312 | + * @return $this |
|
| 313 | + */ |
|
| 314 | + public function whereGroup($glue = 'AND') |
|
| 315 | + { |
|
| 316 | + $this->queryStructure->setElement(QueryStructure::WHERE, array('glue' => $glue, 'body' => '(', 'type' => 'start_where_group')); |
|
| 317 | + |
|
| 318 | + return $this; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * @return $this |
|
| 323 | + */ |
|
| 324 | + public function orWhereGroup() |
|
| 325 | + { |
|
| 326 | + return $this->whereGroup('OR'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * @return $this |
|
| 331 | + */ |
|
| 332 | + public function whereGroupEnd() |
|
| 333 | + { |
|
| 334 | + $this->queryStructure->setElement(QueryStructure::WHERE, array('glue' => '', 'body' => ')', 'type' => 'end_where_group')); |
|
| 335 | + |
|
| 336 | + return $this; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @return $this |
|
| 341 | + */ |
|
| 342 | + public function ignoreWhereTrigger() |
|
| 343 | + { |
|
| 344 | + $this->queryStructure->setElement(QueryStructure::WHERE_TRIGGER, 0); |
|
| 345 | + |
|
| 346 | + return $this; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @param string|array $param |
|
| 352 | + * @param string $glue |
|
| 353 | + * @return $this |
|
| 354 | + */ |
|
| 355 | + private function where($param, $glue = 'AND') |
|
| 356 | + { |
|
| 357 | + return $this->/** @scrutinizer ignore-call */ |
|
| 358 | + createCondition($param, $glue, QueryStructure::WHERE); |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | 361 | } |
| 362 | 362 | \ No newline at end of file |
@@ -15,48 +15,48 @@ |
||
| 15 | 15 | trait Limit |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - use Objects; |
|
| 18 | + use Objects; |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param int $limit |
|
| 23 | - * @param null $offset |
|
| 24 | - * @return $this |
|
| 25 | - * @throws QueryException |
|
| 26 | - */ |
|
| 27 | - public function limit($limit = 0, $offset = null) |
|
| 28 | - { |
|
| 29 | - $limit = trim($limit); |
|
| 21 | + /** |
|
| 22 | + * @param int $limit |
|
| 23 | + * @param null $offset |
|
| 24 | + * @return $this |
|
| 25 | + * @throws QueryException |
|
| 26 | + */ |
|
| 27 | + public function limit($limit = 0, $offset = null) |
|
| 28 | + { |
|
| 29 | + $limit = trim($limit); |
|
| 30 | 30 | |
| 31 | - if (!QueryHelper::isInteger($limit)) |
|
| 32 | - throw new QueryException('Invalid Limit value', QueryException::QUERY_ERROR_INVALID_LIMIT); |
|
| 31 | + if (!QueryHelper::isInteger($limit)) |
|
| 32 | + throw new QueryException('Invalid Limit value', QueryException::QUERY_ERROR_INVALID_LIMIT); |
|
| 33 | 33 | |
| 34 | - if ($limit == 0) |
|
| 35 | - throw new QueryException('Invalid Limit zero', QueryException::QUERY_ERROR_INVALID_LIMIT_ZERO); |
|
| 34 | + if ($limit == 0) |
|
| 35 | + throw new QueryException('Invalid Limit zero', QueryException::QUERY_ERROR_INVALID_LIMIT_ZERO); |
|
| 36 | 36 | |
| 37 | - if (is_null($offset)) { |
|
| 38 | - $this->queryStructure->setElement(QueryStructure::LIMIT, $limit); |
|
| 37 | + if (is_null($offset)) { |
|
| 38 | + $this->queryStructure->setElement(QueryStructure::LIMIT, $limit); |
|
| 39 | 39 | |
| 40 | - return $this; |
|
| 41 | - } |
|
| 40 | + return $this; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $offset = trim($offset); |
|
| 43 | + $offset = trim($offset); |
|
| 44 | 44 | |
| 45 | - if (!QueryHelper::isInteger($offset)) |
|
| 46 | - throw new QueryException('Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET); |
|
| 45 | + if (!QueryHelper::isInteger($offset)) |
|
| 46 | + throw new QueryException('Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET); |
|
| 47 | 47 | |
| 48 | - $this->queryStructure->setElement(QueryStructure::LIMIT, $offset . ',' . $limit); |
|
| 48 | + $this->queryStructure->setElement(QueryStructure::LIMIT, $offset . ',' . $limit); |
|
| 49 | 49 | |
| 50 | - return $this; |
|
| 51 | - } |
|
| 50 | + return $this; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - private function getLimitSyntax() |
|
| 54 | - { |
|
| 55 | - if (!$this->queryStructure->getElement(QueryStructure::LIMIT)) |
|
| 56 | - return ''; |
|
| 53 | + private function getLimitSyntax() |
|
| 54 | + { |
|
| 55 | + if (!$this->queryStructure->getElement(QueryStructure::LIMIT)) |
|
| 56 | + return ''; |
|
| 57 | 57 | |
| 58 | - return 'LIMIT ' . $this->queryStructure->getElement(QueryStructure::LIMIT); |
|
| 59 | - } |
|
| 58 | + return 'LIMIT ' . $this->queryStructure->getElement(QueryStructure::LIMIT); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | } |
| 62 | 62 | |
@@ -12,18 +12,18 @@ |
||
| 12 | 12 | trait ColumnValidation |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - use Objects; |
|
| 15 | + use Objects; |
|
| 16 | 16 | |
| 17 | - protected function validateColumn($columnName, array $allowed) |
|
| 18 | - { |
|
| 19 | - if (is_integer($columnName)) |
|
| 20 | - return true; |
|
| 17 | + protected function validateColumn($columnName, array $allowed) |
|
| 18 | + { |
|
| 19 | + if (is_integer($columnName)) |
|
| 20 | + return true; |
|
| 21 | 21 | |
| 22 | - if (!count($allowed)) |
|
| 23 | - return true; |
|
| 22 | + if (!count($allowed)) |
|
| 23 | + return true; |
|
| 24 | 24 | |
| 25 | - return false; |
|
| 26 | - } |
|
| 25 | + return false; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -13,48 +13,48 @@ |
||
| 13 | 13 | trait Utilities |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - use Objects; |
|
| 16 | + use Objects; |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return $this |
|
| 21 | - */ |
|
| 22 | - public function explain() |
|
| 23 | - { |
|
| 24 | - $this->queryStructure->setElement(QueryStructure::EXPLAIN, 1); |
|
| 19 | + /** |
|
| 20 | + * @return $this |
|
| 21 | + */ |
|
| 22 | + public function explain() |
|
| 23 | + { |
|
| 24 | + $this->queryStructure->setElement(QueryStructure::EXPLAIN, 1); |
|
| 25 | 25 | |
| 26 | - return $this; |
|
| 27 | - } |
|
| 26 | + return $this; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - protected function getExplainSyntax() |
|
| 30 | - { |
|
| 31 | - if ($this->queryStructure->getElement(QueryStructure::EXPLAIN)) |
|
| 32 | - return 'EXPLAIN'; |
|
| 29 | + protected function getExplainSyntax() |
|
| 30 | + { |
|
| 31 | + if ($this->queryStructure->getElement(QueryStructure::EXPLAIN)) |
|
| 32 | + return 'EXPLAIN'; |
|
| 33 | 33 | |
| 34 | - return ''; |
|
| 35 | - } |
|
| 34 | + return ''; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param string $comment |
|
| 40 | - * @return $this |
|
| 41 | - */ |
|
| 42 | - public function withComment($comment = '') |
|
| 43 | - { |
|
| 44 | - $this->queryStructure->setElement(QueryStructure::QUERY_COMMENT, $comment); |
|
| 38 | + /** |
|
| 39 | + * @param string $comment |
|
| 40 | + * @return $this |
|
| 41 | + */ |
|
| 42 | + public function withComment($comment = '') |
|
| 43 | + { |
|
| 44 | + $this->queryStructure->setElement(QueryStructure::QUERY_COMMENT, $comment); |
|
| 45 | 45 | |
| 46 | - return $this; |
|
| 47 | - } |
|
| 46 | + return $this; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param string $identifier |
|
| 51 | - * @return $this |
|
| 52 | - */ |
|
| 53 | - public function withLogIdentifier($identifier = null) |
|
| 54 | - { |
|
| 55 | - $this->queryStructure->setElement(QueryStructure::QUERY_IDENTIFIER, $identifier); |
|
| 49 | + /** |
|
| 50 | + * @param string $identifier |
|
| 51 | + * @return $this |
|
| 52 | + */ |
|
| 53 | + public function withLogIdentifier($identifier = null) |
|
| 54 | + { |
|
| 55 | + $this->queryStructure->setElement(QueryStructure::QUERY_IDENTIFIER, $identifier); |
|
| 56 | 56 | |
| 57 | - return $this; |
|
| 58 | - } |
|
| 57 | + return $this; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | \ No newline at end of file |
@@ -14,17 +14,17 @@ |
||
| 14 | 14 | trait Ignore |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - use Objects; |
|
| 17 | + use Objects; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return $this |
|
| 21 | - */ |
|
| 22 | - public function ignore() |
|
| 23 | - { |
|
| 24 | - $this->queryStructure->setElement(QueryStructure::IGNORE, 1); |
|
| 19 | + /** |
|
| 20 | + * @return $this |
|
| 21 | + */ |
|
| 22 | + public function ignore() |
|
| 23 | + { |
|
| 24 | + $this->queryStructure->setElement(QueryStructure::IGNORE, 1); |
|
| 25 | 25 | |
| 26 | - return $this; |
|
| 27 | - } |
|
| 26 | + return $this; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |