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?
#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();
}
#include <QtGui/QApplication>
#include "MainWindow.h"
#include <QMetaType>
#include <QTextCodec>
#include <QSqlDatabase>
#include <QSqlQuery>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setUserName("root");
db.setPassword("password0");
db.setDatabaseName("fitnesscenter");
db.open();
QSqlQuery query("insert into users(fullname) values ('Someone')");
query.exec();
}
To copy to clipboard, switch view to plain text mode
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>
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>
To copy to clipboard, switch view to plain text mode
EDIT:
This post contains the right answer:
http://www.qtcentre.org/threads/4550...742#post206742
It is extremely unobvious!
Bookmarks