PDA

View Full Version : QT + Sqlite not working



BrainStorm
10th August 2010, 20:47
I need to use sqlite databases with Qt, and data submiting is not working.
I've connected a button click to this:

void submit()
{
if(!model->database().driver()->hasFeature(QSqlDriver::Transactions))
qDebug() << "sqlite driver doesn't support transactions";
if(model->database().transaction())
{
if(model->submitAll())
{
model->query().finish();
if(model->database().commit())
{
model->query().exec();
commitBtn->setEnabled(false);
return;
}
}
}
model->database().rollback();
QMessageBox::information(
this,
tr("Database error"),
model->database().lastError().text());
}
I've once tried without the query stop stuff but no success, two days since i've started searching around a way but nothing. I hope you guys can help me, thanks in advance, and sorry my bad english.

Lykurg
10th August 2010, 22:19
Have you tried it without the transaction? Because I think submitAll() also uses transactions and they may interfere. Just a wild guess...

And you call always
model->database().rollback();! That is also not the best solution.

BrainStorm
10th August 2010, 23:39
Have you tried it without the transaction? Because I think submitAll() also uses transactions and they may interfere. Just a wild guess...

And you call always
model->database().rollback();! That is also not the best solution.

I've tried:

void submit()
{
if(model->submitAll())
{
//model->database().transaction();
if(model->database().commit())
{
commitBtn->setEnabled(false);
}
else
QMessageBox::information(
this,
tr("Database error"),
model->database().lastError().text());
}
else
QMessageBox::information(
this,
tr("Database error"),
model->database().lastError().text());
}

and the 'commit' returns false, showing the following error:
cannot commit - no transaction is active, unable to commit transaction.
Uncommenting that line works ok, 'commit' returns true, but no database change, nothing happens..

:(:(

BrainStorm
11th August 2010, 01:52
I solved the problem!
I was doing "model->removeCollumn(0)" to hide id's collumn, and this was crashing the submitAll(), the right way to hide a collumn is to do "view->hideCollumn(0)" :):)
thanks Lykurg's for trying to figure it out with me.