Пример #1
0
bool DBManager::writeFinishedTask()
{
    TaskPtr pTask;
    finishedTaskMgr_->lock();
    if(finishedTaskMgr_->hasTask())
    {
        pTask = finishedTaskMgr_->popTask();
    }
    finishedTaskMgr_->unlock();

    if(!pTask)
    {
        return true;
    }

    if(pTask->input().ProblemID == 0)//IDE测试功能,不写数据库
    {
        return true;
    }
    
    if(!writeToDB(pTask))
    {
        return false;
    }

    OJCout<<GetOJString("write finished:")<<pTask->input().SolutionID<<std::endl;
    return true;
}
Пример #2
0
bool DBManager::writeToDB(TaskPtr pTask)
{
    assert(pTask);

    OJChar_t buffer[MaxBufferSize];

    const TaskInputData & input = pTask->input();
    const TaskOutputData & output = pTask->output();


    //更新结果
    OJSprintf(buffer, Statement::UpdateSolutionResult5.c_str(), output.Result, output.RunTime, 
        output.RunMemory, output.PassRate, input.SolutionID);
    if(!sqlDriver_->query(buffer))
    {
        return false;
    }

    //更新用户提交数量
    OJSprintf(buffer, Statement::UpdateUserSubmit2.c_str(), 
        input.UserName.c_str(), input.UserName.c_str());
    if(!sqlDriver_->query(buffer))
    {
        return false;
    }
    
    //用户已解决的。不管答案是否正确都执行此操作,防止是重判,而导致信息不及时刷新。
    OJSprintf(buffer, Statement::UpdateUserSolved3.c_str(), 
        input.UserName.c_str(), JudgeCode::Accept, input.UserName.c_str());
    if(!sqlDriver_->query(buffer))
    {
        return false;
    }

    //题目提交数量
    OJSprintf(buffer, Statement::UpdateProblemSubmit2.c_str(), input.ProblemID, input.ProblemID);
    if(!sqlDriver_->query(buffer))
    {
        return false;
    }

    //题目通过的数量
    OJSprintf(buffer, Statement::UpdateProblemAccept3.c_str(), 
        input.ProblemID, JudgeCode::Accept, input.ProblemID);
    if(!sqlDriver_->query(buffer))
    {
        return false;
    }
    
    //如果未通过,写错误原因

    if(output.Result == JudgeCode::CompileError)//如果编译错误
    {
        OJSprintf(buffer, Statement::DeleteCompile1.c_str(), input.SolutionID);
        if(!sqlDriver_->query(buffer))
        {
            return false;
        }

        OJString compileError = output.CompileError;
        sqlDriver_->escapeString(compileError);

        OJSprintf(buffer, Statement::InsertCompile2.c_str(), 
            input.SolutionID, compileError.c_str());
        if(!sqlDriver_->query(buffer))
        {
            return false;
        }
    }
    else if(output.Result == JudgeCode::RuntimeError)//运行时错误
    {
        OJSprintf(buffer, Statement::DeleteRuntime1.c_str(), input.SolutionID);
        if(!sqlDriver_->query(buffer))
        {
            return false;
        }

        OJString runtimeError = output.RunTimeError;
        sqlDriver_->escapeString(runtimeError);

        OJSprintf(buffer, Statement::InsertRuntime2.c_str(), 
            input.SolutionID, runtimeError.c_str());
        if(!sqlDriver_->query(buffer))
        {
            return false;
        }
    }

    return true;
}