prepareQueryTimeline

@param Data[] $queries

@return  array
978194
public static function prepareQueryTimeline(array $queries)
    {
        if (!$queries) {
            return new NullObject();
        }

        // Prepare timeline data
        $timeline = [];

        foreach ($queries as $i => $data) {
            $time['value'] = abs($data['time']['start'] - $data['time']['end']) * 1000;
            $time['style'] = static::getStateColor($time['value'], 15);

            $memory['value'] = abs($data['memory']['start'] - $data['memory']['end']) / 1048576;
            $memory['style'] = static::getStateColor($memory['value'], 0.01);

            $timeline[$data['serial']] = [
                'time' => $time,
                'memory' => $memory,
                'data' => $data,
            ];
        }

        return $timeline;
    }
1009747
protected function logQuery( $query, $bindings, $time = null ) {
		if ( $this->loggingQueries && $this->logger ) {
			$this->logger->debug( $query, compact( 'bindings', 'time' ) );
		}
	}
220587
protected function filterQueries($queries)
    {
        $app = Application::getFacadeApplication();
        $config = $app->make('config');

        $textIndexDrops = [];
        foreach ($config->get('database.text_indexes') as $indexTable => $indexDefinition) {
            foreach (array_keys($indexDefinition) as $indexName) {
                $textIndexDrops[] = strtolower("DROP INDEX {$indexName} ON {$indexTable}");
            }
        }

        $returnQueries = [];
        foreach ($queries as $query) {
            $queryLowerCase = strtolower($query);
            if (!in_array($queryLowerCase, $textIndexDrops, true)) {
                $returnQueries[] = $query;
            }
        }

        return $returnQueries;
    }
1359638
private function getUserPasswordMigrations($queries)
    {
        $db        = Db::get();
        $userTable = Common::prefixTable($this->userTable);

        $users = $db->fetchAll(
            'SELECT `login`, `password` FROM `' . $userTable . '` WHERE LENGTH(`password`) = 32'
        );

        foreach ($users as $user) {
            $queries[] = $this->migration->db->boundSql(
                'UPDATE `' . $userTable . '`'
                . ' SET `password` = ?'
                . ' WHERE `login` = ?',
                [
                    password_hash($user['password'], PASSWORD_BCRYPT),
                    $user['login'],
                ]
            );
        }

        return $queries;
    }
1307513
public function setQuery($queries)
    {
        if ($this->executed) {
            $this->clear();
        }
        $this->query->multiple()->setQuery($queries);

        return $this;
    }
300235
public function sanitizeQuery($queries)
    {
        $cleanQueries = array();

        if ( ! is_array($queries)) {
            return $cleanQueries;
        }

        foreach ($queries as $key => $query) {
            if ('relation' === $key) {
                $relation = $query;

            } elseif ( ! is_array($query)) {
                continue;

                // First-order clause.
            } elseif ($this->isFirstOrderClause($query)) {
                if (isset($query[ 'value' ]) && array() === $query[ 'value' ]) {
                    unset($query[ 'value' ]);
                }

                $cleanQueries[ $key ] = $query;

                // Otherwise, it's a nested query, so we recurse.
            } else {
                $cleanedQuery = $this->sanitizeQuery($query);

                if ( ! empty($cleanedQuery)) {
                    $cleanQueries[ $key ] = $cleanedQuery;
                }
            }
        }

        if (empty($cleanQueries)) {
            return $cleanQueries;
        }

        // Sanitize the 'relation' key provided in the query.
        if (isset($relation) && 'OR' === strtoupper($relation)) {
            $cleanQueries[ 'relation' ] = 'OR';

            // Default to AND.
        } else {
            $cleanQueries[ 'relation' ] = 'AND';
        }

        return $cleanQueries;
    }
1042904
public function addQueries(array $queries) : self
    {
        foreach ($queries as $key => $value) {
            if (is_null($value)) {
                continue;
            }

            if (!is_string($key)) {
                throw new \InvalidArgumentException("Invalid querystring '" . $key . "'");
            }

            if (!is_string($value) && !is_array($value)) {
                throw new \InvalidArgumentException(sprintf(
                    "Invalid querystring value '%s' with type '%s'",
                    $key,
                    gettype($value)
                ));
            }

            $this->uri['query'][$key] = $value;
        }

        return $this;
    }
1196875
public static function query($options = array())
	{
		$timestamp_start_name = static::temporal_property('start_column');
		$timestamp_end_name = static::temporal_property('end_column');
		$max_timestamp = static::temporal_property('max_timestamp');

		$query = Query_Temporal::forge(get_called_class(), static::connection(), $options)
			->set_temporal_properties($max_timestamp, $timestamp_end_name, $timestamp_start_name);

		//Check if we need to add filtering
		$class = get_called_class();
		$timestamp = \Arr::get(static::$_lazy_filtered_classes, $class, null);

		if( ! is_null($timestamp))
		{
			$query->where($timestamp_start_name, '<=', $timestamp)
				->where($timestamp_end_name, '>', $timestamp);
		}
		elseif(static::get_primary_key_status() and ! static::get_primary_key_id_only_status())
		{
			$query->where($timestamp_end_name, $max_timestamp);
		}

		return $query;
	}
