PDA

View Full Version : QSqlQuery: can't find any issues and should return data but isValid = false



ce_nort
22nd April 2016, 21:22
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)



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.

ChrisW67
22nd April 2016, 22:40
Try removing the semicolon from inside the query string.

ce_nort
26th April 2016, 14:26
Hi Chris,
I forgot to mention in my post, that was something that I had actually already tried. Still no luck.

Lesiok
26th April 2016, 15:01
What is the result of QSqlDatabase::database("gx_db").isValid() ?

ce_nort
26th April 2016, 16:04
Both isValid() and isOpen() return true.

ce_nort
26th April 2016, 18:59
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!