FILE *OpenTable(char *table,char *mode)
{
char    filename[512];
FILE    *fp;

    LockTable(table,LOCK_NORMAL);

    sprintf(filename,"%s.dat",table);
    fp=fopen(filename,mode);

    return(fp);
}
Exemple #2
0
int kGUIDBRecord::NextKey(void)
{
    int last;
    kGUIDbQuery *q;

    LockTable();
    m_db->UpdateLocks();

    q=new kGUIDbQuery(m_db,"SELECT %s from %s ORDER BY %s DESC LIMIT 0,1",m_keyname.GetString(),m_tablename.GetString(),m_keyname.GetString());
    if(q->GetNumRows())
        last=atoi(q->GetRow()[0])+1;
    else
        last=0;
    delete q;
    return(last);
}
Exemple #3
0
void MainWindow::StartJudging(int row, int column)
{
    if (is_locked) return;

    Global::g_is_judge_stoped = false;

    board_table->ClearHighlighted();
    board_table->horizontalHeader()->setSectionsMovable(false);
    board_table->horizontalHeader()->setSortIndicatorShown(false);
    board_table->horizontalHeader()->setSortIndicator(-1, Qt::AscendingOrder);
    board_table->setSelectionMode(QAbstractItemView::NoSelection);

    detail_table->StartLastJudgeTimer();
    detail_table->ClearDetail();

    LockTable();

    ui->action_configure->setEnabled(false);
    ui->action_set_list->setEnabled(false);
    ui->action_export->setEnabled(false);
    ui->action_refresh->setEnabled(false);
    ui->action_judge_selected->setEnabled(false);
    ui->action_judge_unjudged->setEnabled(false);
    ui->action_judge_all->setEnabled(false);
    ui->action_stop->setEnabled(true);

    judge_thread = new JudgeThread(row, column, this);

    connect(judge_thread, &JudgeThread::titleDetailFinished, detail_table, &DetailTable::onAddTitleDetail);
    connect(judge_thread, &JudgeThread::noteDetailFinished,  detail_table, &DetailTable::onAddNoteDetail);
    connect(judge_thread, &JudgeThread::pointDetailFinished, detail_table, &DetailTable::onAddPointDetail);
    connect(judge_thread, &JudgeThread::scoreDetailFinished, detail_table, &DetailTable::onAddScoreDetail);

    connect(judge_thread, &JudgeThread::itemJudgeFinished,   board_table, &BoardTable::onSetItemUnselected);
    connect(judge_thread, &JudgeThread::labelTextChanged,    board_table, &BoardTable::onUpdateLabelText);
    connect(judge_thread, &JudgeThread::sumLabelChanged,     board_table, &BoardTable::onUpdateSumLabel);
    connect(judge_thread, &JudgeThread::problemLabelChanged, board_table, &BoardTable::onUpdateProblemLabel);

    if (row == -1) // Judge selected
    {
        for (int i = 0; i < Global::g_contest.player_num; i++)
            for (auto j : Global::g_contest.problem_order)
                if (board_table->item(i, j + 2)->isSelected())
                    judge_thread->AppendProblem(i, j + 2);
    }
    else if (row == -2) // Judge unjudged
    {
        for (int i = 0; i < Global::g_contest.player_num; i++)
            for (auto j : Global::g_contest.problem_order)
                if (Global::g_contest.players[Global::GetLogicalRow(i)]->ProblemLabelAt(j)->State() == ' ')
                {
                    judge_thread->AppendProblem(i, j + 2);
                    board_table->item(i, j + 2)->setSelected(true);
                }
    }
    else if (column <= 1) // Judge one player's all problems
    {
        for (auto j : Global::g_contest.problem_order)
            board_table->item(row, j + 2)->setSelected(true);
    }
    else if (column > 1) // Judge one
        judge_thread->AppendProblem(row, column);

    QEventLoop* eventLoop = new QEventLoop(this);
    connect(judge_thread, &QThread::finished, eventLoop, &QEventLoop::quit);
    judge_thread->start();
    eventLoop->exec();
    delete eventLoop;
    delete judge_thread;

    UnlockTable();

    board_table->horizontalHeader()->setSectionsMovable(true);
    board_table->setSelectionMode(QAbstractItemView::ExtendedSelection);

    if (Global::g_is_contest_closed) return;

    ui->action_configure->setEnabled(true);
    ui->action_set_list->setEnabled(true);
    ui->action_export->setEnabled(true);
    ui->action_refresh->setEnabled(true);
    ui->action_judge_selected->setEnabled(true);
    ui->action_judge_unjudged->setEnabled(true);
    ui->action_judge_all->setEnabled(true);
    ui->action_stop->setEnabled(false);

    this->activateWindow();

    Global::g_contest.SaveResultCache();
}
Exemple #4
0
bool kGUIDBRecord::Save(void)
{
    unsigned int i;
    unsigned int e;
    int numchanged;
    bool changed;
    bool where;
    bool uselimit;
    kGUIString update;
    kGUIString field;
    kGUIDBRecordEntry *re;
    const char *errormsg;

    assert(m_tablename.GetLen()!=0,"Name not defined for table, call SetTableName(name)!");

    /* locate using old key */
    /* make sure all fields at the same as before changed */
    /* if any are diffent, then return changed by other user error code, unlock table */
    /* update fields that are different */
    /* unlock table */

    update.Alloc(8192);
    field.Alloc(1024);

    for(e=0; e<m_numentries; ++e)
    {
        re=m_entries.GetEntry(e);

        if(re->m_delete==true)
        {
            uselimit=true;
            where=true;
            changed=true;
            update.SetString("DELETE FROM ");
            update.Append(m_tablename.GetString());
        }
        else if(re->m_new==true)
        {
            where=false;
            uselimit=false;
            update.SetString("INSERT ");
            update.Append(m_tablename.GetString());

            update.Append(" SET ");
            changed=false;
            for(i=0; i<m_numfields; ++i)
            {
                if(changed==true)
                    update.Append(", ");
                update.Append(GetFieldName(i));
                update.Append("='");

                m_db->EncodeField(&re->m_newfieldvalues[i],&field);
                update.Append(field.GetString());
                update.Append("'");
                changed=true;
            }
        }
        else	/* update an existing record */
        {
            update.SetString("UPDATE ");
            update.Append(m_tablename.GetString());

            where=true;
            uselimit=true;
            update.Append(" SET ");
            changed=false;
            for(i=0; i<m_numfields; ++i)
            {
                if(strcmp(re->m_newfieldvalues[i].GetString(),re->m_fieldvalues[i].GetString()))
                {
                    if(changed==true)
                        update.Append(", ");
                    update.Append(GetFieldName(i));
                    update.Append("='");

                    m_db->EncodeField(&re->m_newfieldvalues[i],&field);
                    update.Append(field.GetString());
                    update.Append("'");
                    changed=true;
                }
            }
        }

        if(changed==true)
        {
            /* does this table have a unique primary key? */
            if(where==true)
            {
                update.Append(" WHERE ");
                if(m_numprikeyfields)
                {
                    unsigned int f;

                    for(i=0; i<m_numprikeyfields; ++i)
                    {
                        f=m_prikey.GetEntry(i);
                        if(i)
                            update.Append("AND ");
                        update.Append(GetFieldName(f));
                        update.Append("='");
                        m_db->EncodeField(&re->m_fieldvalues[f],&field);
                        update.Append(field.GetString());
                        update.Append("' ");
                    }
                }
#if 0
                if(m_unique==true)
                {
                    update.Append(m_keyname.GetString());
                    update.Append("='");
                    update.Append(m_key.GetString());
                    update.Append("'");
                }
#endif
                else
                {
                    for(i=0; i<m_numfields; ++i)
                    {
                        if(i)
                            update.Append("AND ");
                        update.Append(GetFieldName(i));
                        update.Append("='");
                        m_db->EncodeField(&re->m_fieldvalues[i],&field);
                        update.Append(field.GetString());
                        update.Append("' ");
                    }
                }
            }

            /* this is necessary as there could be multiple matches */
            if(uselimit==true)
                update.Append(" LIMIT 1");

            /* lock table */
            LockTable();
            m_db->UpdateLocks();

            mysql_query(m_db->GetConn(),update.GetString());

            if(m_db->GetTrace())
                m_db->GetTrace()->ASprintf("->%s\n",update.GetString());

            errormsg=mysql_error(m_db->GetConn());
            if(errormsg[0])
                assert(false,errormsg);

            numchanged=(int)mysql_affected_rows(m_db->GetConn());
            assert(numchanged==1,"Error,number of records changed should have been one!");

            /* fields were sucessfully written, copy new fields over previous ones */
            /* hmmm, deleted entries? */
            for(i=0; i<m_numfields; ++i)
            {
                re->m_new=false;
                if(strcmp(re->m_newfieldvalues[i].GetString(),re->m_fieldvalues[i].GetString()))
                    re->m_fieldvalues[i].SetString(re->m_newfieldvalues[i].GetString());
            }
            /* remove lock from this table */
            UnLockTable();
            m_db->UpdateLocks();
        }
    }

    /* delete all entries that are flagged for deletion */
    i=0;
    for(e=0; e<m_numentries; ++e)
    {
        re=m_entries.GetEntry(e-i);
        if(re->m_delete)
        {
            delete re;
            m_entries.DeleteEntry(e-i);
            ++i;	/* ajust for scrolling entries */
        }
    }
    m_numentries-=i;	/* update number of entries */

    return(true);	/* ok! */
}