338712
public function beforeGetFinalisedQuery(DataQuery $dataQuery, $queriedColumns = [], SQLSelect $sqlSelect)
    {
        // Get metadata and SQL from join table
        $hasManyRelation = $this->getParentRelationship($dataQuery);
        $joinTableSQLSelect = $hasManyRelation->dataQuery()->query();
        $joinTableSQL = $joinTableSQLSelect->sql($joinTableParameters);
        $joinTableColumns = array_keys($joinTableSQLSelect->getSelect()); // Get aliases (keys) only
        $joinTableAlias = $this->getJoinAlias();

        // Get fields to join on
        $localKey = $this->getLocalKey();
        $schema = DataObject::getSchema();
        $baseTable = $schema->baseDataClass($dataQuery->dataClass());
        $childField = $schema->sqlColumnForField($baseTable, 'ID');

        // Add select fields
        foreach ($joinTableColumns as $joinTableColumn) {
            $sqlSelect->selectField(
                "\"{$joinTableAlias}\".\"{$joinTableColumn}\"",
                "{$joinTableAlias}_{$joinTableColumn}"
            );
        }

        // Apply join and record sql for later insertion (at end of replacements)
        // By using a string placeholder $$_SUBQUERY_$$ we protect field/table rewrites from interfering twice
        // on the already-finalised inner list
        $sqlSelect->addInnerJoin(
            '(SELECT $$_SUBQUERY_$$)',
            "\"{$joinTableAlias}\".\"{$localKey}\" = {$childField}",
            $joinTableAlias,
            20,
            $joinTableParameters
        );
        $dataQuery->setQueryParam('Foreign.JoinTableSQL', $joinTableSQL);

        // After this join, and prior to afterGetFinalisedQuery, $sqlSelect will be populated with the
        // necessary sql rewrites (versioned, etc) that effect the base table.
        // By using a placeholder for the subquery we can protect the subquery (already rewritten)
        // from being re-written a second time. However we DO want the join predicate (above) to be rewritten.
        // See http://php.net/manual/en/function.str-replace.php#refsect1-function.str-replace-notes
        // for the reason we only add the final substitution at the end of getFinalisedQuery()
    }
812100
public function parse(array $queries = array())
    {
        $this->queries = $queries;
        if (file_exists($this->path) && null != $this->content = file_get_contents($this->path)) {
            // Parse
            ;
            foreach ($this->vars as $var) {
                $this->processVar($var);
            }
        } else {
            $this->content = implode('', $this->queries);
        }

        return $this;
    }
559639
public function prepare($query)
    {
        $this->connect();
        $options = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL];
        $isObject = $query instanceof Query;
        if ($isObject && $query->isBufferedResultsEnabled() === false) {
            $options = [];
        }
        $statement = $this->_connection->prepare($isObject ? $query->sql() : $query, $options);

        return new SqlserverStatement($statement, $this);
    }
233882
private function getElements(array $queries, StorageInterface $storage)
    {
        $elements = [];
        foreach ($queries as $query) {
            $elements[] = $this->getInterpreter($query)->visit($query, $storage);
        }

        return $elements;
    }
1257682
protected function prepareQueryString($queryParameters)
    {
        unset($queryParameters[self::PARAMETER_PAGE]);
        $queryParameters[self::PARAMETER_PAGE] = '';

        return '?' . http_build_query($queryParameters);
    }
106995
protected static function multiQuery(string $queries): void
  {
    if (self::$logQueries)
    {
      $time0 = microtime(true);

      $tmp = self::$mysqli->multi_query($queries);
      if ($tmp===false)
      {
        throw new DataLayerException(self::$mysqli->errno, self::$mysqli->error, $queries);
      }

      self::$queryLog[] = ['query' => $queries, 'time' => microtime(true) - $time0];
    }
    else
    {
      $tmp = self::$mysqli->multi_query($queries);
      if ($tmp===false)
      {
        throw new DataLayerException(self::$mysqli->errno, self::$mysqli->error, $queries);
      }
    }
  }
53712
public function logQuery( string $query, array $bindings, $time = null )
	{
		$this->queries ++;
		if( $time )
		{
			$this->timing += $time;
		}
		if( isset( $this->events ) )
		{
			$this->events->dispatch( new Events\QueryExecutedEvent( $this, $query, $bindings, $time ?? 0 ) );
		}
		if( $this->loggingQueries )
		{
			$this->queryLog[] = compact( 'query', 'bindings', 'time' );
		}
	}
380954
public function prepareQueryOrNewObj(array $query)
    {
        $preparedQuery = array();

        foreach ($query as $key => $value) {
            // Recursively prepare logical query clauses
            if (in_array($key, array('$and', '$or', '$nor')) && is_array($value)) {
                foreach ($value as $k2 => $v2) {
                    $preparedQuery[$key][$k2] = $this->prepareQueryOrNewObj($v2);
                }
                continue;
            }

            if (isset($key[0]) && $key[0] === '$' && is_array($value)) {
                $preparedQuery[$key] = $this->prepareQueryOrNewObj($value);
                continue;
            }

            list($key, $value) = $this->prepareQueryElement($key, $value, null, true);

            $preparedQuery[$key] = is_array($value)
                ? array_map('Doctrine\ODM\MongoDB\Types\Type::convertPHPToDatabaseValue', $value)
                : Type::convertPHPToDatabaseValue($value);
        }

        return $preparedQuery;
    }
1109973
public function prepareQuery(Query $query)
    {
        $parameters = new Parameters($this->driver);

        if ($this->pdo === null)
            $this->connect();

        $sql = $this->driver->toSQL($parameters, $query);

        $statement = $this->prepare($sql);
        $parameters->bindParameters($statement);
        return $statement;
    }