QSqlQuery with MySQL performs twicely (SOLVED)
Hi, I will be very glad to get a quick answer. I'm using QSqlQuery with QSqlDatabase with MySQL. I try to exec one query but client shows two entries in the table. Why?
Code:
#include <QtGui/QApplication>
#include "MainWindow.h"
#include <QMetaType>
#include <QTextCodec>
#include <QSqlDatabase>
#include <QSqlQuery>
int main(int argc, char *argv[])
{
db.setHostName("localhost");
db.setUserName("root");
db.setPassword("password0");
db.setDatabaseName("fitnesscenter");
db.open();
QSqlQuery query
("insert into users(fullname) values ('Someone')");
query.exec();
}
Code:
mysql> delete from users;
Query OK, 2 rows affected (0.04 sec)
mysql> select * from users;
+----+----------+----------+
| id | fullname | password |
+----+----------+----------+
| 39 | Someone | NULL |
| 40 | Someone | NULL |
+----+----------+----------+
2 rows in set (0.00 sec)
mysql>
EDIT:
This post contains the right answer:
http://www.qtcentre.org/threads/4550...742#post206742
It is extremely unobvious!
Re: QSqlQuery with MySQL performs twicely (SOLVED)
Firstly, I think you meant to link to a different thread.
Secondly, given that the behaviour of the constructor you used is documented QSqlQuery::QSqlQuery() I think it is obvious.