Exemplo n.º 1
0
function qa_db_query_raw($query)
{
    $db = qa_db_connection();
    if (QA_DEBUG_PERFORMANCE) {
        global $qa_database_usage, $qa_database_queries;
        $oldtime = array_sum(explode(' ', microtime()));
        $result = mysql_query($query, $db);
        $usedtime = array_sum(explode(' ', microtime())) - $oldtime;
        if (is_array($qa_database_usage)) {
            $qa_database_usage['clock'] += $usedtime;
            if (strlen($qa_database_queries) < 1048576) {
                // don't keep track of big tests
                $qa_database_queries .= $query . "\n\n" . sprintf('%.2f ms', $usedtime * 1000) . "\n\n";
            }
            $qa_database_usage['queries']++;
        }
    } else {
        $result = mysql_query($query, $db);
    }
    if ($result === false) {
        qa_db_fail_error('query', mysql_errno($db), mysql_error($db), $query);
    }
    return $result;
}
Exemplo n.º 2
0
/**
 * Run the raw $query, call the global failure handler if necessary, otherwise return the result resource.
 * If appropriate, also track the resources used by database queries, and the queries themselves, for performance debugging.
 */
function qa_db_query_raw($query)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    if (QA_DEBUG_PERFORMANCE) {
        global $qa_usage;
        // time the query
        $oldtime = array_sum(explode(' ', microtime()));
        $result = qa_db_query_execute($query);
        $usedtime = array_sum(explode(' ', microtime())) - $oldtime;
        // fetch counts
        $gotrows = $gotcolumns = null;
        if ($result instanceof mysqli_result) {
            $gotrows = $result->num_rows;
            $gotcolumns = $result->field_count;
        }
        $qa_usage->logDatabaseQuery($query, $usedtime, $gotrows, $gotcolumns);
    } else {
        $result = qa_db_query_execute($query);
    }
    //	@error_log('Question2Answer MySQL query: '.$query);
    if ($result === false) {
        $db = qa_db_connection();
        qa_db_fail_error('query', $db->errno, $db->error, $query);
    }
    return $result;
}
Exemplo n.º 3
0
function qa_db_query_raw($query)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    if (QA_DEBUG_PERFORMANCE) {
        global $qa_database_usage, $qa_database_queries;
        $oldtime = array_sum(explode(' ', microtime()));
        $result = qa_db_query_execute($query);
        $usedtime = array_sum(explode(' ', microtime())) - $oldtime;
        if (is_array($qa_database_usage)) {
            $qa_database_usage['clock'] += $usedtime;
            if (strlen($qa_database_queries) < 1048576) {
                // don't keep track of big tests
                $gotrows = is_resource($result) ? mysql_num_rows($result) : null;
                $gotcolumns = is_resource($result) ? mysql_num_fields($result) : null;
                $qa_database_queries .= $query . "\n\n" . sprintf('%.2f ms', $usedtime * 1000) . (is_numeric($gotrows) ? ' - ' . $gotrows . ($gotrows == 1 ? ' row' : ' rows') : '') . (is_numeric($gotcolumns) ? ' - ' . $gotcolumns . ($gotcolumns == 1 ? ' column' : ' columns') : '') . "\n\n";
            }
            $qa_database_usage['queries']++;
        }
    } else {
        $result = qa_db_query_execute($query);
    }
    //	@error_log('Question2Answer MySQL query: '.$query);
    if ($result === false) {
        $db = qa_db_connection();
        qa_db_fail_error('query', mysql_errno($db), mysql_error($db), $query);
    }
    return $result;
}