/** * Get the SQL of a update statement * @param zibo\library\database\manipulation\statement\manipulation\UpdateStatement $statement * @return string SQL of the update statement * @throws zibo\library\database\exception\DatabaseException when no table was added to the statement * @throws zibo\library\database\exception\DatabaseException when no values where added to the statement */ protected function parseUpdateStatement(UpdateStatement $statement) { $tables = $statement->getTables(); if (empty($tables)) { throw new DatabaseException('No tables added to the update statement'); } $table = array_shift($tables); $values = $statement->getValues(); if (empty($values)) { throw new DatabaseException('No values added to the update statement'); } $sql = ''; foreach ($values as $valueExpression) { $field = $valueExpression->getField(); $value = $valueExpression->getValue(); $value = $this->parseExpression($value); $sql .= ($sql ? ', ' : '') . $this->connection->quoteIdentifier($field->getName()) . ' = ' . $value; } $sql = 'UPDATE ' . $this->connection->quoteIdentifier($table->getName()) . ' SET ' . $sql; $conditions = $statement->getConditions(); if ($conditions) { $operator = $statement->getOperator(); $sql .= ' WHERE ' . $this->parseConditions($conditions, $operator, false); } return $sql; }