Compile a delete statement into SQL.

@param  \Illuminate\Database\Query\Builder  $query
@return string
173661
public function compileDelete(Builder $query)
    {
        $table = $this->wrapTable($query->from);

        $where = is_array($query->wheres) ? $this->compileWheres($query) : '';

        return isset($query->joins)
                    ? $this->compileDeleteWithJoins($query, $table, $where)
                    : trim("delete from {$table} {$where}");
    }
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");
	}
29066
public function queriedDelete(Query $query)
    {
        $identifier = $this->getIdentifier();
        $queryResult = $this->query($query);
        $deletedIds = [];

        foreach ($queryResult as $record) {
            try {
                $deletedRecord = $this->delete($record[$identifier]);
                $deletedIds[] = $deletedRecord[$identifier];
            } catch (\Throwable $e) {
                // TODO: need to log record that was not deleted
                continue;
            }
        }

        return $deletedIds;
    }
108157
public function compileSelect(Builder $query)
    {
        $original = $query->columns;

        if (is_null($query->columns)) {
            $query->columns = ['*'];
        }

        $sql = trim($this->concatenate($this->compileComponents($query)));

        $query->columns = $original;

        return $sql;
    }
844778
public function buildDeleteSQL($table = null)
	{
		$sql = 'delete from ' . $this->parseTable($table) . ' ';
		$where = $this->parseCondition(isset($this->operationOption['where']) ? $this->operationOption['where'] : '');
		if ('' !== $where)
		{
			$where = 'where ' . $where . ' ';
		}
		return $sql
				. $where
				. $this->parseOrder()
				. $this->parseLimit()
				. $this->parseLock()
				;
	}
784699
protected function compileUpdateWheres(Builder $query)
	{
		$baseWhere = $this->compileWheres($query);

		if (! isset($query->joins)) {
			return $baseWhere;
		}

		// Once we compile the join constraints, we will either use them as the where
		// clause or append them to the existing base where clauses. If we need to
		// strip the leading boolean we will do so when using as the only where.
		$joinWhere = $this->compileUpdateJoinWheres($query);

		if (trim($baseWhere) == '') {
			return 'where '.$this->removeLeadingBoolean($joinWhere);
		}

		return $baseWhere.' '.$joinWhere;
	}
881121
protected function compileDeleteWithJoins($query, $table)
    {
        $using = ' USING '.collect($query->joins)->map(function ($join) {
            return $this->wrapTable($join->table);
        })->implode(', ');

        $where = count($query->wheres) > 0 ? ' '.$this->compileUpdateWheres($query) : '';

        return trim("delete from {$table}{$using}{$where}");
    }
72211
public function delete(KDatabaseQueryDelete $query)
    {
        $context = $this->getContext();
        $context->query = $query;

        //Execute the delete operation
        if ($this->invokeCommand('before.delete', $context) !== false)
        {
            //Execute the query
            $context->result = $this->execute($context->query);
            $context->affected = $this->_affected_rows;

            $this->invokeCommand('after.delete', $context);
        }

        return $context->affected;
    }
1192435
protected function compileWherePart(Query $query, array &$bindings): string
    {
        $sql = $this->compileCriteria($query->where, $bindings);
        if ($sql !== '') {
            $sql = 'WHERE '.$sql;
        }

        return $sql;
    }
699689
public function compile_where( &$query )
	{
		$build = '';

		foreach( $query->wheres as $where ) 
		{
			// to make nested wheres possible you can pass an closure 
			// wich will create a new query where you can add your nested wheres
			if ( !isset( $where[2] ) && is_closure( $where[1] ) )
			{
				$sub_query = new Query;

				call_user_func( $where[1], $sub_query );

				// The parameters get added by the call of compile where
				$build .= ' '.$where[0].' ( '.substr( $this->compile_where( $sub_query ), 7 ).' )';

				continue;
			}

			// when we have an array as where values we have 
			// to parameterize them
			if ( is_array( $where[3] ) ) 
			{
				$where[3] = '('.$this->parameterize( $where[3] ).')';
			}
			else
			{
				$where[3] = $this->param( $where[3] );
			}

			// we always need to escepe where 1 wich referrs to the key
			$where[1] = $this->escape( $where[1] );

			// implode the beauty
			$build .= ' '.implode( ' ', $where );
		}

		return $build;
	}
1234475
public function compileDelete(Builder $query)
    {
        if (isset($query->joins) || isset($query->limit)) {
            $selectSql = parent::compileSelect($query->select("{$query->from}.rowid"));

            return "delete from {$this->wrapTable($query->from)} where {$this->wrap('rowid')} in ({$selectSql})";
        }

        $wheres = is_array($query->wheres) ? $this->compileWheres($query) : '';

        return trim("delete from {$this->wrapTable($query->from)} $wheres");
    }
