Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT 5.14.2 not supporting for oracle query FOR UPDATE SKIP LOCKED



  • Dear QT forum,
    Please kindly help me . I am using Qt 5.14.2 , it is not supporting oracle query "FOR UPDATE SKIP LOCKED" The same Query working for QT 4.7.3. Please kindly help me. please find My code and query below Thank you so much in advance.
    Without UPDATE SKIP LOCKED it is working.

    With UPDATE SKIP LOCKED encountered the below error, same while retrying it is getting success.

    Log and error,
    QOCI driver is available!
    Open database successful
    "ORA-03114: not connected to ORACLE\nUnable to begin transaction"
    "failed to execute database query, ORA-03114: not connected to ORACLE\nUnable to execute statement"
    QOCIDriver::commitTransaction: Database not open
    nMinJobQueueID= 13370
    nMaxJobQueueID= 0
    nMinJobQueueID= 13371

    My code:
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    bool isAvailable = QSqlDatabase::isDriverAvailable("QOCI");
    if (isAvailable)
    qDebug() << "QOCI driver is available!";
    else {
    qDebug() << "QOCI driver is not available!";
    }
    QString msg;
    QSqlDatabase m_sqlDatabase = QSqlDatabase::addDatabase("QOCI", "conn1");
    m_sqlDatabase.setDatabaseName("localhost/orcl");
    m_sqlDatabase.setUserName("bms72user");
    m_sqlDatabase.setPassword("bms72user");
    if (!m_sqlDatabase.open())
    {
    qDebug() << m_sqlDatabase.lastError().text();
    }
    else
    {
    qDebug() << "Open database successful";
    }

    int m_nDBBioType = 2;
    int nAvailableSlot = 100;
    QString strJobCodeCondition = "JOBCODE = 0";
    QSqlQuery  sqlQuery(m_sqlDatabase);
    sqlQuery.setForwardOnly(true);
    QString strVIPSQL = QString("select JOBQUEUE_ID,JOBCODE,REFERENCE_ID,REQUEST_XML,TS_CREATED,SYSDATE,PRIORITY from FE_JOBQUEUE_LIVE where JOBQUEUE_ID>=13370 and JOBQUEUE_ID<=13375 order by JOBQUEUE_ID asc FOR UPDATE SKIP LOCKED");
    //QString strVIPSQL = QString("select JOBQUEUE_ID,JOBCODE,REFERENCE_ID,REQUEST_XML,TS_CREATED,SYSDATE,PRIORITY from FE_JOBQUEUE_LIVE where JOBQUEUE_ID>=13375 and JOBQUEUE_ID<=13375 order by JOBQUEUE_ID asc ");
    bool Found = false;
    while (1)
    {
    	if (!m_sqlDatabase.isOpen())
    		m_sqlDatabase.open();
    	if (!m_sqlDatabase.transaction())
    		qDebug() << ("transaction errr [%1]", m_sqlDatabase.lastError().text());
    	//	sqlQuery.prepare(strVIPSQL);
    	//	if (!sqlQuery.exec())
    
    	if (!sqlQuery.exec(strVIPSQL) || !sqlQuery.isSelect() || !sqlQuery.isActive())
    	{
    		msg = QString("failed to execute database query, %1").arg(sqlQuery.lastError().text());
    		qDebug() << msg;
    		m_sqlDatabase.close();
    	}
    	else
    	{
    		QSqlRecord record = sqlQuery.record();
    		//	qDebug() << ("sqlQuery size [%1]", sqlQuery.size());
    		while (sqlQuery.next())
    		{
    			int nMinJobQueueID = sqlQuery.value(0).toInt();
    			int nMaxJobQueueID = sqlQuery.value(1).toInt();
    			//qDebug() << ("nMinJobQueueID=%1,nMaxJobQueueID=%2", nMinJobQueueID, nMaxJobQueueID);
    			qDebug() << "nMinJobQueueID=" << nMinJobQueueID;
    			qDebug() << "nMaxJobQueueID=" << nMaxJobQueueID;
    			if ((nMinJobQueueID != 0) && (nMaxJobQueueID != 0))
    			{
    				bool bPendingJob = true;
    				return bPendingJob;
    			}
    			Found = true;
    			//break;
    		}
    	}
    	m_sqlDatabase.commit();
    	sqlQuery.clear();
    	//	qDebug() << "loop";
    	if (Found) break;
    }
    m_sqlDatabase.close();
    qDebug() << "Finished";
    return a.exec();
    

    }

    Thanks & Regards,
    Rajesh


Log in to reply