@param Query|null $query

@return array|mixed
@deprecated
425137
public function allArray(Query $query = null) {
		$iterator = $this->getIterator();
		$array = $iterator->all($query);
		$array = $this->forgeEntity($array);
		return $array;
	}
543816
public function listVersions($query = null): \Generator
    {
        $query = $query instanceof FindVersions ? $query : FindVersions::fromArray((array) $query);
        $pageToken = null;
        $count = 0;

        do {
            $response = $this->client->listVersions($query, $pageToken);
            $result = JSON::decode((string) $response->getBody(), true);

            foreach ((array) ($result['versions'] ?? []) as $versionData) {
                ++$count;
                yield Version::fromArray($versionData);

                if ($count === (int) $query->limit()) {
                    return;
                }
            }

            $pageToken = $result['nextPageToken'] ?? null;
        } while ($pageToken);
    }
727999
protected static function normalizeQuery(?string $query): ?string
    {
        if (null === $query) {
            return null;
        }

        if ('' === $query) {
            return '';
        }

        $parts = [];
        $order = [];

        // sort query params by key and remove missing keys
        foreach (explode('&', $query) as $param) {
            if ('' === $param || '=' === $param[0]) {
                continue;
            }
            $parts[] = $param;
            $kvp = explode('=', $param, 2);
            $order[] = $kvp[0];
        }

        array_multisort($order, SORT_ASC, $parts);

        return parent::normalizeQuery(implode('&', $parts));
    }
542844
public function prepare($query)
	{
		if (!$this->isOpen) { $this->throwError("It's not connected to the database",""); return null; }
		$this->lastParam=[];
		$this->lastQuery = $query;
		if ($this->readonly) {
			if (stripos($query, 'insert ') === 0 || stripos($query, 'update ') === 0 || stripos($query, 'delete ') === 0) {
				// we aren't checking SQL-DCL queries.
				$this->throwError("Database is in READ ONLY MODE","");
			}
		}
		if ($this->logLevel>=2) {
			$this->storeInfo($query);
		}

		try {
			$stmt = $this->conn1->prepare($query);
		} catch (Exception $ex) {
			$stmt=false;
			$this->throwError("Failed to prepare",$ex->getMessage(),json_encode($this->lastParam));
		}
		if ($stmt === false) {
			$this->throwError("Unable to prepare query",$this->lastQuery,json_encode($this->lastParam));
		}
		return $stmt;
	}
1230867
public function lookup(Query $query)
    {
        $id = $this->serializeQueryToIdentity($query);

        $expiredAt = $this->expiredAt;

        return $this->cache
            ->get($id)
            ->then(function ($value) use ($query, $expiredAt) {
                // cache 0.5+ resolves with null on cache miss, return explicit cache miss here
                if ($value === null) {
                    return Promise\reject();
                }

                /* @var $recordBag RecordBag */
                $recordBag = unserialize($value);

                // reject this cache hit if the query was started before the time we expired the cache?
                // todo: this is a legacy left over, this value is never actually set, so this never applies.
                // todo: this should probably validate the cache time instead.
                if (null !== $expiredAt && $expiredAt <= $query->currentTime) {
                    return Promise\reject();
                }

                return $recordBag->all();
            });
    }
777862
protected function getQueryInfos($query)
    {
        $type = strtolower(substr($query, 0, 6));

        switch ($type) {
            case 'select':
                $pattern = '/SELECT\s((.|\n)*)\sFROM\s(?P<table>[a-zA-Z_]*)($|(.*)$)/i';
                break;

            case 'insert':
                $pattern = '/INSERT(\s+)INTO(\s+)(?P<table>[a-zA-Z_]*)(\s*)(.*)/i';
                break;

            case 'update':
                $pattern = '/UPDATE(\s+)(?P<table>[a-zA-Z_]*)(\s*)(.*)/i';
                break;

            case 'delete':
                $pattern = '/DELETE(\s+)FROM(\s+)(?P<table>[a-zA-Z_]*)(\s*)(.*)/i';
                break;

            default:
                $type = 'other';
                $pattern = false;
        }

        if ($pattern && preg_match($pattern, $query, $matches)) {
            return array($type, $matches['table']);
        }

        return array($type, '__unknown');
    }
