Results 1 to 7 of 7

Thread: get data from sqlite database

  1. #1
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default get data from sqlite database

    Hi everyone,
    I am using qt 4.7 to access sqlite database. In my database one coloum is there whic contains binary data.
    My database has 5000 rows.I am using QSqlQuery to exexute query and get data from database.But for 5000 record i have to move in a loop which is time consuming .
    Qt Code:
    1. query.record().value(0).toByteArray()
    To copy to clipboard, switch view to plain text mode 

    Plsease tell me a better way so that i can get data within some miliseconds.

    Thanks.

  2. #2
    Join Date
    Mar 2012
    Location
    Lesotho
    Posts
    33
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: get data from sqlite database

    You do not have to move in a loop,You can write sql statement that retrieves only data you want so that your query contains that data.


    Added after 19 minutes:


    You do not have to move in a loop,You can write sql statement that retrieves only data you want so that your query contains that data.
    Last edited by kito; 11th June 2013 at 10:20.

  3. #3
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get data from sqlite database

    Thanks.
    But my problem is i have to check some condition for each data.

  4. #4
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Smile Re: get data from sqlite database

    You are working with QSqlQuery :

    Try this:

    Qt Code:
    1. // EXAMPLE
    2. QSqlQuery query;
    3. QString queryString = "SELECT date FROM TABLE";
    4.  
    5. query.exec(queryString);
    6.  
    7. while (query.next()) {
    8. QSqlRecord record = query.record();
    9. qDebug() << "Date : " << record.value(date).toString();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Hope this will help you.


    CHEERS !!!

  5. #5
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get data from sqlite database

    Yes, I am doing the same thing.But reading form QSqlQuery is time consuming.
    So i want a better method for reading from database.
    Or Is loading all value to an arry is the only better option for fast reading ?

  6. #6
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: get data from sqlite database

    you may store your sqlRecord to QVariantList which will reduce your time to fetch data from database every time.
    This will help you if you want to ONE TIME FETCH data from database.

    Storing data to array will not keep the track of the data.
    So store all the QSqlRecorddata in QVariantMap,
    And append the Map in QVariantList ::

    Qt Code:
    1. QVariantMap myClass::record2map(const QSqlRecord &record)
    2. {
    3. QVariantMap map;
    4.  
    5. for(int index = 0; index < record.count(); ++index) {
    6. QString key = record.fieldName(index);
    7. QVariant value = record.value(index);
    8.  
    9. map.insert(key, value);
    10. }
    11.  
    12. return map;
    13. }
    To copy to clipboard, switch view to plain text mode 


    CHEERS..

    !!!

  7. #7
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get data from sqlite database

    Thanks for reply.
    I tried using array.It was faster.
    But i think what you suggest is better.

Similar Threads

  1. Select data from database SQLite error - Help please!
    By sousadaniel7 in forum Qt Programming
    Replies: 13
    Last Post: 26th April 2012, 10:46
  2. SQLite database problem in some SO
    By anoraxis in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2012, 23:54
  3. Sqlite Database
    By sabbu in forum Qt Programming
    Replies: 5
    Last Post: 16th May 2011, 13:07
  4. connection to sqlite database using qt4
    By elimelick in forum Newbie
    Replies: 0
    Last Post: 25th July 2010, 14:53
  5. SQLITE database problems
    By phoenix in forum Newbie
    Replies: 3
    Last Post: 30th April 2007, 21:38

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.