Add progress dialog box for the import csv operation

This commit is contained in:
tabuleiro
2009-12-02 18:31:19 +00:00
parent 758e08e268
commit aaf2731ec4
2 changed files with 16 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
#include <qapplication.h>
#include <qimage.h>
#include <qpixmap.h>
#include <QProgressDialog>
/*
* Constructs a importCSVForm as a child of 'parent', with the
@@ -110,6 +111,9 @@ void importCSVForm::createButtonPressed()
}
}
QProgressDialog progress("Inserting data...", "Cancel", 0, curList.size());
progress.setWindowModality(Qt::ApplicationModal);
sql = "CREATE TABLE ";
sql.append(tabname);
sql.append(" (");
@@ -133,7 +137,7 @@ void importCSVForm::createButtonPressed()
{//avoid error on MSVC due to rollback label
//now lets import all data, one row at a time
for ( QStringList::Iterator ct = curList .begin(); ct != curList .end(); ++ct ) {
for ( int i=0; i < curList.size(); ++i ) {
if (colNum==0)
{
sql = "INSERT INTO ";
@@ -142,7 +146,7 @@ void importCSVForm::createButtonPressed()
}
//need to mprintf here
//sql.append(*ct);
char * formSQL = sqlite3_mprintf("%Q",(const char *) (*ct));
char * formSQL = sqlite3_mprintf("%Q",(const char *) curList[i]);
sql.append(formSQL);
if (formSQL) sqlite3_free(formSQL);
@@ -155,6 +159,9 @@ void importCSVForm::createButtonPressed()
sql.append(");");
if (!pdb->executeSQLDirect(sql)) goto rollback;
}
progress.setValue(i);
if (progress.wasCanceled()) goto rollback;
}
}
@@ -166,6 +173,7 @@ void importCSVForm::createButtonPressed()
return;
rollback:
progress.cancel();
QApplication::restoreOverrideCursor(); // restore original cursor
QString error = "Error importing data. Message from database engine: ";
error.append(pdb->lastErrorMessage);

View File

@@ -6,6 +6,7 @@
#include <qfile.h>
#include <q3filedialog.h>
#include <qmessagebox.h>
#include <QProgressDialog>
void DBBrowserTable::addField(int order, const QString& wfield,const QString& wtype)
{
@@ -714,7 +715,10 @@ QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char q
bool inescapemode = false;
int recs = 0;
*numfields = 0;
if ( file.open( QIODevice::ReadWrite ) ) {
QProgressDialog progress("Decoding CSV file...", "Cancel", 0, file.size());
progress.setWindowModality(Qt::ApplicationModal);
char c=0;
while ( c!=-1) {
c = file.getch();
@@ -759,6 +763,8 @@ QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char q
*numfields = result.count();
}
recs++;
progress.setValue(file.pos());
if (progress.wasCanceled()) break;
if ((recs>maxrecords)&&(maxrecords!=-1)) {
break;
}