Results 1 to 5 of 5

Thread: strange problem for a if condition and Sqlite data base insertion

  1. #1
    Join Date
    Dec 2010
    Posts
    41
    Thanks
    12

    Question strange problem for a if condition and Sqlite data base insertion

    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... ?
    Qt Code:
    1. void datareceiver::insertdb()
    2. {
    3. timer8->stop();
    4. for(int p = 0; p < temperaturedata.count();p++)
    5. {
    6. QVector<QString> *v111 = new QVector<QString>();
    7. finaldatabuff << v111;
    8. //for(rd = 0 ; rd < 550;rd++)
    9. //{
    10. for(int q = 0; q < temperaturedata[p]->count(); q++)
    11. {
    12. finaldatabuff[finaldatabuff.count()-1]->append(temperaturedata[p]->at(q));
    13. columncount++; // incremented untill 550
    14.  
    15. }
    16. }
    17.  
    18. if(columncount == 550) // when columncount=550 insert 550 channels the data into the db .
    19. {
    20. m_query.exec("begin transaction Trans");
    21. QTime startTime = QTime::currentTime();
    22. for (int i = 0; i < finaldatabuff.count(); ++i)
    23. {
    24. QString sQuery = "insert into thdata";
    25. sQuery += " values (";
    26. for (int j = 0; j < finaldatabuff[i]->count(); ++j)
    27. sQuery += QString("%1").arg(finaldatabuff[i]->at(j)) + ", ";
    28. sQuery.remove(sQuery.length() - 2, 2);
    29. sQuery += ")";
    30. q.exec(sQuery);
    31. if(!m_query.exec(sQuery))
    32. {
    33. qDebug() << m_query.lastError().text();
    34. }
    35. }
    36.  
    37. m_query.exec("commit transaction Trans");
    38. columncount=0;
    39. for(int i = 0; i < finaldatabuff.size(); ++i)
    40. delete finaldatabuff[i];
    41. finaldatabuff.clear();
    42.  
    43. for(int i = 0; i < temperaturedata.size(); ++i)
    44. delete temperaturedata[i];
    45. temperaturedata.clear();
    46. timer8->start(2000);
    47. }
    48. }
    To copy to clipboard, switch view to plain text mode 

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

    thank you,

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: strange problem for a if condition and Sqlite data base insertion

    Do you mean that even when columncount equals 550, the code isn't executed?

  3. #3
    Join Date
    Dec 2010
    Posts
    41
    Thanks
    12

    Default Re: strange problem for a if condition and Sqlite data base insertion

    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,.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: strange problem for a if condition and Sqlite data base insertion

    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.

  5. #5
    Join Date
    Dec 2010
    Posts
    41
    Thanks
    12

    Default Re: strange problem for a if condition and Sqlite data base insertion

    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

Similar Threads

  1. Qt to Sqlite data insertion doubt.
    By rex in forum Qt Programming
    Replies: 15
    Last Post: 16th December 2010, 13:31
  2. Replies: 0
    Last Post: 17th November 2010, 01:29
  3. Replies: 0
    Last Post: 4th December 2008, 06:48
  4. QTable - Data Base Problem
    By esq in forum Qt Tools
    Replies: 9
    Last Post: 28th May 2007, 00:08
  5. program for working with Data Base(i need it)
    By banakil in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 23:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.