0

I have a table that supposed to record changes, deletion and additions to the Database via QT application. But by looking at the data it seems that only records the first selection for the table. Everything works with the addition, deletion or changes is just the recording of the action correctly.

I have a table that is constructed this way:

  model = new QSqlTableModel(this);
  model->setTable("user");
  model->setEditStrategy(QSqlTableModel::OnManualSubmit);
  model->select();

At the save button I have the following:

void UserInformation::on_save_clicked()
{
  model->submitAll();
  QString lastCommand=model->query().lastQuery();
  qDebug() << lastCommand;
  QSqlQuery query;
  query.prepare("insert into access (iduser,action) values (:iduser, :action)");
  query.bindValue(":iduser",workData->userID);
  query.bindValue(":action",lastCommand);
  query.exec(); 
}

This is the result, even when i change or add a record:

"SELECT `iduser`, `email`, `passwd`, `privilege`, `remainder`, `active` FROM user"

I can see on the database the changes being posted.

Is there anyway to get the last command to the database?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dan3460
  • 95
  • 3
  • 13
  • https://stackoverflow.com/questions/5777409/how-to-get-last-prepared-and-executed-query-using-qsqlquery – john elemans Aug 24 '17 at 19:48
  • Thanks John for that comment but the link deals with preparing a query and getting the actual place holders. My problem is with the query executed by the model. If you see i'm capturing the last executed query right after the "model->submitall()" statement. – Dan3460 Aug 24 '17 at 20:06
  • I have been doing some testing trying to solve this problem and i think i starting to understand what is going on. Because the all the queries are handled by the tablemodel, as soon as you invoke the submit all, the model issues a select statement to repopulate the table with any changes that have been made. So even when the submitall() may have failed, the subsequent select will always succeed. Is this correct? – Dan3460 Aug 24 '17 at 22:06

0 Answers0