<commit_before><?php
/**
 * Vision PHP-Framework
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012-2013 <NAME>
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
namespace Vision\Database;

/**
 * PDO
 *
 * @author <NAME> <<EMAIL>>
 */
class PDO extends \PDO
{
    /** @type bool $hasActiveTransaction */
    protected $hasActiveTransaction = false;

    /**
     * This method returns the current driver name (only if it's supported by the driver)
     *
     * @api
     *
     * @return string
     */
    public function getDriverName()
    {
        return parent::getAttribute(\PDO::ATTR_DRIVER_NAME);
    }

    /**
    * Workaround for WHERE IN() queries
    *
    * @api
    *
    * @param mixed $mixed
    *
    * @return string|array
    */
    public function createQuestionMarks($mixed)
    {
        if (is_array($mixed)) {
            $count = count($mixed) - 1;
            $questionMarks = str_repeat('?,', $count) . '?';
            return $questionMarks;
        }

        return array();
    }

    /**
     * This method returns a UUID ready to be stored as BINARY(16).
     *
     * @todo Support for other drivers.
     *
     * @api
     *
     * @return string
     */
    public function createUuid()
    {
        $name = $this->getDriverName();

        switch ($name) {
            case 'mysql':
                $sth = $this->query('SELECT UNHEX(REPLACE(UUID(), "-", ""))');
                return $sth->fetchColumn();

            default:
                return null;
        }
    }

    /**
     * Another workaround for WHERE IN() queries with array.
     *
     * Example: Passing an array with three elements it will return "IN (?, ?, ?)"
     *
     * @api
     *
     * @param array $data
     *
     * @return string
     */
    public function IN(array $data)
    {
        $string = $this->createQuestionMarks($data);
        $string = 'IN (' . $string . ')';
        return $string;
    }
    
    public function VALUES($data)
    {
        return $this->createMultipleValuesList($data);
    }

    /**
     * Useful method for Inserts
     *
     * @api
     *
     * @param mixed $mixed
     *
     * @return string
     */
    public function createMultipleValuesList($mixed)
    {
        if (is_array($mixed)) {<commit_msg>Add: convenient method for SET expr in SQL<commit_after><?php
/**
 * Vision PHP-Framework
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012-2013 <NAME>
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
namespace Vision\Database;

/**
 * PDO
 *
 * @author <NAME> <<EMAIL>>
 */
class PDO extends \PDO
{
    /** @type bool $hasActiveTransaction */
    protected $hasActiveTransaction = false;

    /**
     * This method returns the current driver name (only if it's supported by the driver)
     *
     * @api
     *
     * @return string
     */
    public function getDriverName()
    {
        return parent::getAttribute(\PDO::ATTR_DRIVER_NAME);
    }

    /**
    * Workaround for WHERE IN() queries
    *
    * @api
    *
    * @param mixed $mixed
    *
    * @return string|array
    */
    public function createQuestionMarks($mixed)
    {
        if (is_array($mixed)) {
            $count = count($mixed) - 1;
            $questionMarks = str_repeat('?,', $count) . '?';
            return $questionMarks;
        }

        return array();
    }

    /**
     * This method returns a UUID ready to be stored as BINARY(16).
     *
     * @todo Support for other drivers.
     *
     * @api
     *
     * @return string
     */
    public function createUuid()
    {
        $name = $this->getDriverName();

        switch ($name) {
            case 'mysql':
                $sth = $this->query('SELECT UNHEX(REPLACE(UUID(), "-", ""))');
                return $sth->fetchColumn();

            default:
                return null;
        }
    }

    /**
     * Another workaround for WHERE IN() queries with array.
     *
     * Example: Passing an array with three elements it will return "IN (?, ?, ?)"
     *
     * @api
     *
     * @param array $data
     *
     * @return string
     */
    public function IN(array $data)
    {
        $string = $this->createQuestionMarks($data);
        $string = 'IN (' . $string . ')';
        return $string;
    }
    
    public function VALUES($data)
    {
        return $this->createMultipleValuesList($data);
    }
    
    public function SET(array $data)
    {
        $values = array_keys($data);
        array_walk($values, function(&$value) {
            $value = $value . ' = ?';
        }); 
        $qs = 'SET ' . implode(', ', $values);
        return $qs;
    }

    /**
     * Useful method for Inserts
     *
     * @api
     *
     * @param mixed $mixed
     *
     * @return string
     */
    public function createMultipleValuesList($mixed)
    {
        if (is_array($mixed)) {
{'fraction_non_alphanumeric': 0.1402464065708419, 'fraction_numerical': 0.004517453798767967, 'mean_word_length': 1.7834285714285714, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1976816', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1463, 'n_words': 359}