Results 1 to 1 of 1

Thread: Slow Microsoft Access QSqlQuery (possible bug)

  1. #1
    Join Date
    May 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question Slow Microsoft Access QSqlQuery (possible bug)

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QSqlDatabase>
    3. #include <QSqlQuery>
    4.  
    5. #include <QDebug>
    6. #include <QTime>
    7.  
    8. int main(int argc, char *argv[]) {
    9.  
    10. QCoreApplication a(argc, argv);
    11.  
    12. QTime time;
    13. QString command;
    14.  
    15. command = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};";
    16. command += "FIL={MS Access};DBQ=C:/database.accdb";
    17.  
    18. QSqlDatabase sql = QSqlDatabase::addDatabase("QODBC3");
    19.  
    20. sql.setDatabaseName(command);
    21.  
    22. qDebug() << "open" << sql.open();
    23.  
    24. // Slow query
    25.  
    26. QSqlQuery query("SELECT name + 'x' FROM users", sql);
    27.  
    28. time.start();
    29.  
    30. while(query.next()) query.value(0);
    31.  
    32. qDebug() << "query1 (slow)" << QString::number(time.elapsed()) + "ms";
    33.  
    34. // Others slow queries:
    35. // SELECT 'x' FROM users
    36. // SELECT '' FROM users
    37. // SELECT CStr('x') FROM users
    38.  
    39. // Normal query
    40.  
    41. QSqlQuery query2("SELECT name FROM users", sql);
    42.  
    43. time.start();
    44.  
    45. while(query2.next()) query2.value(0);
    46.  
    47. qDebug() << "query2" << QString::number(time.elapsed()) + "ms";
    48.  
    49. return a.exec();
    50.  
    51. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. open true
    2. query1 (slow) "408ms"
    3. query2 "6ms"
    To copy to clipboard, switch view to plain text mode 
    The problem happen when I try select a virtual field (SELECT 'str') or a field concatenated with literal string (SELECT field + 'str').

    The database is only an example with one table (users), two fields (id, name) and 1000 records.

    Greetings and thanks.
    Attached Files Attached Files

Similar Threads

  1. Connect to Microsoft Access 2010 *.accdb file
    By FuNkDaDdY in forum Newbie
    Replies: 11
    Last Post: 26th April 2018, 09:43
  2. select and edit like Microsoft Access with cute sql?
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 19th December 2010, 12:37
  3. Trouble Connecting to Microsoft Access *.accdb files
    By FuNkDaDdY in forum Qt Programming
    Replies: 1
    Last Post: 10th November 2010, 11:18
  4. Replies: 10
    Last Post: 30th September 2010, 07:16
  5. how to connect to a microsoft access database?
    By mismael85 in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 10:25

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.