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. MYsql exec() query probleme

MYsql exec() query probleme

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 3.1k 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.
  • G gdaboy

    my qt project isn't adding anything to database , he can remove , display and edit all the date in my mysqlDatabase except adding without giving me any error ... and he can also add in onther tab in the same database

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #2

    @gdaboy
    You would have to show your code for this behaviour....

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gdaboy
      wrote on last edited by
      #3

      i am sorry ```
      //

      QSqlQuery qry ;
      qry.prepare("INSERT INTO flight arrive VALUES(:arrive')");
      qry.bindValue(":arrive","98");
      if(qry.exec()) {
      qDebug()<<"fine";
      return true ;
      }
      else{
      qDebug()<<qry.lastError().text() ;
      return false ;
      }

      
      
      mrjjM JonBJ 2 Replies Last reply
      0
      • G gdaboy

        i am sorry ```
        //

        QSqlQuery qry ;
        qry.prepare("INSERT INTO flight arrive VALUES(:arrive')");
        qry.bindValue(":arrive","98");
        if(qry.exec()) {
        qDebug()<<"fine";
        return true ;
        }
        else{
        qDebug()<<qry.lastError().text() ;
        return false ;
        }

        
        
        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #4

        @gdaboy
        Hi
        is table name really "flight arrive" ?
        If it really have a space, i think you need to quote it. please check mysql docs.
        Also syntax looks a bit odd ?

         QSqlQuery query;
            query.prepare("INSERT INTO employee (id, name, salary) "
                          "VALUES (:id, :name, :salary)");
            query.bindValue(":id", 1001);
        ...
        
        G 1 Reply Last reply
        0
        • G gdaboy

          i am sorry ```
          //

          QSqlQuery qry ;
          qry.prepare("INSERT INTO flight arrive VALUES(:arrive')");
          qry.bindValue(":arrive","98");
          if(qry.exec()) {
          qDebug()<<"fine";
          return true ;
          }
          else{
          qDebug()<<qry.lastError().text() ;
          return false ;
          }

          
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #5

          @gdaboy
          Try:
          qry.prepare("INSERT INTO flight (arrive) VALUES(:arrive')");
          ?

          And doesn't your current code show an error message rather than "fine" ?

          1 Reply Last reply
          1
          • mrjjM mrjj

            @gdaboy
            Hi
            is table name really "flight arrive" ?
            If it really have a space, i think you need to quote it. please check mysql docs.
            Also syntax looks a bit odd ?

             QSqlQuery query;
                query.prepare("INSERT INTO employee (id, name, salary) "
                              "VALUES (:id, :name, :salary)");
                query.bindValue(":id", 1001);
            ...
            
            G Offline
            G Offline
            gdaboy
            wrote on last edited by
            #6

            @mrjj
            no tbale name is only flight and all i want to do is add a something in arrive coloum

            JonBJ 1 Reply Last reply
            0
            • G gdaboy

              @mrjj
              no tbale name is only flight and all i want to do is add a something in arrive coloum

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #7

              @gdaboy So have you tried what I wrote above?

              G 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Hi,

                Unless it's a typo here you have a ' right after arrive that shouldn't be there.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                JonBJ 1 Reply Last reply
                2
                • SGaistS SGaist

                  Hi,

                  Unless it's a typo here you have a ' right after arrive that shouldn't be there.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #9

                  @SGaist ...which is why it would be so helpful if people posted code in fixed/monospace font here...

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @gdaboy So have you tried what I wrote above?

                    G Offline
                    G Offline
                    gdaboy
                    wrote on last edited by
                    #10

                    @JNBarchan
                    yes i've tried that also

                    JonBJ 1 Reply Last reply
                    0
                    • G gdaboy

                      @JNBarchan
                      yes i've tried that also

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #11

                      @gdaboy
                      You certainly need to remove the extraneous ' than @SGaist noticed in his post above.

                      I know from other SQLs that INSERT syntax is INSERT INTO <table> (<column1>, <column2>, ...) VALUES (<value1>, <value2>, ...), i.e. columns must be inside () as well as values. I don't know whether MySQL accepts the column list without (), so you may or may not need that also. Personally, I think it's clearer anyway to parenthesize them.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        You should also post the error message returned for your query.
                        Also, what version of Qt are you using ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gdaboy
                          wrote on last edited by
                          #13

                          thanks guy for helping
                          the probleme was in mysql engine !!! you have to add innobd engine to your table in mysql

                          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