PDA

View Full Version : strange problem for a if condition and Sqlite data base insertion



rex
18th December 2010, 21:16
Hello every one i have am trying to insert some 550 channels of data to sqlite db. This is the code i am using to update. every thing is but i am having a problem in the place where i am appending the data into the finaldatabuff, i am trying to increment columncount till 550 and then insert the 550 channels data into the db. But here even after the columncount counter cross's 550, the condition if(columncount == 550) is not satisfied and the query is not executed at all. .. in case i remove the if(columncount == 550) condition all the data is saved into the db but it is repeated.. what do you think is going wrong , why is the if condition not satisfied... ?


void datareceiver::insertdb()
{
timer8->stop();
for(int p = 0; p < temperaturedata.count();p++)
{
QVector<QString> *v111 = new QVector<QString>();
finaldatabuff << v111;
//for(rd = 0 ; rd < 550;rd++)
//{
for(int q = 0; q < temperaturedata[p]->count(); q++)
{
finaldatabuff[finaldatabuff.count()-1]->append(temperaturedata[p]->at(q));
columncount++; // incremented untill 550

}
}

if(columncount == 550) // when columncount=550 insert 550 channels the data into the db .
{
m_query.exec("begin transaction Trans");
QTime startTime = QTime::currentTime();
for (int i = 0; i < finaldatabuff.count(); ++i)
{
QString sQuery = "insert into thdata";
sQuery += " values (";
for (int j = 0; j < finaldatabuff[i]->count(); ++j)
sQuery += QString("%1").arg(finaldatabuff[i]->at(j)) + ", ";
sQuery.remove(sQuery.length() - 2, 2);
sQuery += ")";
QSqlQuery q;
q.exec(sQuery);
if(!m_query.exec(sQuery))
{
qDebug() << m_query.lastError().text();
}
}

m_query.exec("commit transaction Trans");
columncount=0;
for(int i = 0; i < finaldatabuff.size(); ++i)
delete finaldatabuff[i];
finaldatabuff.clear();

for(int i = 0; i < temperaturedata.size(); ++i)
delete temperaturedata[i];
temperaturedata.clear();
timer8->start(2000);
}
}

pls help me out tell me what could be going wrong. ..

thank you,

tbscope
18th December 2010, 21:24
Do you mean that even when columncount equals 550, the code isn't executed?

rex
19th December 2010, 05:55
Hello yea sir even when columncount = 550 that part of code is not executed. i checked the value of columncount it does increment, but it does't stop at 550 it keeps on incrementing,.

tbscope
19th December 2010, 07:07
Ok, so columncount is NOT 550, is it?

Your if structure is not inside the for loop, thus it will only execute if columncount is 550 when the for loop ends.
Since you say that columncount is bigger than 550, it is obvious that the if structure is not executed.

rex
19th December 2010, 07:15
Yes sir even after the columncount == 550, the IF condition does not execute.. the columncount keeps incrementing, i thought when the columncount is equal to 550 the data is inserted into 550 columns and the columncount is assigned 0 again, after the data is inserted.. in case i remove the if condition the data to be inserted is repeated in the db cause more then 550 columns of data is there in QVector.. How can i overcome this problem sir, is there a way to append 550 columns of data instead of what i am doing using a counter.

thank you