@@ -17,110 +17,110 @@ |
||
| 17 | 17 | trait InsertMultiple |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - use Objects; |
|
| 20 | + use Objects; |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param $fieldsList |
|
| 25 | - * @param array $rowsForInsert |
|
| 26 | - * @return $this |
|
| 27 | - */ |
|
| 28 | - public function fromArray($fieldsList, array $rowsForInsert) |
|
| 29 | - { |
|
| 30 | - $this->setFieldsList($fieldsList); |
|
| 23 | + /** |
|
| 24 | + * @param $fieldsList |
|
| 25 | + * @param array $rowsForInsert |
|
| 26 | + * @return $this |
|
| 27 | + */ |
|
| 28 | + public function fromArray($fieldsList, array $rowsForInsert) |
|
| 29 | + { |
|
| 30 | + $this->setFieldsList($fieldsList); |
|
| 31 | 31 | |
| 32 | - foreach ($rowsForInsert as $row) |
|
| 33 | - $this->addSingleRow($row); |
|
| 32 | + foreach ($rowsForInsert as $row) |
|
| 33 | + $this->addSingleRow($row); |
|
| 34 | 34 | |
| 35 | - return $this; |
|
| 36 | - } |
|
| 35 | + return $this; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param $fieldsList |
|
| 41 | - * @param QuerySelect $query |
|
| 42 | - * @return $this |
|
| 43 | - */ |
|
| 44 | - public function fromQuerySelect($fieldsList, QuerySelect $query) |
|
| 45 | - { |
|
| 46 | - $this->setFieldsList($fieldsList); |
|
| 39 | + /** |
|
| 40 | + * @param $fieldsList |
|
| 41 | + * @param QuerySelect $query |
|
| 42 | + * @return $this |
|
| 43 | + */ |
|
| 44 | + public function fromQuerySelect($fieldsList, QuerySelect $query) |
|
| 45 | + { |
|
| 46 | + $this->setFieldsList($fieldsList); |
|
| 47 | 47 | |
| 48 | - foreach ($query->getBindParams() as $key => $value) |
|
| 49 | - $this->queryStructure->setParams($key, $value); |
|
| 48 | + foreach ($query->getBindParams() as $key => $value) |
|
| 49 | + $this->queryStructure->setParams($key, $value); |
|
| 50 | 50 | |
| 51 | - $this->queryStructure->replaceElement(QueryStructure::SET_FIELDS, $query); |
|
| 51 | + $this->queryStructure->replaceElement(QueryStructure::SET_FIELDS, $query); |
|
| 52 | 52 | |
| 53 | - return $this; |
|
| 54 | - } |
|
| 53 | + return $this; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param string|array $fieldList |
|
| 59 | - */ |
|
| 60 | - private function setFieldsList($fieldList) |
|
| 61 | - { |
|
| 62 | - if (!is_array($fieldList)) |
|
| 63 | - $fieldList = QueryHelper::explode($fieldList); |
|
| 57 | + /** |
|
| 58 | + * @param string|array $fieldList |
|
| 59 | + */ |
|
| 60 | + private function setFieldsList($fieldList) |
|
| 61 | + { |
|
| 62 | + if (!is_array($fieldList)) |
|
| 63 | + $fieldList = QueryHelper::explode($fieldList); |
|
| 64 | 64 | |
| 65 | - $this->queryStructure->replaceElement(QueryStructure::FIELDS, $fieldList); |
|
| 65 | + $this->queryStructure->replaceElement(QueryStructure::FIELDS, $fieldList); |
|
| 66 | 66 | |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param array $rowValues |
|
| 71 | - * @return $this |
|
| 72 | - * @throws QueryException |
|
| 73 | - */ |
|
| 74 | - private function addSingleRow(array $rowValues) |
|
| 75 | - { |
|
| 69 | + /** |
|
| 70 | + * @param array $rowValues |
|
| 71 | + * @return $this |
|
| 72 | + * @throws QueryException |
|
| 73 | + */ |
|
| 74 | + private function addSingleRow(array $rowValues) |
|
| 75 | + { |
|
| 76 | 76 | |
| 77 | - if ($this->getNumberOfFields() !== count($rowValues)) |
|
| 78 | - throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT); |
|
| 77 | + if ($this->getNumberOfFields() !== count($rowValues)) |
|
| 78 | + throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT); |
|
| 79 | 79 | |
| 80 | - $pdoRowValues = array(); |
|
| 80 | + $pdoRowValues = array(); |
|
| 81 | 81 | |
| 82 | - foreach ($rowValues as $value) |
|
| 83 | - $pdoRowValues[] = $this->queryStructure->bindParam('value', $value); |
|
| 82 | + foreach ($rowValues as $value) |
|
| 83 | + $pdoRowValues[] = $this->queryStructure->bindParam('value', $value); |
|
| 84 | 84 | |
| 85 | - $pdoRowValuesString = '( ' . QueryHelper::implode($pdoRowValues, ', ') . ' )'; |
|
| 85 | + $pdoRowValuesString = '( ' . QueryHelper::implode($pdoRowValues, ', ') . ' )'; |
|
| 86 | 86 | |
| 87 | - $this->queryStructure->setElement(QueryStructure::SET_FIELDS, $pdoRowValuesString); |
|
| 87 | + $this->queryStructure->setElement(QueryStructure::SET_FIELDS, $pdoRowValuesString); |
|
| 88 | 88 | |
| 89 | - return $this; |
|
| 90 | - } |
|
| 89 | + return $this; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - private function getInsertMultipleRowsSyntax() |
|
| 96 | - { |
|
| 97 | - if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class)) |
|
| 98 | - return $this->getSyntaxWithSelect(); |
|
| 92 | + /** |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + private function getInsertMultipleRowsSyntax() |
|
| 96 | + { |
|
| 97 | + if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class)) |
|
| 98 | + return $this->getSyntaxWithSelect(); |
|
| 99 | 99 | |
| 100 | - $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 101 | - $values = QueryHelper::implode($this->queryStructure->getElement(QueryStructure::SET_FIELDS), ', '); |
|
| 100 | + $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 101 | + $values = QueryHelper::implode($this->queryStructure->getElement(QueryStructure::SET_FIELDS), ', '); |
|
| 102 | 102 | |
| 103 | - return $fields . ' VALUES ' . $values; |
|
| 104 | - } |
|
| 103 | + return $fields . ' VALUES ' . $values; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - private function getSyntaxWithSelect() |
|
| 111 | - { |
|
| 112 | - $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + private function getSyntaxWithSelect() |
|
| 111 | + { |
|
| 112 | + $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 113 | 113 | |
| 114 | - return $fields . ' ' . $this->queryStructure->getElement(QueryStructure::SET_FIELDS)->getSyntax(); |
|
| 115 | - } |
|
| 114 | + return $fields . ' ' . $this->queryStructure->getElement(QueryStructure::SET_FIELDS)->getSyntax(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @return int |
|
| 119 | - */ |
|
| 120 | - private function getNumberOfFields() |
|
| 121 | - { |
|
| 122 | - return count($this->queryStructure->getElement(QueryStructure::FIELDS)); |
|
| 123 | - } |
|
| 117 | + /** |
|
| 118 | + * @return int |
|
| 119 | + */ |
|
| 120 | + private function getNumberOfFields() |
|
| 121 | + { |
|
| 122 | + return count($this->queryStructure->getElement(QueryStructure::FIELDS)); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | } |
| 127 | 127 | \ No newline at end of file |
@@ -14,61 +14,61 @@ |
||
| 14 | 14 | |
| 15 | 15 | trait SelectFields |
| 16 | 16 | { |
| 17 | - use Objects; |
|
| 17 | + use Objects; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param string|array $fields |
|
| 22 | - * @return $this |
|
| 23 | - * @throws QueryException |
|
| 24 | - */ |
|
| 25 | - public function fields($fields) |
|
| 26 | - { |
|
| 20 | + /** |
|
| 21 | + * @param string|array $fields |
|
| 22 | + * @return $this |
|
| 23 | + * @throws QueryException |
|
| 24 | + */ |
|
| 25 | + public function fields($fields) |
|
| 26 | + { |
|
| 27 | 27 | |
| 28 | - switch (gettype($fields)) { |
|
| 29 | - case QueryStructure::ELEMENT_TYPE_ARRAY: |
|
| 28 | + switch (gettype($fields)) { |
|
| 29 | + case QueryStructure::ELEMENT_TYPE_ARRAY: |
|
| 30 | 30 | |
| 31 | - $fields = $this->prepareArrayFields($fields); |
|
| 31 | + $fields = $this->prepareArrayFields($fields); |
|
| 32 | 32 | |
| 33 | - if (count($fields)) |
|
| 34 | - $this->queryStructure->setElement(QueryStructure::FIELDS, implode(', ', $fields)); else |
|
| 35 | - $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 36 | - break; |
|
| 33 | + if (count($fields)) |
|
| 34 | + $this->queryStructure->setElement(QueryStructure::FIELDS, implode(', ', $fields)); else |
|
| 35 | + $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 36 | + break; |
|
| 37 | 37 | |
| 38 | - case QueryStructure::ELEMENT_TYPE_STRING: |
|
| 38 | + case QueryStructure::ELEMENT_TYPE_STRING: |
|
| 39 | 39 | |
| 40 | - $fields = trim($fields); |
|
| 41 | - if ('' !== $fields) |
|
| 42 | - $this->queryStructure->setElement(QueryStructure::FIELDS, $fields); else |
|
| 43 | - $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 44 | - break; |
|
| 40 | + $fields = trim($fields); |
|
| 41 | + if ('' !== $fields) |
|
| 42 | + $this->queryStructure->setElement(QueryStructure::FIELDS, $fields); else |
|
| 43 | + $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 44 | + break; |
|
| 45 | 45 | |
| 46 | - default: |
|
| 47 | - throw new QueryException('Invalid fields parameter type', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY); |
|
| 46 | + default: |
|
| 47 | + throw new QueryException('Invalid fields parameter type', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY); |
|
| 48 | 48 | |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return $this; |
|
| 52 | - } |
|
| 51 | + return $this; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param array $fieldsArray |
|
| 56 | - * @return array |
|
| 57 | - * @throws QueryException |
|
| 58 | - */ |
|
| 59 | - private function prepareArrayFields($fieldsArray = array()) |
|
| 60 | - { |
|
| 61 | - $prepareArray = []; |
|
| 54 | + /** |
|
| 55 | + * @param array $fieldsArray |
|
| 56 | + * @return array |
|
| 57 | + * @throws QueryException |
|
| 58 | + */ |
|
| 59 | + private function prepareArrayFields($fieldsArray = array()) |
|
| 60 | + { |
|
| 61 | + $prepareArray = []; |
|
| 62 | 62 | |
| 63 | - foreach ($fieldsArray as $field) { |
|
| 64 | - if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING) |
|
| 65 | - throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD); |
|
| 63 | + foreach ($fieldsArray as $field) { |
|
| 64 | + if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING) |
|
| 65 | + throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD); |
|
| 66 | 66 | |
| 67 | - if ('' !== trim($field)) |
|
| 68 | - $prepareArray[] = trim($field); |
|
| 69 | - } |
|
| 67 | + if ('' !== trim($field)) |
|
| 68 | + $prepareArray[] = trim($field); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return $prepareArray; |
|
| 72 | - } |
|
| 71 | + return $prepareArray; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | \ No newline at end of file |
@@ -15,68 +15,68 @@ |
||
| 15 | 15 | trait GroupBy |
| 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 groupBy($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 groupBy($column, array $allowedColumns = []) |
|
| 28 | + { |
|
| 29 | + $column = trim($column); |
|
| 30 | 30 | |
| 31 | - if (!$this->validateColumn($column, $allowedColumns)) |
|
| 32 | - throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 31 | + if (!$this->validateColumn($column, $allowedColumns)) |
|
| 32 | + throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 33 | 33 | |
| 34 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column); |
|
| 34 | + $this->queryStructure->setElement(QueryStructure::GROUP_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 groupByDesc($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 groupByDesc($column, array $allowedColumns = []) |
|
| 47 | + { |
|
| 48 | + $column = trim($column); |
|
| 49 | 49 | |
| 50 | - if (!$this->validateColumn($column, $allowedColumns)) |
|
| 51 | - throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 50 | + if (!$this->validateColumn($column, $allowedColumns)) |
|
| 51 | + throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 52 | 52 | |
| 53 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column . ' DESC'); |
|
| 53 | + $this->queryStructure->setElement(QueryStructure::GROUP_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 groupByExpression($expression) |
|
| 64 | - { |
|
| 65 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $expression); |
|
| 59 | + /** |
|
| 60 | + * @param $expression |
|
| 61 | + * @return $this |
|
| 62 | + */ |
|
| 63 | + public function groupByExpression($expression) |
|
| 64 | + { |
|
| 65 | + $this->queryStructure->setElement(QueryStructure::GROUP_BY, $expression); |
|
| 66 | 66 | |
| 67 | - return $this; |
|
| 68 | - } |
|
| 67 | + return $this; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - private function getGroupBySyntax() |
|
| 75 | - { |
|
| 76 | - if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY))) |
|
| 77 | - return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', '); |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + private function getGroupBySyntax() |
|
| 75 | + { |
|
| 76 | + if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY))) |
|
| 77 | + return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', '); |
|
| 78 | 78 | |
| 79 | - return ''; |
|
| 80 | - } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -16,40 +16,40 @@ |
||
| 16 | 16 | trait Replacement |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - use Objects; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param $syntax |
|
| 23 | - * @param int $withReplacement |
|
| 24 | - * @return mixed|string |
|
| 25 | - */ |
|
| 26 | - private function getSyntaxReplace($syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE) |
|
| 27 | - { |
|
| 28 | - $syntax = QueryHelper::clearMultipleSpaces($syntax); |
|
| 29 | - |
|
| 30 | - if (!$withReplacement) |
|
| 31 | - return $syntax; |
|
| 32 | - |
|
| 33 | - return $this->replaceValues($syntax); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param $syntax |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - private function replaceValues($syntax) |
|
| 41 | - { |
|
| 42 | - $bindParams = $this->queryStructure->getElement(QueryStructure::BIND_PARAMS); |
|
| 43 | - $search = array(); |
|
| 44 | - $replace = array(); |
|
| 45 | - foreach ($bindParams as $key => $value) { |
|
| 46 | - $search[] = ':' . $key; |
|
| 47 | - $replace[] = DbConnect::getInstance()->quote($value); |
|
| 48 | - } |
|
| 49 | - $syntax = str_ireplace($search, $replace, $syntax); |
|
| 50 | - |
|
| 51 | - return $syntax; |
|
| 52 | - |
|
| 53 | - } |
|
| 19 | + use Objects; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param $syntax |
|
| 23 | + * @param int $withReplacement |
|
| 24 | + * @return mixed|string |
|
| 25 | + */ |
|
| 26 | + private function getSyntaxReplace($syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE) |
|
| 27 | + { |
|
| 28 | + $syntax = QueryHelper::clearMultipleSpaces($syntax); |
|
| 29 | + |
|
| 30 | + if (!$withReplacement) |
|
| 31 | + return $syntax; |
|
| 32 | + |
|
| 33 | + return $this->replaceValues($syntax); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param $syntax |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + private function replaceValues($syntax) |
|
| 41 | + { |
|
| 42 | + $bindParams = $this->queryStructure->getElement(QueryStructure::BIND_PARAMS); |
|
| 43 | + $search = array(); |
|
| 44 | + $replace = array(); |
|
| 45 | + foreach ($bindParams as $key => $value) { |
|
| 46 | + $search[] = ':' . $key; |
|
| 47 | + $replace[] = DbConnect::getInstance()->quote($value); |
|
| 48 | + } |
|
| 49 | + $syntax = str_ireplace($search, $replace, $syntax); |
|
| 50 | + |
|
| 51 | + return $syntax; |
|
| 52 | + |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |
@@ -15,60 +15,60 @@ |
||
| 15 | 15 | trait Distinct |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - use Objects; |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @return $this |
|
| 23 | - */ |
|
| 24 | - public function all() |
|
| 25 | - { |
|
| 26 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 0); |
|
| 27 | - |
|
| 28 | - return $this; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @return $this |
|
| 33 | - */ |
|
| 34 | - public function distinct() |
|
| 35 | - { |
|
| 36 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 1); |
|
| 37 | - |
|
| 38 | - return $this; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @return $this |
|
| 43 | - */ |
|
| 44 | - public function distinctRow() |
|
| 45 | - { |
|
| 46 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 2); |
|
| 47 | - |
|
| 48 | - return $this; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return string |
|
| 54 | - * @throws QueryException |
|
| 55 | - */ |
|
| 56 | - private function getDistinctSyntax() |
|
| 57 | - { |
|
| 58 | - $useDistinct = $this->queryStructure->getElement(QueryStructure::DISTINCT); |
|
| 59 | - |
|
| 60 | - switch ($useDistinct) { |
|
| 61 | - case 0: |
|
| 62 | - return ''; |
|
| 63 | - case 1: |
|
| 64 | - return 'DISTINCT'; |
|
| 65 | - case 2: |
|
| 66 | - return 'DISTINCTROW'; |
|
| 67 | - default: |
|
| 68 | - throw new QueryException('Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - } |
|
| 18 | + use Objects; |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @return $this |
|
| 23 | + */ |
|
| 24 | + public function all() |
|
| 25 | + { |
|
| 26 | + $this->queryStructure->setElement(QueryStructure::DISTINCT, 0); |
|
| 27 | + |
|
| 28 | + return $this; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @return $this |
|
| 33 | + */ |
|
| 34 | + public function distinct() |
|
| 35 | + { |
|
| 36 | + $this->queryStructure->setElement(QueryStructure::DISTINCT, 1); |
|
| 37 | + |
|
| 38 | + return $this; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @return $this |
|
| 43 | + */ |
|
| 44 | + public function distinctRow() |
|
| 45 | + { |
|
| 46 | + $this->queryStructure->setElement(QueryStructure::DISTINCT, 2); |
|
| 47 | + |
|
| 48 | + return $this; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return string |
|
| 54 | + * @throws QueryException |
|
| 55 | + */ |
|
| 56 | + private function getDistinctSyntax() |
|
| 57 | + { |
|
| 58 | + $useDistinct = $this->queryStructure->getElement(QueryStructure::DISTINCT); |
|
| 59 | + |
|
| 60 | + switch ($useDistinct) { |
|
| 61 | + case 0: |
|
| 62 | + return ''; |
|
| 63 | + case 1: |
|
| 64 | + return 'DISTINCT'; |
|
| 65 | + case 2: |
|
| 66 | + return 'DISTINCTROW'; |
|
| 67 | + default: |
|
| 68 | + throw new QueryException('Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | \ No newline at end of file |
@@ -14,16 +14,16 @@ |
||
| 14 | 14 | trait LowPriority |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - use Objects; |
|
| 17 | + use Objects; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return $this |
|
| 21 | - */ |
|
| 22 | - public function lowPriority() |
|
| 23 | - { |
|
| 24 | - $this->queryStructure->setElement(QueryStructure::PRIORITY, 'LOW_PRIORITY'); |
|
| 19 | + /** |
|
| 20 | + * @return $this |
|
| 21 | + */ |
|
| 22 | + public function lowPriority() |
|
| 23 | + { |
|
| 24 | + $this->queryStructure->setElement(QueryStructure::PRIORITY, 'LOW_PRIORITY'); |
|
| 25 | 25 | |
| 26 | - return $this; |
|
| 27 | - } |
|
| 26 | + return $this; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -13,9 +13,9 @@ |
||
| 13 | 13 | trait Objects |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var QueryStructure |
|
| 18 | - */ |
|
| 19 | - protected $queryStructure; |
|
| 16 | + /** |
|
| 17 | + * @var QueryStructure |
|
| 18 | + */ |
|
| 19 | + protected $queryStructure; |
|
| 20 | 20 | |
| 21 | 21 | } |
| 22 | 22 | \ No newline at end of file |
@@ -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 |
@@ -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 |