Compile an update statement into SQL.

@param Builder  $query
@param  array  $values
@return string
169613
public function compileUpdate(Builder $query, $values)
	{
		$table = $alias = $this->wrapTable($query->from);

		if (strpos(strtolower($table), '] as [') !== false) {
			$segments = explode('] as [', $table);

			$alias = '['.$segments[1];
		}

		// Each one of the columns in the update statements needs to be wrapped in the
		// keyword identifiers, also a place-holder needs to be created for each of
		// the values in the list of bindings so we can make the sets statements.
		$columns = [];

		foreach ($values as $key => $value) {
			$columns[] = $this->wrap($key).' = '.$this->parameter($value);
		}

		$columns = implode(', ', $columns);

		// If the query has any "join" clauses, we will setup the joins on the builder
		// and compile them so we can attach them to this update, as update queries
		// can get join statements to attach to other tables when they're needed.
		if (isset($query->joins)) {
			$joins = ' '.$this->compileJoins($query, $query->joins);
		} else {
			$joins = '';
		}

		// Of course, update queries may also be constrained by where clauses so we'll
		// need to compile the where clauses and attach it to the query so only the
		// intended records are updated by the SQL statements we generate to run.
		$where = $this->compileWheres($query);

		if (! empty($joins)) {
			return trim("update {$alias} set {$columns} from {$table}{$joins} {$where}");
		}

		return trim("update {$table}{$joins} set $columns $where");
	}
240245
protected function compileWheres(Builder $query)
    {
        $cypher = array();

        if (is_null($query->wheres)) return '';

        // Each type of where clauses has its own compiler function which is responsible
        // for actually creating the where clauses Cypher. This helps keep the code nice
        // and maintainable since each clause has a very small method that it uses.
        foreach ($query->wheres as $where)
        {
            $method = "WHERE{$where['type']}";

            $cypher[] = $where['boolean'].' '.$this->$method($query, $where);
        }

        // If we actually have some where clauses, we will strip off the first boolean
        // operator, which is added by the query builders for convenience so we can
        // avoid checking for the first clauses in each of the compilers methods.
        if (count($cypher) > 0)
        {
            $cypher = implode(' ', $cypher);

            return 'WHERE '.preg_replace('/and |or /', '', $cypher, 1);
        }

        return '';
    }
887426
public function compileUpdate(Builder $query, $values) {
    $this->beforePut($values);
    $this->remapWheres($query);
    return $this->grammar->compileUpdate($query, $values);
  }
1068149
protected function compileBody(Builder $query)
    {
        $body = [];

        $hasBody = !is_null($query->body);

        if ($hasBody) {
            foreach ($query->body as $postField) {
                $body[$postField['column']] = $postField['value'];
            }

            if (count($body) > 0) {
                return $body;
            }
        }

        return '';
    }
307524
public function update(array $values) {
		$sql = $this->buildUpdateSQL($values);
		$params = $this->getParameters();
		return $this->db->query($sql, $params)->affected();
	}
1014270
public function statements($query, $statements)
    {
        try {
            $query = $this->conn->prepare($query);

            foreach ($statements as $key => $value) {
                $param = $statements[$key][0];
                $value = $statements[$key][1];
                $ifExists = (isset($statements[$key][2]));
                $dataType = $ifExists ? $statements[$key][2] : false;

                switch ($dataType) {
                    case 'bool':
                        $query->bindValue($param, $value, \PDO::PARAM_BOOL);
                        continue;
                    case 'null':
                        $query->bindValue($param, $value, \PDO::PARAM_NULL);
                        continue;
                    case 'int':
                        $query->bindValue($param, $value, \PDO::PARAM_INT);
                        continue;
                    case 'str':
                        $query->bindValue($param, $value, \PDO::PARAM_STR);
                        continue;
                }

                $query->bindValue($param, $value);
            }

            $query->execute();

            return $query;
        } catch (\PDOException $e) {
            $this->error = $e->getMessage();

            return null;
        }
    }
1109309
protected function compileJoins(Builder $query, $joins)
    {
        $sql = [];

        foreach ($joins as $join) {
            $conditions = $this->compileWheres($join);

            $table = $this->wrapTable($join->table);

            $sql[] = trim("{$join->type} join {$table} {$conditions}");
        }

        return implode(' ', $sql);
    }
33778
public function compileMatches(Builder $query, $matches)
    {
        if ( ! is_array($matches) || empty($matches)) return '';

        $prepared = array();

        foreach ($matches as $match)
        {
            $method = 'prepareMatch'. ucfirst($match['type']);
            $prepared[] = $this->$method($match);
        }

        return "MATCH " . implode(', ', $prepared);
    }
945694
def compile_update(self, query, values):
        
        sql = super(MySqlQueryGrammar, self).compile_update(query, values)

        if query.orders:
            sql += ' %s' % self._compile_orders(query, query.orders)

        if query.limit_:
            sql += ' %s' % self._compile_limit(query, query.limit_)

        return sql.rstrip()
850832
public function compileUpdateLob(Builder $query, array $values, array $binaries, $sequence = 'id')
    {
        $table = $this->wrapTable($query->from);

        // Each one of the columns in the update statements needs to be wrapped in the
        // keyword identifiers, also a place-holder needs to be created for each of
        // the values in the list of bindings so we can make the sets statements.
        $columns = [];

        foreach ($values as $key => $value) {
            $columns[] = $this->wrap($key) . ' = ' . $this->parameter($value);
        }

        $columns = implode(', ', $columns);

        // set blob variables
        if (! is_array(reset($binaries))) {
            $binaries = [$binaries];
        }
        $binaryColumns    = $this->columnize(array_keys(reset($binaries)));
        $binaryParameters = $this->parameterize(reset($binaries));

        // create EMPTY_BLOB sql for each binary
        $binarySql = [];
        foreach ((array) $binaryColumns as $binary) {
            $binarySql[] = "$binary = EMPTY_BLOB()";
        }

        // prepare binary SQLs
        if (count($binarySql)) {
            $binarySql = (empty($columns) ? '' : ', ') . implode(',', $binarySql);
        }

        // If the query has any "join" clauses, we will setup the joins on the builder
        // and compile them so we can attach them to this update, as update queries
        // can get join statements to attach to other tables when they're needed.
        $joins = '';
        if (isset($query->joins)) {
            $joins = ' ' . $this->compileJoins($query, $query->joins);
        }

        // Of course, update queries may also be constrained by where clauses so we'll
        // need to compile the where clauses and attach it to the query so only the
        // intended records are updated by the SQL statements we generate to run.
        $where = $this->compileWheres($query);

        return "update {$table}{$joins} set $columns$binarySql $where returning " . $binaryColumns . ', ' . $this->wrap($sequence) . ' into ' . $binaryParameters . ', ?';
    }
584071
public function compileUpsert(QueryBuilder $query, array $values): string
    {
        // keyspace-ref:
        $table = $this->wrapTable($query->from);
        // use-keys-clause:
        $keyClause = $this->wrapKey($query->key);
        // returning-clause
        $returning = implode(', ', $query->returning);

        if (!is_array(reset($values))) {
            $values = [$values];
        }
        $parameters = [];

        foreach ($values as $record) {
            $parameters[] = '(' . $this->parameterize($record) . ')';
        }
        $parameters = (!$keyClause) ? implode(', ', $parameters) : "({$keyClause}, \$parameters)";
        $keyValue = (!$keyClause) ? null : '(KEY, VALUE)';

        return "UPSERT INTO {$table} {$keyValue} VALUES $parameters RETURNING {$returning}";
    }
782853
public function buildUpdateFragment(SQLUpdate $query, array &$parameters)
    {
        $table = $query->getTable();
        $text = "UPDATE $table";

        // Join SET components together, considering parameters
        $parts = array();
        foreach ($query->getAssignments() as $column => $assignment) {
            // Assigment is a single item array, expand with a loop here
            foreach ($assignment as $assignmentSQL => $assignmentParameters) {
                $parts[] = "$column = $assignmentSQL";
                $parameters = array_merge($parameters, $assignmentParameters);
                break;
            }
        }
        $nl = $this->getSeparator();
        $text .= "{$nl}SET " . implode(', ', $parts);
        return $text;
    }
683942
public function update(array $values)
    {
        $sql = $this->grammar->compileUpdate($this, $values);

        return $this->connection->update($sql, $this->cleanBindings(
            $this->grammar->prepareBindingsForUpdate($this->bindings, $values)
        ));
    }
1291070
protected function compileWheres(Builder $query)
    {
        $wheres = [];

        $hasWheres = !is_null($query->wheres);

        if ($hasWheres) {
            foreach ($query->wheres as $where) {
                if ($this->hasReplacedParameter($where)) {
                    continue;
                }

                $wheres[$where['column']] = $where['value'];
            }

            // Here we create the query string. Some APIs (Graphite) support multiple
            // parameters with the same key. When we find an entry with multiple values
            // well add it multiple times to the query.
            if (count($wheres) > 0) {
                $queryString = null;

                foreach ($wheres as $key => $value) {
                    if (is_array($value)) {
                        foreach ($value as $attribute) {
                            $queryString .= $this->buildQuery($key, $attribute);
                        }
                    } else {
                        $queryString .= $this->buildQuery($key, $value);
                    }
                }

                return substr($queryString, 1, strlen($queryString));
            }
        }

        return '';
    }
1338030
public function compileInsertGetId(Builder $query, $values, $sequence)
    {
        if (is_null($sequence)) {
            $sequence = 'id';
        }

        return $this->compileInsert($query, $values).' returning '.$this->wrap($sequence);
    }
602822
protected function compileUpdateColumns($query, $values)
    {
        // When gathering the columns for an update statement, we'll wrap each of the
        // columns and convert it to a parameter value. Then we will concatenate a
        // list of the columns that can be added into this update query clauses.
        return collect($values)->map(function ($value, $key) use ($query) {
            $column = Str::after($key, $query->from.'.');

            if ($this->isJsonSelector($key)) {
                return $this->compileJsonUpdateColumn($column, $value);
            }

            return $this->wrap($column).' = '.$this->parameter($value);
        })->implode(', ');
    }
1225363
protected function compileUpdateFrom(Builder $query)
	{
		if ( ! isset($query->joins)) return '';

		$froms = array();

		// When using Postgres, updates with joins list the joined tables in the from
		// clause, which is different than other systems like MySQL. Here, we will
		// compile out the tables that are joined and add them to a from clause.
		foreach ($query->joins as $join)
		{
			$froms[] = $this->wrapTable($join->table);
		}

		if (count($froms) > 0) return ' from '.implode(', ', $froms);
	}