282870
public function decode($query): array
    {
        foreach (explode("&", $query) as $keyValuePair) {
            list($key, $value) = $this->decodePair($keyValuePair);
            $this->values->addValue($key, $value);
        }
        return $this->values->getValues();
    }
259382
public function makeRequest(string $type = null, array $query = [])
    {
        if ($type) {
            $query[$type] = null;
        }

        $query['key'] = $this->apiKey;

        return $this->decodeResponse($this->client
            ->get($this->baseUrl, compact('query'))
            ->getBody()
            ->getContents());
    }
873648
public function query($query = NULL) {
        if (isset($query)) {
            $this->setQuery(self::cleanQuery($query));
            return $this;
        }
        return $this->getQuery();
    }
141401
public function textSearch($query = null) {
		if ($query) {
			if (strpos($query, 'type@') === 0) {
				$query = str_replace('type@', '', $query);
				return ['Log.type' => $query];
			}

			$escapedQuery = "'" . $query . "'"; // for now - $this->getDataSource()->value($query);
			return ["MATCH (message) AGAINST ($escapedQuery)"];
		}
		return [];
	}
1274378
public function query($query, $params = array())
  {
    $results = $this->api->get($query, $params);
    if(!isset($results->errors)) {
      return $results;
    } else {
      return $this->debug_mode ? $results->errors[0]->message : null;
    }
  }
244307
public function all(Query $query = null) {
		$query = Query::forge($query);
		$collection = parent::all($query);
		if(YII_ENV_TEST) {
			$collection[] = $this->forgeEntity([
				'title' => 'Source',
				'name' => 'source',
				'code' => LanguageEnum::code(LanguageEnum::SOURCE),
				'locale' => LanguageEnum::SOURCE,
				'is_main' => false,
				'is_enabled' => true,
			]);
		}
		return $collection;
	}
28570
public function toArray($query)
    {
        $nodes = $this->xpath->query((string) $query);
        if ($nodes->length) {
            $result = array();
            foreach ($nodes as $node) {
                $result[] = json_decode(
                    json_encode(
                        simplexml_load_string(
                            $this->dom->saveXML($node)
                        )
                    ),
                    true
                );
            }
            return $result;
        }
        return null;
    }
1334384
public static function getRow($query)
    {
        $ret = null;

        $res = self::query($query);
        if ($res) {
            if ($row = self::connection()->sql_fetch_assoc($res)) {
                $ret = $row;
            }
            self::free($res);
        }

        return $ret;
    }
394055
protected function getValueFromRelationQuery($query)
    {
        // Prevent looking up connected model when foreign keys are NULL to prevent query errors.

        /** @var MorphTo $query */
        $typeName = $query->getMorphType();
        $keyName  = $query->getForeignKey();

        if ( ! $this->model->{$typeName} || ! $this->model->{$keyName}) {
            return null;
        }

        $query = $this->prepareRelationQuery($query);

        return $this->getValueFromModel(
            $query->first()
        );
    }
1230516
public function findID(Query $query) {
        $pk = $this->getPrimaryKey();

        // Gather ID from where clause
        foreach ($query->getWhere()->getParams() as $param) {
            if ($param instanceof Expr && $param->getField() === $pk && in_array($param->getOperator(), ['=', 'in'])) {
                return $param->getValue();
            }
        }

        // Query for the ID then
        $select = clone $query;
        $results = array_values($select->setType(Query::SELECT)->fields($pk)->lists($pk, $pk, [
            'before' => false,
            'after' => false
        ]));

        if (count($results) > 1) {
            return $results;

        } else if (count($results) === 1) {
            return $results[0];
        }

        return null;
    }
36890
protected function checkQuery($query=null)
    {
        if ($query) {
            $this->getQuery()->set($query);
            unset($query);
        }
        
        $query = $this->getQuery();
        
        // if no table then set table
        if (!isset($query['table'])) {
            $query['table'] = $this->getTableName();
        }
        
        // use model database.table_prefix
        if (!isset($query['database']) && isset($this['database'])) {
            $query['database'] = $this['database'];
        }
        
        if (!isset($query['table_prefix']) && isset($this['table_prefix'])) {
            $query['table_prefix'] = $this['table_prefix'];
        }
        
        return static::formatQuery($query);
    }