Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. "No query executed" is the QT Error Code -1.
QtWS25 Last Chance

"No query executed" is the QT Error Code -1.

Scheduled Pinned Locked Moved Unsolved Game Development
3 Posts 3 Posters 380 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.
  • Sachin BhattS Offline
    Sachin BhattS Offline
    Sachin Bhatt
    wrote on last edited by
    #1

    I was working on a project that required me to use Natural Link in SQL with QT Development to link two tables. I used these columns as the join condition because the tables have numerous columns with identical names.

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("mydatabase");
    db.setUserName("myusername");
    db.setPassword("mypassword");
    
    if (db.open()) {
        QSqlQuery query;
        query.prepare("SELECT * FROM mytable WHERE id = :id");
        query.bindValue(":id", 1);
        
        if (query.exec()) {
            // Do something with the query results
        } else {
            qDebug() << "Error executing query:" << query.lastError().text();
            qDebug() << "Error code:" << query.lastError().number();
        }
        
        db.close();
    } else {
        qDebug() << "Error opening database:" << db.lastError().text();
        qDebug() << "Error code:" << db.lastError().number();
    }
    

    When I ran the query, however, I received an error notice with the number 1052, indicating that the query had confusing column names. I've read online from this doc but I don't understand the example they give.

    When I try to run a SQL query using the QT programming framework, I get the error code -1 "No query executed". This error occurs when the SQL query fails to run for whatever reason, such as a syntax mistake or a problem with the database connection.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • Sachin BhattS Sachin Bhatt

      I was working on a project that required me to use Natural Link in SQL with QT Development to link two tables. I used these columns as the join condition because the tables have numerous columns with identical names.

      QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
      db.setHostName("localhost");
      db.setDatabaseName("mydatabase");
      db.setUserName("myusername");
      db.setPassword("mypassword");
      
      if (db.open()) {
          QSqlQuery query;
          query.prepare("SELECT * FROM mytable WHERE id = :id");
          query.bindValue(":id", 1);
          
          if (query.exec()) {
              // Do something with the query results
          } else {
              qDebug() << "Error executing query:" << query.lastError().text();
              qDebug() << "Error code:" << query.lastError().number();
          }
          
          db.close();
      } else {
          qDebug() << "Error opening database:" << db.lastError().text();
          qDebug() << "Error code:" << db.lastError().number();
      }
      

      When I ran the query, however, I received an error notice with the number 1052, indicating that the query had confusing column names. I've read online from this doc but I don't understand the example they give.

      When I try to run a SQL query using the QT programming framework, I get the error code -1 "No query executed". This error occurs when the SQL query fails to run for whatever reason, such as a syntax mistake or a problem with the database connection.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Sachin-Bhatt How does the query look like (use https://doc.qt.io/qt-6/qsqlquery.html#executedQuery to see what is really executed)?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Sachin BhattS Sachin Bhatt

        I was working on a project that required me to use Natural Link in SQL with QT Development to link two tables. I used these columns as the join condition because the tables have numerous columns with identical names.

        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setDatabaseName("mydatabase");
        db.setUserName("myusername");
        db.setPassword("mypassword");
        
        if (db.open()) {
            QSqlQuery query;
            query.prepare("SELECT * FROM mytable WHERE id = :id");
            query.bindValue(":id", 1);
            
            if (query.exec()) {
                // Do something with the query results
            } else {
                qDebug() << "Error executing query:" << query.lastError().text();
                qDebug() << "Error code:" << query.lastError().number();
            }
            
            db.close();
        } else {
            qDebug() << "Error opening database:" << db.lastError().text();
            qDebug() << "Error code:" << db.lastError().number();
        }
        

        When I ran the query, however, I received an error notice with the number 1052, indicating that the query had confusing column names. I've read online from this doc but I don't understand the example they give.

        When I try to run a SQL query using the QT programming framework, I get the error code -1 "No query executed". This error occurs when the SQL query fails to run for whatever reason, such as a syntax mistake or a problem with the database connection.

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

        @Sachin-Bhatt
        QSqlQuery::prepare() returns a result. Check it, especially while developing and you don't know what is going on.
        Change your query first to SELECT * FROM mytable WHERE id = 1 and then to SELECT * FROM mytable. If the latter does not work maybe you don't have mytable.

        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