Im using Qt 4.8.3 and the MySQL ODBC 3.51 Driver. The driver does not seem to support LastInsertId which I test like this:
db.driver()->hasFeature(QSqlDriver::LastInsertId)
I need it to find the auto increment id I just inserted
query.exec("INSERT INTO myTable (MyVal, Created) VALUES ('1', NOW())");
auto insertId = query.lastInsertId().toString();
What is the best workaround?
EDIT: there will be concurrent access to this table from multiple clients.
According to MySQL documentation, you can call:
after the insert query to get the latest id inserted for the current connection, even when using ODBC.
Use OUTPUT INSERTED.[Field Name] as in code below. Read the returned ID with next() function.
}
You could do something like:
to get the largest id in your table - this should be the one you just inserted.
If you are writing an application that can have multiple concurrent users you'll have to look into creating a lock on your table and then releasing the lock after you run this second query.