Builds an delete query. Handles multiple resources at once.

@param AnDomainQuery $query Query object

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

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

        $names = array();

        foreach ($resources as $resource) {
            $query->from($resource->getName().' AS '.$this->_store->quoteName($resource->getAlias()));
            $names[] = $this->_store->quoteName($resource->getAlias());
        }

        $clause = 'DELETE '.implode(', ', $names);

        return $clause;
    }
972978
protected function checkForDeleted(Builder $query)
    {
        if (request()->has('deleted') && request()->input('deleted') === '1')
            $query = $query->onlyTrashed();

        return $query;
    }
428957
public function buildQuery($query)
	{
		foreach($this->children as $child)
		{
			if($child->master!==null)
				$child->_joined=true;
			elseif($child->relation instanceof CHasOneRelation || $child->relation instanceof CBelongsToRelation
				|| $this->_finder->joinAll || $child->relation->together || (!$this->_finder->baseLimited && $child->relation->together===null))
			{
				$child->_joined=true;
				$query->join($child);
				$child->buildQuery($query);
			}
		}
	}
31097
public function buildDeleteFragment(SQLDelete $query, array &$parameters)
    {
        $text = 'DELETE';

        // If doing a multiple table delete then list the target deletion tables here
        // Note that some schemas don't support multiple table deletion
        $delete = $query->getDelete();
        if (!empty($delete)) {
            $text .= ' ' . implode(', ', $delete);
        }
        return $text;
    }
1050238
public function select($query)
    {
        $clause = 'SELECT @DISTINCT';

        if ($query->operation['type'] & AnDomainQuery::QUERY_SELECT_DEFAULT) {
            $description = $query->getRepository()->getDescription();
            $columns = AnDomainQueryHelper::parseColumns($query, $query->columns);
            foreach ($description->getProperty() as $name => $property) {
                if (isset($columns[$name])) {
                    $result = AnDomainQueryHelper::parseColumn($query, $name);
                    if ($result['columns'] instanceof AnDomainResourceColumn) {
                        $columns[] = $columns[$name].' AS '.$this->_store->quoteValue($result['columns']->key());
                        unset($columns[$name]);
                    }
                } elseif ($property->isAttribute()) {
                    $columns[] = $property->getColumn();
                } elseif ($property->isRelationship() && $property->isManyToOne()) {
                    $columns = array_merge($columns, array_values(AnConfig::unbox($property->getColumns())));
                }
            }

            if ($description->getInheritanceColumn()) {
                $columns[] = $description->getInheritanceColumn();
            }

            foreach ($columns as $key => $column) {
                if ($column instanceof AnDomainResourceColumn) {
                    if ($column->resource->getLink()) {
                        $columns[$key] = $column.' AS '.$this->_store->quoteValue((string) $column);
                        continue;
                    } else {
                        $columns[$key] = (string) $column;
                    }
                }
                if (!is_numeric($key)) {
                    $columns[$key] = $column.' AS '.$this->_store->quoteValue($key);
                }
            }
            $clause .= ' '.implode(' , ', $columns);
        } else {
            $columns = (array) $query->operation['value'];
            $columns = AnDomainQueryHelper::parseColumns($query, $columns);
            $clause .= ' '.implode(' , ', $columns);
        }

        return $clause;
    }
650735
public function where($query)
    {
        $clauses = $this->_where($query);

        $clause = implode(' AND ', $clauses);

        if (!empty($clause)) {
            $clause = 'WHERE '.$clause;
        }

        return $clause;
    }
179170
protected function getDeleteQuery()
    {
        $foreign = $this->getAttribute($this->foreignKey);

        $query = $this->newQuery()->where($this->foreignKey, $foreign);

        return $query->where($this->otherKey, $this->getAttribute($this->otherKey));
    }
908669
private function filterQuery($query)
    {
        if (! empty($query) && strpos($query, '?') === 0) {
            $query = substr($query, 1);
        }

        $parts = explode('&', $query);
        foreach ($parts as $index => $part) {
            list($key, $value) = $this->splitQueryValue($part);
            if ($value === null) {
                $parts[$index] = $this->filterQueryOrFragment($key);
                continue;
            }
            $parts[$index] = sprintf(
                '%s=%s',
                $this->filterQueryOrFragment($key),
                $this->filterQueryOrFragment($value)
            );
        }

        return implode('&', $parts);
    }
502253
public function buildDeleteQuery($entity) {
        $mapper = MapperBuilder::buildFromMapping($this->mapping, get_class($entity));
        $query = "";
        foreach ($mapper->getRelations() as $relation) {
            $query .= $this->buildDeleteRelationQuery($relation, $entity);
        }

        $query .= "DELETE FROM " . $mapper->getTable() . " ";
        $query .= "WHERE id = '" . $entity->getId() . "';";

        return $query;
    }
841756
private function queryToAndExpression(LuceneQuery $query)
    {
        $span = new SpanExpression('AND');

        if (!$query->hasTrivialMainQuery())
            $span->addExpression($query->getMainQuery());

        $span->addExpressions($query->getFilterQueries());

        return $span;
    }
755313
protected function _callQuery($query)
    {
        $query->contain($this->type['contain']);
        $extQuery = $this->type['query'];
        return $extQuery($query);
    }
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;
        }
    }
197366
public function build(&$query)
    {
        if (isset($query['alias']) && isset($query['id'])) {
            $query['id'] = $query['id'].'-'.$query['alias'];
            unset($query['alias']);
        }

        $segments = array();

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

        $segments = array_merge($segments, parent::build($query));

        return $segments;
    }
1055606
public function rawDelete(Query $query)
        {
            $query->setTable($this);
            $query->generateDeleteSQL();

            $value = Statement::getPreparedStatement($query)->execute();
            $this->clearB2DBCachedObjects();

            return $value;
        }
386494
protected function deleteRecord(Query $query): bool
	{
		return (bool) $query->where($this->primaryKey, '=', $this->columns[$this->primaryKey])->delete();
	}
879490
public function delete($query, array $options = []) {
		$this->_checkConnection();

		$defaults = [
			'justOne' => false,
			'w' => $this->_config['w'],
			'wTimeoutMS' => $this->_config['wTimeoutMS'],
			'fsync' => false
		];
		$options = array_intersect_key($options + $defaults, $defaults);
		$params = compact('query', 'options');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$prefix = $this->_config['gridPrefix'];

			$query = $params['query'];
			$options = $params['options'];
			$args = $query->export($this, ['keys' => ['source', 'conditions']]);
			$source = $args['source'];
			$conditions = $args['conditions'];

			if ($source === "{$prefix}.files") {
				$result = $this->_deleteFile($conditions);
			} else {
				$result = $this->connection->{$args['source']}->remove($conditions, $options);
				$result = $this->_ok($result);
			}
			if ($result && $query->entity()) {
				$query->entity()->sync(null, [], ['dematerialize' => true]);
			}
			return $result;
		});
	}
908136
protected function buildDeleteQuery(SQLDelete $query, array &$parameters)
    {
        $sql  = $this->buildDeleteFragment($query, $parameters);
        $sql .= $this->buildFromFragment($query, $parameters);
        $sql .= $this->buildWhereFragment($query, $parameters);
        return $sql;
    }