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 Updated to NodeBB v4.3 + New Features

[SOLVED] QtSql database execution SLOW

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views 1 Watching
  • 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 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
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on 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 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

        • Login

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