1
Considering the following table:
ID : int
Quantidade : smallint
PrecoUnitario : float(5,2)
I tested the following Query in Mysql Workbench:
SELECT ID, SUM(Quantity * Precounitario) FROM test GROUP BY ID;
And as expected it was executed correctly.
However, when I do the implementation in Qt and try to get the results is not possible:
qDebug() << "Correndo Teste...";
QSqlQuery query(myDB);
query.prepare(" SELECT ID, SUM(Quantidade * PrecoUnitario) FROM teste GROUP BY ID;");
if(!query.exec())
throw "Error";
else{
qDebug() << "Size: " << query.size();
while(query.next()){
qDebug() << query.value(0).toInt();
qDebug() << query.value(1).toFloat();
}
}
qDebug() << "Fim!";
That is, the table being filled with the following content:
| 1 | 3 | 1.00 |
| 1 | 3 | 2.00 |
| 2 | 3 | 3.00 |
The result of the implementation is:
Running Test...
Size: 2
End!
Although the size returned is 2, the cycle while is never run.
Strangely, by altering the PrecoUnitario
for int the problem goes away.
Is there any justification for what is happening?