Re: Bulk insert into SQLite
Yesterday .... I imported a sqlite import file .sql from 36Mb on 3 minute moore as 250'000
(500 Mb ram , 3GHz intel )
row ... but... i not use qt sqlite plugin i use a static lib .... same on window / mac /linux
http://svn.sourceforge.net/viewvc/qt..._sqlite_table/
IMO comment http://sourceforge.net/forum/forum.p...orum_id=301849
Re: Bulk insert into SQLite
Is there a Qt way to do this ?
Thanks a lot
Re: Bulk insert into SQLite
Quote:
Originally Posted by
munna
Is there a Qt way to do this ?
Thanks a lot
Oh.. yes... (I can write only qt4 i owerflow heavy c++ books ;-) ) you import the the cvs file and convert to SQL - insert to sqlite and on the table model display only 100 row or 50 row ... button next >> prev <<< edit ready...
Or other elegant method ..... only by window ...
1- you make a new odbc connection to file cvs connect (setup file name path ecc.) all on plugin qt odbc ....
a small snip to qt4 next & prev button have a look
http://qtforum.de/forum/viewtopic.php?t=2431 simple & fast
You need ony a QTableWidget & 2 button (next & prev)
Or a little moore work and You build a fast static lib
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;
Code:
SQL>> BEGIN TRANSACTION; // execute as QSqlQuery
csv = FileParser::open( "somefile.csv", CSV );
while( current_record = csv.nextRecord() ) {
QSqlQuery q
( "INSERT INTO table (firstname,lastname,etc) VALUES (:firstname,:lastname,:etc)" );
q.bindValue( ":firstname", current_record[0] );
q.bindValue( ":lastname", current_record[1] );
...
if( !q.exec() ) throw RecordException; // or however you want to handle an error
}
close( csv );
SQL>> COMMIT
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
Re: Bulk insert into SQLite
Quote:
Originally Posted by
natbobc
I know this comment is old, but is it possible to improve performance using transactions?
If SQLite docs say so, then it might work. This really depends on the DBMS and other databases might like different constructs.
For tips on PostgreSQL read this: http://www.depesz.com/index.php/2007...t-as-possible/
Quote:
Code:
while( current_record = csv.nextRecord() ) {
QSqlQuery q
( "INSERT INTO table (firstname,lastname,etc) VALUES (:firstname,:lastname,:etc)" );
...
q.bindValue( ":firstname", current_record[0] );
...
If you pass the query string to QSqlQuery constructor, it will execute it immediately --- you have to use prepare() if you have placeholders:
Code:
q.prepare( "INSERT INTO table (firstname,lastname,etc) VALUES (:firstname,:lastname,:etc)" );
while( current_record = csv.nextRecord() ) {
...
q.bindValue( ":firstname", current_record[0] );
...
Also by moving call to prepare() out of the loop, you can save a bit of time (esp. in case of nasty queries).
Re: Bulk insert into SQLite