<commit_before><?php

namespace ByJG\AnyDataset\Store;

use ByJG\AnyDataset\DbDriverInterface;
use ByJG\AnyDataset\Exception\NotAvailableException;
use ByJG\AnyDataset\Dataset\DbIterator;
use ByJG\AnyDataset\Factory;
use ByJG\AnyDataset\Store\Helpers\SqlBind;
use ByJG\AnyDataset\Store\Helpers\SqlHelper;
use ByJG\Util\Uri;
use PDO;
use PDOStatement;

abstract class DbPdoDriver implements DbDriverInterface
{

    /**
     * @var PDO
     */
    protected $instance = null;

    /**
     * @var Uri
     */
    protected $connectionUri;

    public function __construct(Uri $connUri, $preOptions = null, $postOptions = null)
    {
        $this->connectionUri = $connUri;

        if (!defined('PDO::ATTR_DRIVER_NAME')) {
            throw new NotAvailableException("Extension 'PDO' is not loaded");
        }

        if (!extension_loaded('pdo_' . strtolower($connUri->getScheme()))) {
            throw new NotAvailableException("Extension 'pdo_" . strtolower($connUri->getScheme()) . "' is not loaded");
        }

        $strcnn = $this->createPboConnStr($connUri);

        $this->createPdoInstance($strcnn, $preOptions, $postOptions);
    }

    protected function createPdoInstance($pdoConnectionString, $preOptions = null, $postOptions = null)
    {
        // Create Connection
        $this->instance = new PDO(
            $pdoConnectionString,
            $this->connectionUri->getUsername(),
            $this->connectionUri->getPassword(),
            (array) $preOptions
        );

        $this->connectionUri->withScheme($this->instance->getAttribute(PDO::ATTR_DRIVER_NAME));

        // Set Specific Attributes
        $this->instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->instance->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);

        foreach ((array) $postOptions as $key => $value) {
            $this->instance->setAttribute($key, $value);
        }
    }
    
    protected function createPboConnStr(Uri $connUri)
    {
        $host = $connUri->getHost();
        if (empty($host)) {
            return $connUri->getScheme() . ":" . $connUri->getPath();
        }
        
        $strcnn = $connUri->getScheme() . ":"
            . "dbname=" . preg_replace('~^/~', '', $connUri->getPath())
            . ";host=" . $connUri->getHost();

        if ($connUri->getPort() != "") {
            $strcnn .= ";port=" . $connUri->getPort();
        }

        $query = $connUri->getQuery();
        $strcnn .= ";" . implode(';', explode('&', $query));

        return $strcnn;
    }
    <commit_msg>DbPdoDriver does not require Database parameter<commit_after><?php

namespace ByJG\AnyDataset\Store;

use ByJG\AnyDataset\DbDriverInterface;
use ByJG\AnyDataset\Exception\NotAvailableException;
use ByJG\AnyDataset\Dataset\DbIterator;
use ByJG\AnyDataset\Factory;
use ByJG\AnyDataset\Store\Helpers\SqlBind;
use ByJG\AnyDataset\Store\Helpers\SqlHelper;
use ByJG\Util\Uri;
use PDO;
use PDOStatement;

abstract class DbPdoDriver implements DbDriverInterface
{

    /**
     * @var PDO
     */
    protected $instance = null;

    /**
     * @var Uri
     */
    protected $connectionUri;

    public function __construct(Uri $connUri, $preOptions = null, $postOptions = null)
    {
        $this->connectionUri = $connUri;

        if (!defined('PDO::ATTR_DRIVER_NAME')) {
            throw new NotAvailableException("Extension 'PDO' is not loaded");
        }

        if (!extension_loaded('pdo_' . strtolower($connUri->getScheme()))) {
            throw new NotAvailableException("Extension 'pdo_" . strtolower($connUri->getScheme()) . "' is not loaded");
        }

        $strcnn = $this->createPboConnStr($connUri);

        $this->createPdoInstance($strcnn, $preOptions, $postOptions);
    }

    protected function createPdoInstance($pdoConnectionString, $preOptions = null, $postOptions = null)
    {
        // Create Connection
        $this->instance = new PDO(
            $pdoConnectionString,
            $this->connectionUri->getUsername(),
            $this->connectionUri->getPassword(),
            (array) $preOptions
        );

        $this->connectionUri->withScheme($this->instance->getAttribute(PDO::ATTR_DRIVER_NAME));

        // Set Specific Attributes
        $this->instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->instance->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);

        foreach ((array) $postOptions as $key => $value) {
            $this->instance->setAttribute($key, $value);
        }
    }
    
    protected function createPboConnStr(Uri $connUri)
    {
        $host = $connUri->getHost();
        if (empty($host)) {
            return $connUri->getScheme() . ":" . $connUri->getPath();
        }

        $database = preg_replace('~^/~', '', $connUri->getPath());
        if (!empty($database)) {
            $database = ";dbname=$database";
        }

        $strcnn = $connUri->getScheme() . ":"
            . "host=" . $connUri->getHost()
            . $database;

        if ($connUri->getPort() != "") {
            $strcnn .= ";port=" . $connUri->getPort();
        }

        $query = $connUri->getQuery();
        $strcnn .= ";" . implode(';', explode('&', $query));

        return $strcnn;
    }
    
{'fraction_non_alphanumeric': 0.15298152028957895, 'fraction_numerical': 0.0, 'mean_word_length': 2.6107290233837688, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 63, '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': '4791574', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1602, 'n_words': 278}