Results 1 to 4 of 4

Thread: fast quering

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default fast quering

    what is the fastest method to select a query over thounds of datas. When I query a select statement to a mssql database it is very slow. I do it like this
    Qt Code:
    1. QSqlDatabase usedDB = QSqlDatabase::database("mydb") ;
    2. QSqlQuery q("my select statement",usedDB);
    3. q.setForwardOnly(true);
    4. while (q.next())
    5. {
    6. //do my stuff
    7. }//while
    To copy to clipboard, switch view to plain text mode 

    is it possible that odbc connections are damn slow ???

    P.S.: qt sdk 4.6(mingw) xp sp3

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: fast quering

    setForwardOnly must be called before using exec():
    Qt Code:
    1. QSqlQuery q(usedDB);
    2. q.setForwardOnly(true);
    3. q.exec("My statement");
    To copy to clipboard, switch view to plain text mode 
    Other than that it depends on the code represented by '//Do my stuff'.

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

    codeman (29th December 2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: fast quering

    hmm thanks for that tip/correction

    perhaps it is faster to set a query to a model and iterate over the model? have anbody some expierinces with this???

  5. #4
    Join Date
    Dec 2009
    Location
    Romania, Iasi
    Posts
    18
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: fast quering

    Quote Originally Posted by codeman View Post
    hmm thanks for that tip/correction

    perhaps it is faster to set a query to a model and iterate over the model? have anbody some expierinces with this???
    I do not recommend you to retrieve specific data from an sql model if you just need to sort out only some simple select statements. Use directly QSqlQuery::exec() or QSqlQuery::execBatch().
    I especially insist on this, if you're using a remote database connection. The model/view approach works very poor remotely.

  6. The following user says thank you to vcernobai for this useful post:

    codeman (30th December 2009)

Similar Threads

  1. fast drawing in Qt
    By franco.amato in forum Qt Programming
    Replies: 0
    Last Post: 23rd November 2009, 21:22
  2. Replies: 2
    Last Post: 10th August 2009, 09:45
  3. QGraphicsView and fast moving objects
    By deMarco in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2009, 11:07
  4. Fast plotting widget
    By nemesis in forum Qt Programming
    Replies: 0
    Last Post: 30th June 2008, 10:12
  5. Qt3 more fast than Qt4 ?
    By commarmi in forum Qt Programming
    Replies: 11
    Last Post: 14th September 2007, 14:36

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.