Builds an update query.

@param AnDomainQuery $query Query object

@return string
508785
public function update($query)
    {
        $resources = $query->getRepository()->getResources();

        foreach ($resources as $resource) {
            $names[] = $query->getPrefix().$resource->getName().' AS '.$this->_store->quoteName($resource->getAlias());
            //only join update if there are no order			
            if (!empty($query->order)) {
                break;
            }
        }

        $operation = $query->operation['value'];

        if (is_array($query->operation['value'])) {
            $operation = array();
            foreach ($query->operation['value'] as $key => $value) {
                $operation[] = is_numeric($key) ? $value : '@col('.$key.')='.$this->_store->quoteValue($value);
            }
            $operation = implode(',', $operation);
        }

        //only join update if there are no order
        if (empty($query->order)) {
            $resources = $query->getRepository()->getResources();

            foreach ($resources->getLinks() as $link) {
                $query->where($link->child, '=', $link->parent);
            }
        }

        $clause = 'UPDATE '.implode($names, ', ').' SET '.$operation;

        return $clause;
    }
916026
protected function performUpdate(Builder $query)
    {
        // If the updating event returns false, we will cancel the update operation so
        // developers can hook Validation systems into their models and cancel this
        // operation if the model does not pass validation. Otherwise, we update.
        if ($this->fireModelEvent('updating') === false) {
            return false;
        }

        // First we need to create a fresh query instance and touch the creation and
        // update timestamp on the model which are maintained by us for developer
        // convenience. Then we will just continue saving the model instances.
        if ($this->usesTimestamps()) {
            $this->updateTimestamps();
        }

        // Once we have run the update operation, we will fire the "updated" event for
        // this model instance. This will allow developers to hook into these after
        // models are updated, giving them a chance to do any special processing.
        $dirty = $this->getDirty();

        if (count($dirty) > 0) {
            // If dirty attributes contains binary field
            // extract binary fields to new array
            $this->updateBinary($query, $dirty);

            $this->fireModelEvent('updated', false);
        }

        return true;
    }
23785
public function apply(Query $query) : Query
    {
        return $query->where(
            (new QueryExpression())->gt(
                $this->field,
                $this->value,
                $query->getTypeMap()->type($this->field)
            )
        );
    }
768444
public static function render(Query\Update $query)
    {
        return Compiler::withDb($query->getDb(), function () use ($query) {
            return Compiler::expression(array(
                'UPDATE',
                $query->getType(),
                Aliased::combine($query->getTable()),
                Join::combine($query->getJoin()),
                Compiler::word('SET', Set::combine($query->getSet())),
                Compiler::word('WHERE', Condition::combine($query->getWhere())),
                Compiler::word('ORDER BY', Direction::combine($query->getOrder())),
                Compiler::word('LIMIT', $query->getLimit()),
            ));
        });
    }
15531
protected function functions(&$query)
    {

        switch ($this->mode) {

            case "mysql":
            case "odbc":
            case "sqlite":
                $query = preg_replace("/\bISNULL\(/", "IFNULL(", $query);
                break;

            case "postgres":
            case "redshift":
                $query = preg_replace("/\bI[FS]NULL\(/", "COALESCE(", $query);
                break;

            case "mssql":
            case "mssqlsrv":
                $query = preg_replace("/\bIFNULL\(/", "ISNULL(", $query);
                break;
        }

        switch ($this->mode) {

            case "mysql":
            case "postgres":
            case "redshift":
            case "odbc":
            case "mssql":
            case "mssqlsrv":
                $query = preg_replace("/\bSUBSTR\(/", "SUBSTRING(", $query);
                break;

            case "sqlite":
                $query = preg_replace("/\bSUBSTRING\(/", "SUBSTR(", $query);
                break;
        }

        switch ($this->mode) {

            case "postgres":
            case "redshift":
                $query = preg_replace("/\FROM_UNIXTIME\(([^,\)]+),(\s*)([^\)]+)\)/", "TO_CHAR(ABSTIME($1), $3)", $query);
                break;
        }
    }
1146840
public function newEloquentBuilder($query)
    {
        return \tap(new Builder($query), function ($builder) {
            $builder->setTenantor($this->tenantor ?? null);
        });
    }
914066
public function compileUpdate(Builder $query, $values)
    {
        $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 = array();

        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);

        return trim("update {$table}{$joins} set $columns $where");
    }
1053084
public function build(&$query)
    {
        if (isset($query['alias']) && isset($query['id'])) {
            if (!isset($query['get'])) {
                $query['id'] = $query['id'].'-'.$query['alias'];
            }

            unset($query['alias']);
        }

        $has_id = isset($query['id']);
        $segments = parent::build($query);

        if ($has_id) {
            if (isset($query['get'])) {
                $segments[] = $query['get'];

                if ($query['get'] == 'graph') {
                    if (!isset($query['type'])) {
                        $query['type'] = 'followers';
                    }

                    $segments[] = $query['type'];

                    unset($query['type']);
                }

                unset($query['get']);
            }
        } elseif (isset($query['oid'])) {
            if ($query['oid'] == 'viewer') {
                $query['oid'] = get_viewer()->uniqueAlias;
            }

            $segments[] = '@'.$query['oid'];

            unset($query['oid']);
        }

        return $segments;
    }
