Results 1 to 3 of 3

Thread: extract record from database

  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default extract record from database

    hi everyone,

    I am trying to extract data from a sqlite data base in embedded board.But it is taking 3 hours for 120510 records.My code is :

    Qt Code:
    1. QString str="select * from user20";
    2. query_model.setQuery(str);
    3.  
    4. i=0;
    5. while(query_model.record(i).value("Id").toByteArray()!="")
    6. {
    7. data+=query_model.record(i).value("Id").toByteArray();
    8. data=data+unit_sp;
    9. data +=query_model.record(i).value("Name").toByteArray();
    10. data=data+unit_sp;
    11. data +=query_model.record(i).value("Address").toByteArray();
    12. data +=record_sp;
    13.  
    14. i++;
    15. }
    To copy to clipboard, switch view to plain text mode 


    Is there any better way to extract or any thing extract is required ?

  2. #2
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: extract record from database

    I don't known better way but can suggest to try this code with simple optimization:

    Qt Code:
    1. QSqlQuery query("SELECT Id, Name, Address FROM user20");
    2. while(query.next())
    3. {
    4. data+=query.value(0).toByteArray();
    5. data+=unit_sp;
    6. data+=query.value(1).toByteArray();
    7. data+=unit_sp;
    8. data+=query.value(2).toByteArray();
    9. data+=record_sp;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Plz try it. It very interestingly for me how long it will be take

    And you can extract data in parts (for example every 1000 records). It help for minimization memory usage.
    Last edited by unit; 8th March 2011 at 15:18.
    Try read Qt documentation before ask stupid question.

  3. #3
    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: extract record from database

    what are you trying to achieve? To store all data in one QByteArray without and delimiter seems pretty nonsense to me. As a further improvement for speed, use the concat function in your sql, so you only have to query one field which will increase the performance.

Similar Threads

  1. Replies: 11
    Last Post: 24th February 2011, 18:51
  2. Replies: 7
    Last Post: 27th November 2010, 15:55
  3. Replies: 3
    Last Post: 4th August 2010, 18:51
  4. Replies: 2
    Last Post: 13th April 2010, 16:50
  5. Replies: 3
    Last Post: 26th March 2010, 04:32

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.