"No query executed" is the QT Error Code -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.
-
@Sachin-Bhatt How does the query look like (use https://doc.qt.io/qt-6/qsqlquery.html#executedQuery to see what is really executed)?
-
@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 toSELECT * FROM mytable WHERE id = 1
and then toSELECT * FROM mytable
. If the latter does not work maybe you don't havemytable
.