[SOLVED] Mysql queries execute twice
-
wrote on 7 Jun 2012, 11:14 last edited by
Hi,
We are using Qt 4.8.1 with MySQL, the db server is running on another system. Whatever the SQL queries I give, it gets executed twice. I did a packet analysis using wireshark and it shows two SQL queries being sent to the server, so the problem is at my Qt client application.
I have downloaded mysql C connector for windows 7 32bit and installed (MySQL Connector C 6.0.2). Then compiled the Qt plugins with this using visual studio. The mysql dll I have is "libmysql.dll"
What could be the reason for this?
Thanks,
Lloyd
-
wrote on 7 Jun 2012, 16:12 last edited by
Well, it's hard to say without seeing code. Nevertheless, I would check my code in that case. You're sending sql statement twice :-P
-
wrote on 8 Jun 2012, 01:09 last edited by
If you don't post code the best chance you have of narrowing down the problem is throwing some debug outputs around your code, to see when/what is being executed
-
wrote on 8 Jun 2012, 04:41 last edited by
Here is a sample code fragment. I am clueless about this problem!
Thanks a lot,
Lloyd
@ QSqlDatabase db;
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.1.1");
db.setPort(3306);
db.setDatabaseName("test");
db.setUserName("root");
db.setPassword("");
QSqlQuery squery("insert into test_table values ('Test1',10)",db);
if(!squery.exec())
{
QSqlError err = squery.lastError();
}@ -
wrote on 8 Jun 2012, 05:11 last edited by
Well that code looks benign enough, I think the problem is outside of that snippet. Have you checked the "examples":http://qt-project.org/doc/qt-4.8/examples-sql.html Qt provides on using SQL?
-
wrote on 8 Jun 2012, 05:16 last edited by
Could this mysql code be in a slot, if so put a debug statement in it see if your slot is getting called twice.
-
wrote on 8 Jun 2012, 06:35 last edited by
bq. "QSqlQuery::QSqlQuery(const QString & query = QString(), QSqlDatabase db = QSqlDatabase())":http://qt-project.org/doc/qt-4.8/qsqlquery.html#QSqlQuery-2
Constructs a QSqlQuery object using the SQL query and the database db. If db is not specified, or is invalid, the application's default database is used. If query is not an empty string, it will be executed.You statement is executed once at construction due to passing a query to the constructor and once due to the call to QSqlQuery::exec().
-
wrote on 8 Jun 2012, 09:39 last edited by
Thanks Lukas Geyer.
2/8