[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



  • 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



  • 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



  • 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?



  • Could this mysql code be in a slot, if so put a debug statement in it see if your slot is getting called twice.



  • 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().



  • Thanks Lukas Geyer.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.