<commit_before><?php
/**
 * This file is a part of Siny\Q4MBundle package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Siny\Q4MBundle\Queue;

use Siny\Q4MBundle\Queue\Exception\Q4MException;
use \PDO;
use \PDOStatement;
use \PDOException;
use \Exception;

/**
 * This is a class that is very simply Q4M client.
 *
 * @package SinyQ4M
 * @subpackage Queue
 * @author <NAME> <<EMAIL>>
 */
class Q4M
{
    /**
     * PDO object
     * @var PDO
     */
    private $pdo;

    /**
     * Whether mode is owner
     *
     * @var boolean
     */
    private $isModeOwner = false;

    /**
     * Waiting queue table name
     *
     * @var string
     */
    private $waitingTable;

    /**
     * Constructing with PDO
     *
     * @param PDO $pdo
     */
    public function __construct(PDO $pdo)
    {
        $this->pdo = $pdo;
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }

    /**
     * Get PDO object
     *
     * @return \Siny\Q4MBundle\Queue\PDO
     */
    public function getPDO()
    {
        return $this->pdo;
    }

    /**
     * Is mode Owner ?
     * @return boolean
     */
    public function isModeOwner()
    {
        return $this->isModeOwner;
    }

    /**
     * Get table name
     *
     * @return mixed - return the table name when its name was set.
     *                 if its name was not set, return null.
     */
    public function getWaitingTableName()
    {
        return $this->waitingTable;
    }

    /**
     * Enqueue
     *
     * @param string $table     - specify a table name of queueing target.
     * @param array $parameters - the queueing parameters
     * @throws Q4MException
     * @return \Siny\Q4MBundle\Queue\Q4M
     */
    public function enqueue($table, array $parameters)
    {
        try {
            $statement = $this->bind($this->pdo->prepare($this->generateEnqueueSQL($table, $parameters)), $parameters);
            $result = $statement->execute();
            if ($result !== true) {
                throw new Q4MException(sprintf("Failed to insert. error=[%s]", implode(",", $statement->errorInfo())));
            }
            return $this;
        } catch (Exception $e) {
            $parameterString = str_replace("\n", "", var_export($parameters, true));
            throw new Q4MException(sprintf("Failed to enqueue. table=[%s], parameters=[%s]", $table, $parameterString), 0, $e);
        }
    }

    /**
     * Dequeue
     *
     * @param integer $style - PDO fetch style
     * @throws Exception
     * @return mixed (depends on the fetch type)
     */
    public function dequeue($style = PDO::FETCH_ASSOC)
    {
        if ($this->isModeOwner() === false) {
            throw new Q4MException("Must execute any wait function before dequeueing.");
        }
        try {
            $statement = $this->query(sprintf('SELECT * FROM %s', $this->getWaitingTableName()));
            return $this->fetch($statement, $style);
        } catch (Exception $e) {
            throw new Q4MException(sprintf("Failed to dequeue. style=[%s]", $style), 0, $e);
        }
    }

    /**
     * Wait on single table
     *
     * @param string $table
     * @throws Exception
     * @return \Siny\Q4MBundle\Queue\Q4M
     */
    public function waitOnSingleTable($table)
    {
        try {
            $this->executeFunction(sprintf("queue_wait(%s)", $this->pdo->quote($table)));
            $this->isModeOwner  = true;
            $this->waitingTable = $table;
            return $this;
        } catch (Exception $e) {
            throw new Q4MException(sprintf("Failed to wait on single table. function=[%s]", $function), 0, $e);
        }
    }
<commit_msg>fixed a bug that php notice<commit_after><?php
/**
 * This file is a part of Siny\Q4MBundle package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Siny\Q4MBundle\Queue;

use Siny\Q4MBundle\Queue\Exception\Q4MException;
use \PDO;
use \PDOStatement;
use \PDOException;
use \Exception;

/**
 * This is a class that is very simply Q4M client.
 *
 * @package SinyQ4M
 * @subpackage Queue
 * @author <NAME> <<EMAIL>>
 */
class Q4M
{
    /**
     * PDO object
     * @var PDO
     */
    private $pdo;

    /**
     * Whether mode is owner
     *
     * @var boolean
     */
    private $isModeOwner = false;

    /**
     * Waiting queue table name
     *
     * @var string
     */
    private $waitingTable;

    /**
     * Constructing with PDO
     *
     * @param PDO $pdo
     */
    public function __construct(PDO $pdo)
    {
        $this->pdo = $pdo;
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }

    /**
     * Get PDO object
     *
     * @return \Siny\Q4MBundle\Queue\PDO
     */
    public function getPDO()
    {
        return $this->pdo;
    }

    /**
     * Is mode Owner ?
     * @return boolean
     */
    public function isModeOwner()
    {
        return $this->isModeOwner;
    }

    /**
     * Get table name
     *
     * @return mixed - return the table name when its name was set.
     *                 if its name was not set, return null.
     */
    public function getWaitingTableName()
    {
        return $this->waitingTable;
    }

    /**
     * Enqueue
     *
     * @param string $table     - specify a table name of queueing target.
     * @param array $parameters - the queueing parameters
     * @throws Q4MException
     * @return \Siny\Q4MBundle\Queue\Q4M
     */
    public function enqueue($table, array $parameters)
    {
        try {
            $statement = $this->bind($this->pdo->prepare($this->generateEnqueueSQL($table, $parameters)), $parameters);
            $result = $statement->execute();
            if ($result !== true) {
                throw new Q4MException(sprintf("Failed to insert. error=[%s]", implode(",", $statement->errorInfo())));
            }
            return $this;
        } catch (Exception $e) {
            $parameterString = str_replace("\n", "", var_export($parameters, true));
            throw new Q4MException(sprintf("Failed to enqueue. table=[%s], parameters=[%s]", $table, $parameterString), 0, $e);
        }
    }

    /**
     * Dequeue
     *
     * @param integer $style - PDO fetch style
     * @throws Exception
     * @return mixed (depends on the fetch type)
     */
    public function dequeue($style = PDO::FETCH_ASSOC)
    {
        if ($this->isModeOwner() === false) {
            throw new Q4MException("Must execute any wait function before dequeueing.");
        }
        try {
            $statement = $this->query(sprintf('SELECT * FROM %s', $this->getWaitingTableName()));
            return $this->fetch($statement, $style);
        } catch (Exception $e) {
            throw new Q4MException(sprintf("Failed to dequeue. style=[%s]", $style), 0, $e);
        }
    }

    /**
     * Wait on single table
     *
     * @param string $table
     * @throws Exception
     * @return \Siny\Q4MBundle\Queue\Q4M
     */
    public function waitOnSingleTable($table)
    {
        $function = sprintf("queue_wait(%s)", $this->pdo->quote($table));
        try {
            $this->executeFunction($function);
            $this->isModeOwner  = true;
            $this->waitingTable = $table;
            return $this;
        } catch (Exception $e) {
            throw new Q4MException(sprintf("Failed to wait on single table. function=[%s]", $function), 0, $e);
        }
    }

{'fraction_non_alphanumeric': 0.13535803115591047, 'fraction_numerical': 0.005498101845791334, 'mean_word_length': 2.0281411018628615, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 57, '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': '1298242', 'n_tokens_mistral': 2360, 'n_tokens_neox': 2340, 'n_words': 609}