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

MYsql exec() query probleme

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 3.1k Views 3 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.
  • G gdaboy
    17 Nov 2017, 19:16

    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 ;
    }

    
    
    M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 17 Nov 2017, 19:23 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 17 Nov 2017, 19:59
    0
    • G gdaboy
      17 Nov 2017, 19:16

      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 ;
      }

      
      
      J Offline
      J Offline
      JonB
      wrote on 17 Nov 2017, 19:47 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
      • M mrjj
        17 Nov 2017, 19:23

        @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 17 Nov 2017, 19:59 last edited by
        #6

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

        J 1 Reply Last reply 17 Nov 2017, 20:21
        0
        • G gdaboy
          17 Nov 2017, 19:59

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

          J Offline
          J Offline
          JonB
          wrote on 17 Nov 2017, 20:21 last edited by
          #7

          @gdaboy So have you tried what I wrote above?

          G 1 Reply Last reply 18 Nov 2017, 11:48
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 17 Nov 2017, 21:11 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

            J 1 Reply Last reply 17 Nov 2017, 23:07
            2
            • S SGaist
              17 Nov 2017, 21:11

              Hi,

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

              J Offline
              J Offline
              JonB
              wrote on 17 Nov 2017, 23:07 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
              • J JonB
                17 Nov 2017, 20:21

                @gdaboy So have you tried what I wrote above?

                G Offline
                G Offline
                gdaboy
                wrote on 18 Nov 2017, 11:48 last edited by
                #10

                @JNBarchan
                yes i've tried that also

                J 1 Reply Last reply 18 Nov 2017, 11:52
                0
                • G gdaboy
                  18 Nov 2017, 11:48

                  @JNBarchan
                  yes i've tried that also

                  J Offline
                  J Offline
                  JonB
                  wrote on 18 Nov 2017, 11:52 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
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 18 Nov 2017, 23:26 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 20 Nov 2017, 09:39 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

                      13/13

                      20 Nov 2017, 09:39

                      • Login

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