Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Mysql queries execute twice
QtWS25 Last Chance

[SOLVED] Mysql queries execute twice

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 7.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lloydqt
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      soroush
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Blizzard
        wrote on last edited by
        #3

        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

        Software Engineer | Aerospace & Defence

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lloydqt
          wrote on last edited by
          #4

          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();
          }@

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Blizzard
            wrote on last edited by
            #5

            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?

            Software Engineer | Aerospace & Defence

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DBoosalis
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lloydqt
                  wrote on last edited by
                  #8

                  Thanks Lukas Geyer.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved