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. Strange behaviour of QSqlQuery
Forum Updated to NodeBB v4.3 + New Features

Strange behaviour of QSqlQuery

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 2.2k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    clochydd
    wrote on last edited by
    #2

    Hi, what is your query.lastError?

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

      It is :

      "Driver not loaded Driver not loaded"

      1 Reply Last reply
      0
      • C Offline
        C Offline
        clochydd
        wrote on last edited by
        #4

        As the other queries work, this messages seems to be misleading.
        I suggest to look at the QString for your query by using qDebug().
        Probably this may be useful for you:
        @
        QString s = "INSERT INTO [dbo].[Pesee] ...";
        query.prepare(s);
        if (!query.exec()) {
        QMessageBox::warning(this, "ERR", "Error in query!\n" + query.lastError().text(), QMessageBox::Ok);
        qDebug() << s;

        @

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

          That's not that finally -_-

          I test the call of this query in a basic program and it work.

          Actually, I just saw that in my original program, two of the arguments are null (= 0) and can't work because of the relation with other table I guess...
          I'll fix it before anything else and see what happen after that.

          Thanks anyway ^^

          1 Reply Last reply
          0
          • C Offline
            C Offline
            clochydd
            wrote on last edited by
            #6

            You're welcome.
            Have you considered to work with QSqlQuery::bindValue? This method is more transparent and easier to debug.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              Basch006
              wrote on last edited by
              #7

              I tried to use this at the beginning, but I got some problems. I followed some tutorial about that but nothing worked so I changed my queries in that way :/

              1 Reply Last reply
              0
              • C Offline
                C Offline
                clochydd
                wrote on last edited by
                #8

                I use it like this:
                @
                query = QSqlQuery(db);
                QString s = "UPDATE mytable SET\n"
                "field1 = :p01, field2 = :p02\n"
                "WHERE fieldidx = :pID;";
                query.prepare(s);
                // WHERE clause:
                query.bindValue(":pID", ui->lineEditID->text());
                // SET fields:
                query.bindValue(":p01", ui->lineEdit01->text());
                query.bindValue(":p02", ui->lineEdit02->text());

                if (!query.exec()) {
                // show lastError:
                qDebug() << query.lastError();
                // show QString of query:
                qDebug() << s;
                }
                @

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Basch006
                  wrote on last edited by
                  #9

                  Is there a difference of performance/speed between the two methods ?

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    clochydd
                    wrote on last edited by
                    #10

                    I did not test it up to now.
                    But I am working with very large sql queries and I am absolutely satisfied with the performance (with both methods!).

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      Basch006
                      wrote on last edited by
                      #11

                      I'll try again the bindValue so ^^

                      thx for your replies ;-)

                      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