982012
public function compile_select( &$query )
	{
		$build = ( $query->distinct ? 'select distinct' : 'select' ).' ';

		if ( !empty( $query->fields ) )
		{
			foreach( $query->fields as $key => $field )
			{
				if ( !is_numeric( $key ) )
				{
					$build .= $this->escape( $key ).' as '.$this->escape( $field );
				}
				elseif ( is_array( $field ) )
				{
					$build .= $this->escape( $field[0] ).' as '.$this->escape( $field[1] );
				}
				else 
				{
					$build .= $this->escape( $field );
				}
				$build .= ', ';
			}

			$build = substr( $build, 0, -2 );
		}
		else 
		{
			$build .= '*';
		}

		// append the table
		$build .= ' from '.$this->escape_table( $query );

		// build the where stuff
		$build .= $this->compile_where( $query );
		$build .= $this->compile_group( $query );
		$build .= $this->compile_order( $query );
		$build .= $this->compile_limit_with_offset( $query );

		return $build;
	}
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;
    }
404598
public function clause($condition = 'AND')
    {
        if (empty($this->where)) {
            $condition = null;
        }
        $clause = new AnDomainQueryClause($this, $condition);

        return $clause;
    }
1301786
public function queriedUpdate($record, Query $query)
    {
        if ($query->getLimit()
            || $query->getSort()
            || ($query instanceof RqlQuery && $query->getGroupBy())
            || $query->getSelect()) {
            throw new InvalidArgumentException('Only where clause allowed for update');
        }

        $selectResult = $this->selectForUpdateWithQuery($query);

        if (!$selectResult) {
            return [];
        }

        $conditionBuilder = new SqlConditionBuilder(
            $this->getDbTable()->getAdapter(),
            $this->getDbTable()->getTable()
        );

        $sql = new Sql($this->getDbTable()->getAdapter());
        $update = $sql->update($this->getDbTable()->getTable());
        $update->where($conditionBuilder->__invoke($query->getQuery()));
        $update->set($record);
        $sqlString = $sql->buildSqlString($update);

        $adapter = $this->dbTable->getAdapter();

        try {
            $statement = $adapter->getDriver()->createStatement($sqlString);
            $updateResult = $statement->execute();
            $updatedIds = [];

            if ($selectResult->getAffectedRows() === $updateResult->getAffectedRows()) {
                foreach ($selectResult as $record) {
                    $updatedIds[] = $record[$this->getIdentifier()];
                }
            } else {
                $effectedRecords = $this->query($query);

                foreach ($selectResult as $record) {
                    if ($record !== $effectedRecords[$this->getIdentifier()]) {
                        $updatedIds[] = $effectedRecords[$this->getIdentifier()];
                    }
                }
            }
        } catch (\Throwable $e) {
            throw new DataStoreException("Can't update records using query", 0, $e);
        }

        return $updatedIds;
    }
464101
public function compileUpdate(Builder $query, $values)
    {
        $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 = $this->compileUpdateColumns($query, $values);

        $from = $this->compileUpdateFrom($query);

        $where = $this->compileUpdateWheres($query);

        return trim("update {$table} set {$columns}{$from} {$where}");
    }
1093016
private function executeCreateUpdateQuery (&$query)
	{
		
		// Execute

		try
		{
			$query->execute ();
			return TRUE;
		}
		catch (\PDOException $e)
		{
			
			// Catch some errors
			
			switch ($e->getCode ())
			{
				
				// Duplicate Key
				
				case 23000:
				
					// Get attribute name and set error

					if (preg_match ('/Duplicate entry \'(.*?)\' for key \'(.*?)\'/', $e->getMessage (), $match))
					{
						$name	= $this->attributeExists ($match[2]) && isset (static::$attributes[$match[2]]['name'])? static::$attributes[$match[2]]['name'] : $match[2];
						new Message ('error',  'Please choose another ' . ucwords ($name) . ' `' . $match[1] . '` already exists!');
						return FALSE;
					}

					// Else unrecognised message so throw the error again

					else
					{
						throw $e;
					}
					
					break;
					
					
				// Throw error by default
					
				default:
					throw $e;
				
			}
			
		}
		
	}
414417
public function compileUpdate(Builder $query, $values)
    {
        // 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.

        foreach ($values as $key => $value)
        {
            // Update bindings are differentiated with an _update postfix to make sure the don't clash
            // with query bindings.
            $columns[] = $this->wrap($key) . ' = ' . $this->parameter(array('column' => $key .'_update'));
        }

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

        // 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 Cypher statements we generate to run.
        $where = $this->compileWheres($query);

        // We always need the MATCH clause in our Cypher which
        // is the responsibility of compiling the From component.
        $match = $this->compileComponents($query, array('from'));
        $match = $match['from'];

        // When updating we need to return the count of the affected nodes
        // so we trick the Columns compiler into returning that for us.
        $return = $this->compileColumns($query, array('count('. $query->modelAsNode() .')'));

        return "$match $where SET $columns $return";
    }
3192
public function setQuery($query)
    {
        if (is_string($query)) {
            $output = null;
            parse_str($query, $output);
            $this->query = new QueryString($output);
        } elseif (is_array($query)) {
            $this->query = new QueryString($query);
        } elseif ($query instanceof QueryString) {
            $this->query = $query;
        }

        return $this;
    }
81685
public function build(&$query)
    {
        $segments = array();

        if (isset($query['oid'])) {
            $segments[] = '@'.$query['oid'];
        }

        if (isset($query['q'])) {
            $segments[] = $query['q'];
        }

        //we don't need the view
        unset($query['view']);
        unset($query['oid']);
        unset($query['q']);

        return $segments;
    }