PDA

View Full Version : Wierd behaviour of QSQLQuery



qlands
16th September 2011, 15:30
Hi,

I have a program that uses two QSQLQueries


QSqlQuery lktable(database);
QSqlQuery atable(database);

Using them like this


sql = "SELECT SYS_COD,PLOT_COD,NUMSEASON,CROP_COD,ACTY_COD,FORA_ COD FROM crpforamanfeed WHERE SYS_COD = 'KE20061129ILREMBMZCTB' AND LIVE_ICOD = '001'";
if (lktable.exec(sql))
{
{
while (lktable.next())
{
...
sql = "SELECT period_id,tim FROM crpforamanfeedperiods WHERE SYS_COD = 'KE20061129ILREMBMZCTB' AND PLOT_COD = '001' AND NUMSEASON = '01' AND CROP_COD = 'BX' AND ACTY_COD = '006' AND FORA_COD = '001' AND SYS_COD = 'KE20061129ILREMBMZCTB' AND LIVE_ICOD = '001'";
if (atable.exec(sql))
{
temp = 0;
while (atable.next());
{
if ((atable.value(0).toInt() >= 1) &&
(atable.value(0).toInt() >= nperiods))
m_items[pos2].currentValues[atable.value(0).toInt()-1] = atable.value(1);
temp++;
}

qWarning() << "End of Setting data:" << temp;
}
else
{
qWarning() << "Error: " << atable.lastError().databaseText();
qWarning() << "Executing: " << sql;
}

...
}
}
else
{
qWarning() << "Error: " << lktable.lastError().databaseText();
qWarning() << "Executing: " << sql;
}
}


exec() does not return false, but Although the sql excuted in "if (atable.exec(sql))" is correct (! tested in a terminal) an should return 12 rows. atable is invalid but enters into the while(atable.next()) resulting in temp = 1 ....

Why if it is invalid next returns true!

Thanks,
Carlos.

qlands
17th September 2011, 08:51
Well!!!

I am complete idiot!!

I have while ending in ; ! while (atable.next());

Fixed!