QSqlQuery: can't find any issues and should return data but isValid = false
Hello,
I have a QSqlQuery where query.isValid = false and query.size() = 0, but I can't figure out why. It was working fine a couple weeks ago (famous last words). I have checked and confirmed the following:
-DB is open.
-query.exec() = true
-query.lastError() = QSqlError("", "", "")
-SQL syntax is valid (query works fine and returns results when output with qDebug() and run in Sequel Pro; also changing or simplifying the query doesn't affect anything)
-There is data to be returned, so it is not that the query has no results (see above)
Code:
QString orderID
= appInfo
->orderID;
QString queryString
= "SELECT order_item.qty_ordered, order_item.sku, order_item.name, order_item.price FROM order_item JOIN order ON order_item.order_id = order.entity_id WHERE order_item.qty_ordered > 0 AND order.increment_id = '" + orderID
+ "';";
QSqlQuery query
(queryString,
QSqlDatabase::database("gx_db"));
// I have multiple DBs connected, just specifying which one here
while(query.next()) {
qDebug() << "Why isn't this showing up??";
QJsonObject obj;
obj.insert("qty", query.value("qty_ordered").toString());
obj.insert("sku", query.value("sku").toString());
obj.insert("description", query.value("name").toString());
obj.insert("salePrice", query.value("price").toString());
array.append(obj);
}
Any ideas? I'm stumped.
Re: QSqlQuery: can't find any issues and should return data but isValid = false
Try removing the semicolon from inside the query string.
Re: QSqlQuery: can't find any issues and should return data but isValid = false
Hi Chris,
I forgot to mention in my post, that was something that I had actually already tried. Still no luck.
Re: QSqlQuery: can't find any issues and should return data but isValid = false
What is the result of QSqlDatabase::database("gx_db").isValid() ?
Re: QSqlQuery: can't find any issues and should return data but isValid = false
Both isValid() and isOpen() return true.
Re: QSqlQuery: can't find any issues and should return data but isValid = false
This is looking like an issue with our test server that I was using. It works on our other server. So thanks for the trouble-shooting attempts, but it seems like a behind the scenes problem!