960900
public function build($query)
    {
        //clone the query so it won't be modified
        $query = clone $query;
        $parts = array();
        $this->_query = $query;
        $this->_store = $query->getRepository()->getStore();
        switch ($query->operation['type']) {
            case AnDomainQuery::QUERY_SELECT_DEFAULT :
            case AnDomainQuery::QUERY_SELECT  :
                $parts[] = $this->select($query);
                $parts[] = $this->from($query);
                $parts[] = '@MYSQL_JOIN_PLACEHOLDER';
                $parts[] = $this->where($query);
                $parts[] = $this->group($query);
                $parts[] = $this->having($query);
                $parts[] = $this->order($query);
                $parts[] = $this->limit($query);
                break;
            case AnDomainQuery::QUERY_UPDATE :
                $parts[] = $this->update($query);
                $parts[] = $this->where($query);
                $parts[] = $this->order($query);
                $parts[] = $this->limit($query);
                break;
            case AnDomainQuery::QUERY_DELETE :
                $parts[] = $this->delete($query);
                $parts[] = $this->from($query);
                $parts[] = $this->where($query);
                break;
            default :
                _die();
        }

        $string = implode(' ', $parts);
        $string = $this->parseMethods($query, $string);
        $string = str_replace('@MYSQL_JOIN_PLACEHOLDER', $this->join($query), $string);
        $string = $this->parseMethods($query, $string);

        if (!empty($query->binds)) {
            foreach ($query->binds as $key => $value) {
                $key = ':'.$key;
                $value = $this->_store->quoteValue($value);
                $string = str_replace($key, $value, $string);
            }
        }

        $string = str_replace('@DISTINCT', $query->distinct ? 'DISTINCT' : '', $string);

        return    $string;
    }
1058953
public function compileWheres(Query $query)
	{
		$wheres = $query->wheres;

		$sql = [];

		foreach ($wheres as $where)
		{
			if ($where instanceof Expression)
			{
				switch ($where->type)
				{
					case 'raw':

						$sql[] = $this->compileRawWhere($where);

						break;

					case 'disjunct':
						
						$sql[] = $this->compileBasicWhere($where);

						break;

					case 'builder':

						$query = Query::$self->newQuery();

						call_user_func($where->clause, $query);

						$sql[] = '(' . substr($this->compileWheres($query), 6) . ')';

						break;
					
					default:
						# code...
						break;
				}
			}
			elseif (($operator = $where) instanceof Operator)
			{
				$sql[] = $operator->getType();
			}
		}

		return 'WHERE ' . implode(' ', $sql);
	}
503900
public function compileSelect(Builder $query) {
    $this->beforeGet($query);
    return $this->grammar->compileSelect($query);
  }
1366757
public function build(Query $query): string
    {
        $this->query = $query;

        $sql = $this->buildQueryStart();

        switch ($this->query->getType()) {
            case Query\Type::INSERT:
                $sql .=
                    $this->buildInto() .
                    $this->buildSet();
                break;
            case Query\Type::SELECT:
                $sql .=
                    $this->buildColumns() .
                    $this->buildFrom() .
                    $this->buildWhere() .
                    $this->buildOrderBy() .
                    $this->buildGroupBy() .
                    $this->buildLimit();
                break;
            case Query\Type::UPDATE:
                $sql .=
                    ' ' . $this->query->getTable() . ' t' .
                    $this->buildSet() .
                    $this->buildWhere();
                break;
            case Query\Type::DELETE:
                $sql .=
                    $this->buildFrom() .
                    $this->buildWhere();
                break;
            default:
                throw new \UnexpectedValueException('Unexpected value of property $type');
        }

        return $sql;
    }
36179
public static function delete($query)
    {
        static::applySchema();

        $key = static::getPrimaryKeyOrMainField();

        if ($key && !is_array($query)) {
            $query = [$key => $query];
        }

        $whereArray = [];
        if (isset($query['where'])) {
            $whereArray[] = $query['where'];
            unset($query['where']);
        }

        $params = [];

        foreach ($query as $field => $value) {
            $token = ':'.$field;
            $whereArray[] = "`{$field}` = {$token}";
            $params[$token] = $value;
        }

        $where = $whereArray
               ? 'WHERE '.implode(' AND ', $whereArray)
               : '';

        $table = static::getTable();
        $sql = "DELETE FROM {$table} {$where}";

        static::getDatabase()->execute($sql, $params);
    }
415632
public function compileSelect(Builder $query)
	{
		$original = $query->columns;

		if (is_null($query->columns)) {
			$query->columns = ['*'];
		}

		$components = $this->compileComponents($query);

		// If an offset is present on the query, we will need to wrap the query in
		// a big "ANSI" offset syntax block. This is very nasty compared to the
		// other database systems but is necessary for implementing features.
		if ($query->offset > 0) {
			return $this->compileAnsiOffset($query, $components);
		}

		$sql = $this->concatenate($components);

		$query->columns = $original;

		return $sql;
	}