PDA

View Full Version : QIBASE and problem with transaction



Hostel
21st May 2013, 13:01
Qt 4.8.4, Firebird 2.5.

I have code like this:


// model - QSqlRelationalTableModel
if( model->database().transaction() )
{
int indexDialog;

if( _index == 0 )
{
model->insertRow( model->rowCount() );
indexDialog = model->index( model->rowCount() - 1, 0 ).row();
}
else
{
indexDialog = _index;
}

DokumentDialog dialog( model, indexDialog, this );
if( dialog.exec() == QDialog::Accepted )
{
if( dialog.submit() )// call mapper->submit();
{
if( model->database().commit() )
{
qDebug() << BOOST_CURRENT_FUNCTION;
qDebug() << "\ttransaction successful commit";
}
else
{
qDebug() << BOOST_CURRENT_FUNCTION;
qDebug() << "\ttransaction faild to commit";
qDebug() << "\t" << model->lastError().text();

model->database().rollback();
model->revert();
}
}
else
{
qDebug() << BOOST_CURRENT_FUNCTION;
qDebug() << "\tsubmit from mapper error";
qDebug() << "\t" << model->lastError().text();

model->database().rollback();
model->revert();
}
}
else
{
model->database().rollback();
model->revert();
}
}


First insert/update is ok. Second and next returns me an error:


submit from mapper error
"invalid transaction handle (expecting explicit transaction start) Unable to execute query"

When I comment transaction, commit, rollback then insert and updates works ok, but I want to solve transaction issue.