Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QtSql database execution SLOW
Forum Update on Monday, May 27th 2025

[SOLVED] QtSql database execution SLOW

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chrisw01
    wrote on 13 May 2014, 15:51 last edited by
    #1

    Hi everyone, I wish to pull a json file from the web and stick its content into a SQL database of type QSQLITE which I have done successfully its just super slow. I have read that you can nest the commands within a 'begin' and a 'end' statement to eliminate repetitive executions here is a snip of one of the loops.

    @
    for(int loop2 = 0; loop2 < (int)(sizeof(displayLocationElements) / sizeof(QString)); loop2++) {
    QString str("display_location.");
    str.append(displayLocationElements[loop2]);
    sql.bindValue(":var", str);
    sql.bindValue(":value",QString(jsonSubMap[displayLocationElements[loop2]].toString()));
    sql.exec();
    }
    @

    If I comment out all the sql commands it takes less than 1/2 seconds to go through this whole function parsing the json code, with the sql commands it takes 12-14 seconds which I think is terrible since there is only 60-70 elements being processed. What is the best way to process all the data and only execute once completed.

    Thanks in advance...

    Chris

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 13 May 2014, 16:47 last edited by
      #2

      Hi,

      You already mentioned the solution:
      [quote author="Chrisw01" date="1399996287"]you can nest the commands within a 'begin' and a 'end' statement to eliminate repetitive executions[/quote]Add BEGIN and END to your code:
      @
      sql.exec("BEGIN");
      for(...) ...
      sql.exec("END");
      @

      It has nothing to do with Qt SQL. SQLite transactions are very slow (see http://www.sqlite.org/faq.html#q19 ). If you use BEGIN and END, you only make one transaction to INSERT everything. If you don't, then you make many transactions, because every INSERT makes a new transaction.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chrisw01
        wrote on 13 May 2014, 17:21 last edited by
        #3

        Thanks for pointing that out, I only had 1/2 the answer, when I used the BEGIN/END part I had commented out the internal execs and it wasn't updating the database, you still have to call .exec within the for loop it just doesn't process the transactions until the END is called.

        1 Reply Last reply
        0

        1/3

        13 May 2014, 15:51

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved