<commit_before><?php
/**
 * Copyright 2018 The WildPHP Team
 *
 * You should have received a copy of the MIT license with the project.
 * See the LICENSE file for more information.
 */

namespace WildPHP\Core\Storage\Providers;

use WildPHP\Core\Storage\StorageException;

class GenericPdoDatabaseStorageProvider implements DatabaseStorageProviderInterface
{
    /**
     * @var \PDO
     */
    protected $pdo;

    /**
     * @var array
     */
    protected $knownTables = ['users', 'channels', 'policies'];

    /**
     * @param string $table
     * @param array $columns
     * @param array $where
     * @param array $joins
     * @return array
     * @throws StorageException
     */
    public function select(string $table, array $columns = [], array $where = [], array $joins = []): array
    {
        $query = sprintf('SELECT %s FROM %s %s %s',
            $this->prepareColumnNames($columns),
            $this->prepareTableName($table),
            $this->prepareJoinStatement($joins),
            $this->prepareWhereStatement($where)
        );
        $result = $this->pdo->prepare($query, array_values($where));

        return $result->fetchAll(\PDO::FETCH_ASSOC);
    }

    /**
     * @param string $table<commit_msg>PDO: fix select() so it executes the query<commit_after><?php
/**
 * Copyright 2018 The WildPHP Team
 *
 * You should have received a copy of the MIT license with the project.
 * See the LICENSE file for more information.
 */

namespace WildPHP\Core\Storage\Providers;

use WildPHP\Core\Storage\StorageException;

class GenericPdoDatabaseStorageProvider implements DatabaseStorageProviderInterface
{
    /**
     * @var \PDO
     */
    protected $pdo;

    /**
     * @var array
     */
    protected $knownTables = ['users', 'channels', 'policies'];

    /**
     * @param string $table
     * @param array $columns
     * @param array $where
     * @param array $joins
     * @return array
     * @throws StorageException
     */
    public function select(string $table, array $columns = [], array $where = [], array $joins = []): array
    {
        $query = sprintf('SELECT %s FROM %s %s %s',
            $this->prepareColumnNames($columns),
            $this->prepareTableName($table),
            $this->prepareJoinStatement($joins),
            $this->prepareWhereStatement($where)
        );
        $result = $this->pdo->prepare($query);
        $result->execute(array_values($where));

        return $result->fetchAll(\PDO::FETCH_ASSOC);
    }

    /**
     * @param string $table
{'fraction_non_alphanumeric': 0.13433425523508494, 'fraction_numerical': 0.0031608060055314103, 'mean_word_length': 2.643165467625899, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '675813', 'n_tokens_mistral': 723, 'n_tokens_neox': 709, 'n_words': 188}