Results 1 to 3 of 3

Thread: QtSql: execBatch() with SELECT statements

  1. #1
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QtSql: execBatch() with SELECT statements

    I am not an expert SQL user and I do not have much experience with the QtSql Module, I hope I am not missing something obvious:

    I want to retrieve a list of blobs from my (sqlite) database with a batch command. But it does not work properly. isSelect() is not true for the query and I cannot get the results of the query.
    Am I using the command correctly? Or should I simply do consecutive exec() commands. Will that have an effect on the speed?

    Here is my sample code:
    Qt Code:
    1. QString query_string = QString(
    2. "SELECT my_blob_column FROM my_table WHERE id = ? ;"
    3. );
    4. q.prepare(query_string);
    5. q.addBindValue(ids_in_qvariantlist);
    6.  
    7. if (!q.execBatch()) {...}
    8.  
    9. qDebug() << q.isSelect(); // is false
    10.  
    11. while (q.next()) { // is never true
    12. qDebug() << q.value(0).toByteArray()
    13. }
    To copy to clipboard, switch view to plain text mode 

    edit:
    I am running Qt 4.5.3 on OpenSuse 11.2
    Last edited by herrmarder; 28th January 2010 at 13:08.

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtSql: execBatch() with SELECT statements

    Why don't you build a list of the ids you want to retrieve. (I assume, that its not just all or some simple subset...)

    Qt Code:
    1. QString idset = "(";
    2. for (int i=0;i < list.length();++i)
    3. {
    4. idset += QString::number(list.at(i));
    5. if (i < list.length()-1)
    6. idset += ",";
    7. }
    8. idset += ")";
    9.  
    10. q.exec("SELECT my_blob_column FROM my_table WHERE id in "+idset+";");
    11. while (q.next())
    12. {
    13. }
    14. ..
    To copy to clipboard, switch view to plain text mode 

    HIH

    Johannes

  3. #3
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtSql: execBatch() with SELECT statements

    Thank you Johannes,
    I have tried using execBatch() so much that I did not see the obvious workaround :-)
    Tobias

Similar Threads

  1. about Windows Ado and QtSql
    By lutins in forum General Programming
    Replies: 1
    Last Post: 1st September 2008, 20:04
  2. problem of QtSql
    By cresthong in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2008, 17:48
  3. a problem about QSqlQuery::execBatch()
    By yjyong1217 in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2008, 03:28
  4. QtSql and Windows Vista
    By imitrik in forum Qt Programming
    Replies: 1
    Last Post: 5th October 2007, 19:19
  5. reading fprintf statements from console in qt
    By KrishnaKishan in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2007, 10:00

Tags for this Thread

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.