Example #1
0
// Generic exec().  A prepare should have been done already
bool NSqlQuery::exec() {
    bool indexPauseSave;
    bool indexRestoreNeeded = false;
    QLOG_DEBUG() << "Sending SQL:" << getLastExecutedQuery(*this);
    for (int i=1; i<1000; i++) {
        bool rc = QSqlQuery::exec();
        if (rc) {
            if (indexRestoreNeeded)
                global.indexRunner->pauseIndexing = indexPauseSave;
            return true;
        }
        if (lastError().number() != DATABASE_LOCKED)
            return false;
        if (i>DEBUG_TRIGGER) {
            QLOG_ERROR() << "DB Locked:  Retry #" << i;
        }

        if (i == INDEX_PAUSE_TRIGGER && this->db->getConnectionName() != "indexrunner") {
            QLOG_DEBUG() << "Pausing indexrunner due to db lock";
            indexPauseSave = global.indexRunner->pauseIndexing;
            indexRestoreNeeded = true;
            global.indexRunner->pauseIndexing=true;
        }


        // Print stack trace to see what is happening
        if (i==DEBUG_TRIGGER) {
            QLOG_DEBUG() << "Dumping stack due to DB lock limit of " << DEBUG_TRIGGER << " being reached.";
            global.stackDump();
        }

        QTime dieTime= QTime::currentTime().addSecs(1);
        while( QTime::currentTime() < dieTime )
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    }
    if (indexRestoreNeeded)
        global.indexRunner->pauseIndexing = indexPauseSave;
    return false;
}