Page 2 of 2 FirstFirst 12
Results 21 to 35 of 35

Thread: Multi Column selection from a Sqlite table

  1. #21
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Multi Column selection from a Sqlite table

    hi sir , I have been trying to get the right output but , not able to figure out why data is not been extracted..

    Qt Code:
    1. QSqlQuery sq1("SELECT "+ colNames +" FROM thdata where rowid = " + QString::number(rowcnt) + "");
    2.  
    3. while(sq1.next())
    4. {
    5. for (int i = 0; i < tepdata.size(); ++i)
    6. {
    7. tepdata.push_back(sq1.value(i).toString());
    8. }
    9. }
    10. if(tepdata.count()!= 0)
    11. {
    12. rowcnt++;
    13. }
    14. qDebug() << sq1.lastError().text();
    15. qDebug() << colNames;
    16. qDebug()<< tepdata;
    To copy to clipboard, switch view to plain text mode 
    this is what i am exactly getting in debug window sir. There is no sql error but the data is not yet retrieved from the db.
    Qt Code:
    1. " "
    2. "Thermo0, Thermo1, Thermo2, Thermo3, Thermo4, Thermo5"
    To copy to clipboard, switch view to plain text mode 
    Sir will it be a problem if i try to access a table when it is updating cause the table from which i am trying to retrieve is been updated with data every second, but by the time i access the db there would be already many rows of data so i should be able to retrieve the initial rows. don't know why its not working sir

  2. #22
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Multi Column selection from a Sqlite table

    Your query is right but for the for loop you have wrong conditions - at least it seems so to me. Shouldn't tepdata.size() be the size of the columns?

  3. The following user says thank you to Lykurg for this useful post:

    nagabathula (25th December 2010)

  4. #23
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Multi Column selection from a Sqlite table

    Hello sir , that was it the problem is solved.. Thank you so much sir you came as Santa for me this Christmas..

    i am getting the right out put in qtableView but in the qdebug i can see many white spaces, but i am getting the right out only in the QTableview sir.

    Qt Code:
    1. "Thermo1, Thermo2, Thermo3, Thermo4, Thermo5, Thermo6, Thermo7, Thermo8, Thermo9, Thermo10, Thermo11, Thermo12"
    2. QVector("180", "180", "190", "180", "180", "180", "180", "180", "180", "180", "180", "170", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "")
    3. QVector("TE 5000_1", "TE 5000_2", "TE 5000_3", "TE 5000_4", "TE 5000_5", "TE 5000_6", "TE 5000_7", "TE 5000_8", "TE 5000_9", "TE 5000_10", "TE 5000_11", "TE 5000_12")
    To copy to clipboard, switch view to plain text mode 

    regards

  5. #24
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Multi Column selection from a Sqlite table

    Seems that you loop still is not right. The "spaces" indicate that you loop to far. So how do you determine the size of your query result?

    Two options use the size of the last debuged QVector or use QSqlQuery::record() and count().

  6. #25
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Multi Column selection from a Sqlite table

    hi ,
    Qt Code:
    1. QSqlQuery sq1("SELECT "+ colNames +" FROM thdata where rowid = " + QString::number(rowcnt)); // removed the last +"" its not needed
    2. qDebug()<< "SELECT "+ colNames +" FROM thdata where rowid = " + QString::number(rowcnt);
    3. //run the above qDebug() output in ur Database, then see whether u have any results
    4. if(!sq1.exec()) // did u forget to add sq1.exec()??
    5. {
    6. //put error here
    7. }
    8. while(sq1.next())
    9. {
    10. //The following is ur logical mistake, as Lykurg said.
    11. // consider tepData's size = 0 at first; then ur code inside forloop is never executed . since i<0
    12. //whats the purpose of adding &checking tepdata in forloop here?
    13. for (int i = 0; i < tepdata.size(); ++i)
    14. //for(int i=0;i<indexCount.size();i++) //this should be right
    15. {
    16. tepdata.push_back(sq1.value(i).toString());
    17. }
    18.  
    19. }
    20. if(tepdata.count()!= 0)
    21. {
    22. rowcnt++;
    23. }
    24. qDebug() << sq1.lastError().text();
    25. qDebug() << colNames;
    26. qDebug()<< tepdata;
    To copy to clipboard, switch view to plain text mode 

    hope it helps
    Bala

  7. The following user says thank you to BalaQT for this useful post:

    nagabathula (25th December 2010)

  8. #26
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Multi Column selection from a Sqlite table

    Hello Bala sir thanks a lot , the problem is solved.. You particularly helped me in solving the problem.. I have another doubt sir. I am retrieving continuous data which i am saving in hexadecimal format into the database. which i retrieve back before any manipulation the data has a frame id and 20 channels of data and frame id again and 20 channels of data and so on. I am not sure if i have used the right container. The data to the QString datstr; is push back from the db before to the aligndata() function here.
    Qt Code:
    1. void datareceiver::aligndata()
    2. {
    3. qDebug()<< datstr;
    4.  
    5. newdat.append(datstr.mid(posi, 80)); // QString newdat;
    6. posi+=92; // posi =12; initial condition
    7. datstr.clear();
    8.  
    9.  
    10. qDebug()<< newdat;
    11.  
    12. for(int k=0; k<newdat.size(); k+=4)
    13. {
    14. rawdata.append(newdat.mid(k, 4)); //QList rawdata ,splitting the string to get each channel data here.
    15. }
    16. // some more data manipulation happening after this
    17. }
    To copy to clipboard, switch view to plain text mode 

    i am trying to remove 03b702200000 from the frame so that i have only the data. i.e remove first 12 chars and keep the next 80 and then remove 12 chars from 80th position the second frame id and keep the next 80 chars. This is the data present in datstr from qDebug.

    Full Frame
    Qt Code:
    1. 03b702200000010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    2. 03b702200001010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    3. 03b702200002010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    4. 03b702200003010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    5. 03b70220000001210121012101210121012101210121012101210121012101210121012101210121012101210121
    6. 03b70220000101210121012101210121012101210121012101210121012101210121012101210121012101210121
    7. 03b70220000201210121012101210121012101210121012101210121012101210121012101210121012101210121
    8. 03b70220000301210121012101210121012101210121012101210121012101210121012101210121012101210121
    To copy to clipboard, switch view to plain text mode 

    This is what i get in QDebug After removing the frame id.. instead of shifting to the next data after the first 3 frames, the data is repeating more then what is actually there in the frame.. i am calling the aligndata() with a timer every 500 milli seconds.
    this is the data from newdat; The frame Id is removed but the data is repeated..I think the logic to remove the frame id is right but don't know why data is reapeted
    Qt Code:
    1. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    2. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    3. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    4. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    5. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    6. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    7. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    8. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    9. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    10. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    11. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    12. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    13. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    14. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    15. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    16. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    17. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    To copy to clipboard, switch view to plain text mode 

    thank you sir,

  9. #27
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multi Column selection from a Sqlite table

    I am not sure if i have used the right container. The data to the QString datstr; is push back from the db before to the aligndata() function here.
    it depends on ur need. if u r using more string operations use QStringList.

    This is ur Data
    Qt Code:
    1. 03b702200000010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    2. 03b702200001010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    3. 03b702200002010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    4. 03b702200003010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    5. 03b70220000001210121012101210121012101210121012101210121012101210121012101210121012101210121
    6. 03b70220000101210121012101210121012101210121012101210121012101210121012101210121012101210121
    7. 03b70220000201210121012101210121012101210121012101210121012101210121012101210121012101210121
    8. 03b70220000301210121012101210121012101210121012101210121012101210121012101210121012101210121
    To copy to clipboard, switch view to plain text mode 

    and u need the following output right?
    Qt Code:
    1. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    2. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    3. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    4. 010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a010a
    5. 01210121012101210121012101210121012101210121012101210121012101210121012101210121
    6. 01210121012101210121012101210121012101210121012101210121012101210121012101210121
    7. 01210121012101210121012101210121012101210121012101210121012101210121012101210121
    8. 01210121012101210121012101210121012101210121012101210121012101210121012101210121
    To copy to clipboard, switch view to plain text mode 


    I think the logic to remove the frame id is right but don't know why data is reapeted
    pls stop the timer. and then see whats in datastr @ first [in aligndata] and
    whats in newdat.

    Bala
    Last edited by BalaQT; 27th December 2010 at 12:12.

  10. #28
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Restricting specified chars into db.

    Hello bala sir.. thanks for reply. I did check up sir, actually i was't not clearing the QString container so that was happening, I have cleared all the containers i have used.. I changed it from QString to QByteArray since all the data i have is some temperature data not string, i was not aware i though QString was best to use.. Sir how can i restrict like 2944 chars of data in each row when i am pushing the data into the data base.. cause the alignment of the data which i am doing miss's.. the number of chars stored in every row of the data base varies.. How can i restrict 2944 chars in every row of the db.. ? i have just attached a snap shot of the data which is stored in the db so that you know wat i am trying to tell.. the first row has some 3 master frames of data and from the second row its not like tat.. there is no data missing but when i am retrieving, i think it happens every row wise.. So once the first row ends the second row has the data contained from the previous row it might not be the start of the frame cause of this i am missing the count which i am using to align the data when i am retrieving the data back from the db. By restricting the number of chars to 2499 into every row in the db i will be saving exactly one master frame every row.. I wont have a count problem when i am aligning the data. ..
    Right now i am jus doing this i am receiving data on rs232 and searching for the start of the frame which is 03b702200000 and then i am appending data from there.. How can i only dump 2944 chars every row sir.. ?

    Qt Code:
    1. void datareceiver::myexport1()
    2. {
    3. QByteArray data = (QByteArray::fromRawData(buff,numBytes));
    4. //stfram.resize(2944); Program Breaks when i try to resize the QString strfram to 2944 chars
    5. if(datrow ==0)
    6.  
    7. {
    8. QString pattern("03b702200000");
    9. QStringMatcher matcher(pattern);
    10. pos = matcher.indexIn(oldat, pos);
    11. datrow++;
    12. }
    13. for(np = pos; np<oldat.size(); np++)
    14. {
    15. stfram.append(oldat.at(np));
    16. pos++;
    17. }
    18.  
    19. QString sq("INSERT INTO Bulkdb values(%1, %2)");
    20. sq = sq.arg(rcount)
    21. .arg("'" + stfram + "'");
    22. m_query.exec(sq);
    23. rcount++;
    24. stfram.clear();
    25. }
    To copy to clipboard, switch view to plain text mode 

    this is how i am saving data into the data base, How could i restrict 2944 chars for every row in the db,i sud't lose any data also sir.. i tried using stfram.resize(2944); but it din work as i expected... I am calling this function at o milli sec
    Qt Code:
    1. connect(timer1, SIGNAL(timeout()), this, SLOT(myexport1()));
    2. timer1->start();
    To copy to clipboard, switch view to plain text mode 
    thank you
    Attached Images Attached Images
    Last edited by nagabathula; 28th December 2010 at 12:17.

  11. #29
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Restricting specified chars into db.

    How can i only dump 2944 chars every row....
    How could i restrict 2944 chars for every row in the db
    im not sure what u want ,
    if u want to resize in db, u can change the field width of the table. isnt it?
    but if u want to save only 2944 chars in table from code then
    Qt Code:
    1. QString sq("INSERT INTO Bulkdb values(%1, %2)");
    2. sq = sq.arg(rcount)
    3. .arg("'" + (strfram>2944)?stfram.left(2944):strfram + "'");
    To copy to clipboard, switch view to plain text mode 

    hope it helps,
    Bala

  12. #30
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Restricting specified chars into db.

    i will try both the approach's you told me sir.. Thank you so much .
    I am getting some 500 channels of data on rs232 sir, by trying to save 2944 char's i am trying to save one master frame in a row at a time.. all the 500 channels data is accommodated in 2944 chars sir.. I would't have don this if i din't have a problem when retrieving, when i am retrieving after the first master frame the second frame starts either in the first row only or in between the second row, Cause of this i am have a problem, i am trying to remove the frame id, i know the first 12 chars of each master frame has a frame id. Its fine in the first row but if a frame is continued to the second row from the first then i am having the problem removing it sir.. So in case i save exactly one master frame every row i wont have the problem of aligning the data.

    i will try what you have suggested any ways sir.

    thank you very much


    Added after 47 minutes:


    hello bala sir i am getting a error, not able to figure out what it is wrong..
    for this line sir
    .arg("'" + (stfram>2944)?stfram.left(2944):stfram + "'");

    'QString:perator`QNoImplicitBoolCast'' : cannot access private member declared in class 'QString'
    thank you
    Last edited by nagabathula; 29th December 2010 at 10:32.

  13. #31
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multi Column selection from a Sqlite table

    hi,
    it should be stfram.length()>2944

    Bala
    Last edited by BalaQT; 29th December 2010 at 12:06.

  14. #32
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Multi Column selection from a Sqlite table

    hello bala sir, i tried it but the code din work as expected, there was no data in the data base at all but i could see data in Debug sir i put a qDebug after the insertion query the data is shown but in the data base it is empty.. so i did it this way..
    Qt Code:
    1. if (stfram.length()>2944)
    2. newstr.append(stfram.left(2944));
    3.  
    4. QString sq("INSERT INTO Bulkdb values(%1, %2)");
    5. sq = sq.arg(rcount)
    6. .arg("'" + newstr + "'");
    7. newstr.clear();
    8. stfram.clear();
    9. m_query.exec(sq);
    10. rcount++;
    To copy to clipboard, switch view to plain text mode 
    but only one row of data is saved into the data base sir from the second row it shows as null.. the first row has exactly one master frame but from the second row it is empty.. wats wrong in my code sir. ?

    thank you
    Last edited by nagabathula; 29th December 2010 at 18:39.

  15. #33
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Multi Column selection from a Sqlite table

    sir is this the right way to set the column width.. i tried this but a error is there, don't know if its right syntax.
    Qt Code:
    1. QString sq("INSERT INTO fulldb values(%1, %2)");
    2. sq("SET COLUMN ChannelData WIDTH 2944");
    3. sq = sq.arg(rcount)
    4. .arg("'" + newstr + "'");
    To copy to clipboard, switch view to plain text mode 


    thank you

  16. #34
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multi Column selection from a Sqlite table

    hi,

    Qt Code:
    1. m_query.exec(sq);
    2. qDebug()<<sq; // copy and run the output in database. and check the query is inserting rec properly.
    To copy to clipboard, switch view to plain text mode 

    sir is this the right way to set the column width.. i tried this but a error is there, don't know if its right syntax.
    The syntax is wrong.there is no option to alter column for resizing the table column in sqlite. when u create the table u can set the width.
    ex : create table mytab(framewidth integer(2994));


    hope it helps
    Bala

  17. #35
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Multi Column selection from a Sqlite table

    hello sir i sent you a mail, pls see your forum inbox.. I did try create table mytab(framewidth integer(2994)); but does't work as anticipated. .. I am still experimenting on the above though. I have sent a message also with the code to your inbox sir.

    thanks a lot for all the time you are giving me to help me solve my problem Bala sir.

Similar Threads

  1. Replies: 0
    Last Post: 5th October 2010, 08:50
  2. Replies: 0
    Last Post: 25th June 2008, 19:36
  3. Can a QListView support multi-column?
    By wesley in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 09:00
  4. QListWidget multi selection
    By user in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2008, 08:36
  5. Multi-selection Combo Box
    By EricF in forum Qt Programming
    Replies: 7
    Last Post: 7th November 2007, 08:15

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.