[SOLVED] Mysql queries execute twice
-
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
-
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();
}@ -
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?
-
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().