<commit_before><?php

class Database {

    /** @var $mysqli mysqli */
    private static $mysqli;

    /**
     * @return mixed
     *
     */
    public static function query()
    {
        $numArgs = func_num_args();

        if(!$numArgs)
        {
            return false;
        }
        $mysqli = Database::getMysqli();

        if($numArgs == 1)
        {
            $stmt = $mysqli->prepare(func_get_arg(0));
            if(!$stmt)
            {
                Logger::log('$mysqli->prepare failed (%s).', $mysqli->error);
                return false;
            }
            $stmt->execute();
            if($stmt->errno)
            {
                Logger::log('$mysqli->execute failed (%s).', $stmt->error);
                return false;
            }
            $result = Database::fetch($stmt);
            $stmt->close();

            return $result;
        }

        // if the number of arguments is than two

        $type = "";
        $arguments = array();

        for($i = 1; $i < $numArgs; $i++)
        {
            /*
             *
             * TODO:
             *      better error handling for invalid types
             *
             */
            $argument = func_get_arg($i);
            array_push($arguments, $argument);

            switch(gettype($argument))
            {
                case "string":
                    $type .= 's';
                    break;
                case "NULL":
                    $type .= 's';
                    break;
                case "double":
                    $type .= 'd';
                    break;
                case "integer":
                    $type .= 'i';
                    break;
                default:
                    return false;
                    break;
            }
        }

        array_unshift($arguments, $type);
        $stmt = $mysqli->prepare(func_get_arg(0));
        if(!$stmt)
        {
            Logger::log('$mysqli->prepare failed (%s).', $mysqli->error);
            return false;
        }

        if(!call_user_func_array(array($stmt, "bind_param"), CommonUtil::arrayToReferences($arguments)))
        {
            Logger::log('$mysqli->bind_param failed.');
            return false;
        }
        $stmt->execute();
        if($stmt->errno)
        {
            Logger::log('$mysqli->execute failed (%s).', $stmt->error);
            return false;
        }
        if($stmt->affected_rows == -1)
            $result = Database::fetch($stmt);
        else
            $result = $stmt->insert_id;<commit_msg>added boolean support to database queries<commit_after><?php

class Database {

    /** @var $mysqli mysqli */
    private static $mysqli;

    /**
     * @return mixed
     *
     */
    public static function query()
    {
        $numArgs = func_num_args();

        if(!$numArgs)
        {
            return false;
        }
        $mysqli = Database::getMysqli();

        if($numArgs == 1)
        {
            $stmt = $mysqli->prepare(func_get_arg(0));
            if(!$stmt)
            {
                Logger::log('$mysqli->prepare failed (%s).', $mysqli->error);
                return false;
            }
            $stmt->execute();
            if($stmt->errno)
            {
                Logger::log('$mysqli->execute failed (%s).', $stmt->error);
                return false;
            }
            $result = Database::fetch($stmt);
            $stmt->close();

            return $result;
        }

        // if the number of arguments is than two

        $type = "";
        $arguments = array();

        for($i = 1; $i < $numArgs; $i++)
        {
            /*
             *
             * TODO:
             *      better error handling for invalid types
             *
             */
            $argument = func_get_arg($i);
            array_push($arguments, $argument);

            switch(gettype($argument))
            {
                case "string":
                    $type .= 's';
                    break;
                case "NULL":
                    $type .= 's';
                    break;
                case "double":
                    $type .= 'd';
                    break;
                case "integer":
                    $type .= 'i';
                    break;
                case "boolean":
                    $type .= 'i';
                    break;
                default:
                    return false;
                    break;
            }
        }

        array_unshift($arguments, $type);
        $stmt = $mysqli->prepare(func_get_arg(0));
        if(!$stmt)
        {
            Logger::log('$mysqli->prepare failed (%s).', $mysqli->error);
            return false;
        }

        if(!call_user_func_array(array($stmt, "bind_param"), CommonUtil::arrayToReferences($arguments)))
        {
            Logger::log('$mysqli->bind_param failed.');
            return false;
        }
        $stmt->execute();
        if($stmt->errno)
        {
            Logger::log('$mysqli->execute failed (%s).', $stmt->error);
            return false;
        }
        if($stmt->affected_rows == -1)
            $result = Database::fetch($stmt);
        else
            $result = $stmt->insert_id;
{'fraction_non_alphanumeric': 0.13836477987421383, 'fraction_numerical': 0.001905850962454736, 'mean_word_length': 1.1000400160064026, 'pattern_counts': {'":': 9, '<': 7, '<?xml version=': 0, '>': 39, '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': '3589912', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1370, 'n_words': 271}