Prepares a sql statement to be executed

@param string|\Cake\Database\Query $query The query to prepare.
@return \Cake\Database\StatementInterface
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);
    }
605696
public function query($query, $parameters = [])
    {
        try {
            $statement = $this->handle->prepare($query, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
            $statement->execute($parameters);
            return new DatabaseStatement($statement);
        } catch (\PDOException $e) {
            throw new DatabaseException('Error while preparing query « ' . $query . ' » (' .
                $e->getMessage() . ')', $query);
        }
    }
979897
protected function doQuery(Query $query)
    {
        $result = static::db()->query($query);

        $this->where = null;

        return $result;
    }
935907
public function parse($query)
    {
        $queries = array();
        parse_str($query, $queries);

        return new Query($this->parseHttpQueryComponents($queries), $this->getPersister());
    }
1014270
public function statements($query, $statements)
    {
        try {
            $query = $this->conn->prepare($query);

            foreach ($statements as $key => $value) {
                $param = $statements[$key][0];
                $value = $statements[$key][1];
                $ifExists = (isset($statements[$key][2]));
                $dataType = $ifExists ? $statements[$key][2] : false;

                switch ($dataType) {
                    case 'bool':
                        $query->bindValue($param, $value, \PDO::PARAM_BOOL);
                        continue;
                    case 'null':
                        $query->bindValue($param, $value, \PDO::PARAM_NULL);
                        continue;
                    case 'int':
                        $query->bindValue($param, $value, \PDO::PARAM_INT);
                        continue;
                    case 'str':
                        $query->bindValue($param, $value, \PDO::PARAM_STR);
                        continue;
                }

                $query->bindValue($param, $value);
            }

            $query->execute();

            return $query;
        } catch (\PDOException $e) {
            $this->error = $e->getMessage();

            return null;
        }
    }
105659
public function execute( $query ) {
		if ( $query instanceof QueryBuilder ) {
			$query = $query->getSPARQL();
		}

		if ( !is_string( $query ) ) {
			throw new InvalidArgumentException( '$query has to be a string or an instance of QueryBuilder' );
		}

		$result = $this->getResult( $query );
		
		// TODO also support ask queries (with key 'boolean')
		//      https://www.w3.org/TR/rdf-sparql-json-res/
		return $result['results'];
	}
116044
public static function exec($query)
    {
        $ret = false;

        $res = self::query($query);

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

        return $ret;
    }
952205
protected function prepareStatement($db, $query)
    {
        try {
            $stmt = $db->prepare($query);
        } catch (\Exception $e) {
            $stmt = false;
        }

        if (false === $stmt) {
            throw new \RuntimeException('The database cannot successfully prepare the statement');
        }

        return $stmt;
    }
247421
private function resolvePreparedStatement($query = '', array $parameters = [])
    {

        // the instance of database connection
        $connection = $this->getConnection();
        $prepare = $connection->prepare($query);

        if ($prepare instanceof PDOStatement) {
            $resolved = $this->resolvePdoPreparedStatement($prepare, $parameters);
        } elseif ($prepare instanceof mysqli_stmt) {
            $resolved = $this->resolveMysqliPreparedStatement($prepare, $parameters);
        }

        return [$prepare, $resolved];
    }
249268
public function prepare($query = null)
    {
        $of         = is_null($query) ? $this->getQuery() : $query;
        $datatables = $this->datatables->of($of, get_class($this));
        $path       = str_replace(url('/'), '', url()->current());
        Event::fire("datatables.value.{$path}", [$datatables]);
        Event::fire(new Value($path, $datatables));

        return $datatables;
    }
345994
public function process(QueryInterface $query)
    {
        if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_TABLES) {
            return null;
        }

        $tablet = $this->tablet->getTablet();
        $command = new GetSchema($tablet->getAlias());
        /* @var $vtCtldResult GetSchemaResult */
        $vtCtldResult = $this->client->executeCommand($command);

        return new Tables($vtCtldResult);
    }
1005762
public function query($query)
    {
        \Assert\that($query)->string()->notEmpty();

        $this->query = $query;

        return $this;
    }
715641
public function prepare(string $sql = null)
    {
        $this->sqlQuery = $this->getConnection()->prepare($this->getSql($sql));

        return $this;
    }
538607
public function prepareExecuteAndFetchAll(Query $query)
    {
        $prepare = $this->prepareQuery($query);
        $execute = $this->executePrepared($prepare);

        return $this->fetchAllPrepared($prepare);
    }
621076
public function withQuery($query)
    {
        $new = clone $this;
        try {
            $new->setQuery($query);
        } catch (InvalidArgumentException $ex) {
            throw new InvalidArgumentException('Invalid query provided.', null, $ex);
        }

        return $new;
    }
730556
public function prepare($query)
    {
        $this->connect();
        $isObject = $query instanceof Query;
        $statement = $this->_connection->prepare($isObject ? $query->sql() : $query);

        return new PDOStatement($statement, $this);
    }
1201336
public function modifyQuery(Query $query)
    {
        $query = $this->queryBuilder->startFrom($query)->useElevationFromTypoScript()->getQuery();
        return $query;
    }