Results 1 to 7 of 7

Thread: Bulk insert into SQLite

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Nov 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default Re: Bulk insert into SQLite

    I know this comment is old, but is it possible to improve performance using transactions? From what I understand from the sqlite performance comparison document (yes very old, but probably vaguely applicable) under normal circumstances the db file is opened and closed each time an insert is applied unless it is encapsulated in a transaction.

    Below is some pseudo code of what I mean;
    Qt Code:
    1. SQL>> BEGIN TRANSACTION; // execute as QSqlQuery
    2.  
    3. csv = FileParser::open( "somefile.csv", CSV );
    4.  
    5. while( current_record = csv.nextRecord() ) {
    6. QSqlQuery q( "INSERT INTO table (firstname,lastname,etc) VALUES (:firstname,:lastname,:etc)" );
    7.  
    8. q.bindValue( ":firstname", current_record[0] );
    9. q.bindValue( ":lastname", current_record[1] );
    10.  
    11. ...
    12.  
    13. if( !q.exec() ) throw RecordException; // or however you want to handle an error
    14. }
    15.  
    16. close( csv );
    17.  
    18. SQL>> COMMIT
    To copy to clipboard, switch view to plain text mode 
    I think the alternative and possibly preferred method maybe using QVariantList's with a prepared statement and execBatch() for the insert.

    Once you've loaded the data into the db, then grab the table using QSqlTableModel. Note it's just an idea, haven't actually tested it for performance. Hence the mashed code.

    Regards,

    Nate
    Last edited by natbobc; 16th November 2007 at 00:55. Reason: reformatted to look better

Similar Threads

  1. [Qt4.1] How to insert an image inside a Form?
    By Gonzalez in forum Qt Tools
    Replies: 5
    Last Post: 23rd September 2008, 11:20
  2. Insert QCheckBox into QTableView
    By wind in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2006, 16:15
  3. how to insert an ' in a database
    By jh in forum General Programming
    Replies: 3
    Last Post: 17th August 2006, 02:47
  4. insert a widget into a group "on-the-fly"
    By soul_rebel in forum Qt Programming
    Replies: 4
    Last Post: 15th January 2006, 00:29

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
  •  
Qt is a trademark of The Qt Company.