Hi guys:

I'm having a problem with QSqlQuery. I'm trying to insert a record to a database, like this:

Qt Code:
  1. QSqlDriver *driver = QSqlDatabase::database().driver();
  2. Q_CHECK_PTR(driver);
  3.  
  4. QSqlRecord record = driver->record(tableName);
  5. /* Here I fill the record with values */
  6.  
  7. QString smt = driver->sqlStatement(QSqlDriver::InsertStatement, tableName, record, false);
  8.  
  9. QSqlQuery query(smt);
  10. if (!query.exec())
  11. {
  12. QMessageBox::critical(this, qApp->applicationName(), tr("Error inserting into database. %1").arg(query.lastError().text()));
  13. return;
  14. }
To copy to clipboard, switch view to plain text mode 

Ok, the problem is that I get always a duplicate entry error: "Duplicate entry '47552' for key 'id' QMYSQL: Unable the execute query", but I'm sure that value doesn't exist. In fact, the record is inserted when query.exec() is executed (but I get the error anyways). The number differs everytime in +1 ('cause I'm getting it with a max(id)+1 query).

The primary key isn't autoincremental.

Any ideas?

Thanks!!