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. Why QSqlQuery exec("exit") failed?
Forum Updated to NodeBB v4.3 + New Features

Why QSqlQuery exec("exit") failed?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 7.2k Views 4 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @flydragon said in Why QSqlQuery exec("exit") failed?:

    Is that SQL ?
    Looks like the quit command ?

    kshegunovK F 2 Replies Last reply
    1
    • mrjjM mrjj

      @flydragon said in Why QSqlQuery exec("exit") failed?:

      Is that SQL ?
      Looks like the quit command ?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #3

      @mrjj said in Why QSqlQuery exec("exit") failed?:

      Is that SQL ?

      It is not.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • F flydragon

        When connecting to MySQL DB, it can execute other general query SQL sentences, but cannot execute "exit" sentence? I want to know why !?

        K Offline
        K Offline
        koahnig
        wrote on last edited by
        #4

        @flydragon

        You need to give more details on your attempts instead of throwing some questions into the forum.

        If you have specific question on performing some queries why they are not working as expecxted, give some sample code to help others to understand.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        1
        • F Offline
          F Offline
          flydragon
          wrote on last edited by
          #5

          My query function is as following. It can execute general query sentences, but failed when executing "exit".

          void mysql::query(const char* queryStr)
          {
                  if(!thisdb.isOpen())
                  {
                      QMessageBox::warning(0,"mysql Query Error!","No Connection!");
                      return;
                  }
                  qDebug()<<"11\n";
                  QSqlQuery currquery(thisdb);
                  qDebug()<<"22\n";
                  if(queryResult)
                      delete queryResult;
                  qDebug()<<"33\n";
                  queryResult =new std::vector<QString>;
                  assert(queryResult!=nullptr);
                  if(!currquery.exec(queryStr))
                  {
                      queryValid =false;
                      QMessageBox::warning(0,"Sql Error","Sql Not Executed!");
                      return;
                  }
                  queryValid =true;
                  while(currquery.next())
                  {
                      queryResult->push_back(currquery.value(0).toString());
                  }
          }
          
          kshegunovK 1 Reply Last reply
          0
          • F flydragon

            My query function is as following. It can execute general query sentences, but failed when executing "exit".

            void mysql::query(const char* queryStr)
            {
                    if(!thisdb.isOpen())
                    {
                        QMessageBox::warning(0,"mysql Query Error!","No Connection!");
                        return;
                    }
                    qDebug()<<"11\n";
                    QSqlQuery currquery(thisdb);
                    qDebug()<<"22\n";
                    if(queryResult)
                        delete queryResult;
                    qDebug()<<"33\n";
                    queryResult =new std::vector<QString>;
                    assert(queryResult!=nullptr);
                    if(!currquery.exec(queryStr))
                    {
                        queryValid =false;
                        QMessageBox::warning(0,"Sql Error","Sql Not Executed!");
                        return;
                    }
                    queryValid =true;
                    while(currquery.next())
                    {
                        queryResult->push_back(currquery.value(0).toString());
                    }
            }
            
            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #6

            @flydragon said in Why QSqlQuery exec("exit") failed?:

            It can execute general query sentences, but failed when executing "exit".

            Because exit is not a general query sentence, it's a command for the mysql command line client, it's not part of SQL.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            2
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #7

              Best bet is that is not SQL and hence it do not understand it.

              :) @kshegunov , the one ms faster :)

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

                Hi,

                What is your query exactly ?

                The exit SQL keyword has a precise use, you can't just throw it around alone.

                And if your query fails then you should at least print the error return by QSqlQuery::lastError.

                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
                • mrjjM mrjj

                  @flydragon said in Why QSqlQuery exec("exit") failed?:

                  Is that SQL ?
                  Looks like the quit command ?

                  F Offline
                  F Offline
                  flydragon
                  wrote on last edited by
                  #9

                  @mrjj Yes, I want to quit the MySQL before destroy this MySQL connection.

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

                    Then just close the database connection with QSqlDatabase.

                    Aren't you mixing the mysql command line keywords and the SQL query language ?

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

                    F 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Then just close the database connection with QSqlDatabase.

                      Aren't you mixing the mysql command line keywords and the SQL query language ?

                      F Offline
                      F Offline
                      flydragon
                      wrote on last edited by
                      #11

                      @SGaist I'm sure the syntax is right, because I've input the same sentence "exit" or "quit" in the cmd and it works well. But when using QSqlQuery to execute "exit" or "quit", the lastError's text is
                      "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'quit' at line 1 QMYSQL: Unable to execute query".

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

                        So the answer is yes: you are in fact mixing the mysql command line tool keywords with the SQL Language itself.

                        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
                        1

                        • Login

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