Fixes ported from Arca, fix slow times when importing from CSV (caused by logging lots of SQL statements)

This commit is contained in:
tabuleiro
2009-12-29 00:54:47 +00:00
parent 64fce1c254
commit 79b0efd3ba
4 changed files with 28 additions and 41 deletions

View File

@@ -884,6 +884,7 @@ void mainForm::executeQuery()
queryResultListView->setResizeMode(Q3ListView::AllColumns);
if(*tail==0) break;
if(err!=SQLITE_OK) break;
}
}
@@ -915,7 +916,8 @@ void mainForm::importTableFromCSV()
return;
}
if (db.getDirty())
// Not needed anymore due to nested savepoints
/* if (db.getDirty())
{
QString msg = "Database needs to be saved before the import operation.\nSave current changes and continue?";
if (QMessageBox::question( this, applicationName ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
@@ -924,7 +926,7 @@ void mainForm::importTableFromCSV()
} else {
return;
}
}
}*/
QString wFile = Q3FileDialog::getOpenFileName(
defaultlocation,

View File

@@ -128,12 +128,12 @@ void importCSVForm::createButtonPressed()
//declare local variables we will need before the rollback jump
int colNum = 0;
//begin a transaction, so we can rollback in case of any errors during importing
//begin a savepoint, so we can rollback in case of any errors during importing
//db needs to be saved or an error will occur
if (!pdb->executeSQLDirect(QString("BEGIN TRANSACTION RESTOREPOINT;"))) goto rollback;
if (!pdb->executeSQL(QString("SAVEPOINT CSVIMPORT;"), false, false)) goto rollback;
//execute the create table statement
if (!pdb->executeSQLDirect(sql)) goto rollback;
if (!pdb->executeSQL(sql, false, false)) goto rollback;
{//avoid error on MSVC due to rollback label
//now lets import all data, one row at a time
@@ -157,7 +157,7 @@ void importCSVForm::createButtonPressed()
} else {
colNum = 0;
sql.append(");");
if (!pdb->executeSQLDirect(sql)) goto rollback;
if (!pdb->executeSQL(sql, false, false)) goto rollback;
}
progress.setValue(i);
if (progress.wasCanceled()) goto rollback;
@@ -166,7 +166,8 @@ void importCSVForm::createButtonPressed()
}
//everything ok, just return
//if (!pdb->executeSQL(QString("COMMIT TRANSACTION RESTOREPOINT;"))) goto rollback;
//Do not commit, it will be done automatically on save
if (!pdb->executeSQL(QString("RELEASE CSVIMPORT;"))) goto rollback;
pdb->setDirtyDirect(true);
QApplication::restoreOverrideCursor(); // restore original cursor
accept();
@@ -179,7 +180,7 @@ void importCSVForm::createButtonPressed()
error.append(pdb->lastErrorMessage);
QMessageBox::warning( this, applicationName, error );
//we will uncomment this when SQLite support nested transactions
pdb->executeSQLDirect(QString("ROLLBACK TRANSACTION RESTOREPOINT;"));
pdb->executeSQL(QString("ROLLBACK TO SAVEPOINT CSVIMPORT;"), false, false);
}
void importCSVForm::preview()

View File

@@ -55,6 +55,14 @@ void DBBrowserDB::setDefaultNewData( const QString & data )
curNewData = data;
}
char * DBBrowserDB::GetEncodedQStringAsPointer( const QString & input)
{
if (curEncoding==kEncodingUTF8) return (char *) input.utf8().constData();
if (curEncoding==kEncodingLatin1) return (char *) input.latin1();
return (char *) input.constData();
}
QString DBBrowserDB::GetEncodedQString( const QString & input)
{
if (curEncoding==kEncodingUTF8) return input.utf8();
@@ -96,7 +104,7 @@ bool DBBrowserDB::open ( const QString & db)
lastErrorMessage = QString("no error");
err = sqlite3_open(GetEncodedQString(db), &_db);
err = sqlite3_open_v2(GetEncodedQString(db), &_db, SQLITE_OPEN_READWRITE, NULL);
if ( err ) {
lastErrorMessage = sqlite3_errmsg(_db);
sqlite3_close(_db);
@@ -123,7 +131,7 @@ bool DBBrowserDB::setRestorePoint()
if (!isOpen()) return false;
if (_db){
sqlite3_exec(_db,"BEGIN TRANSACTION RESTOREPOINT;",
sqlite3_exec(_db,"SAVEPOINT RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
@@ -135,7 +143,7 @@ bool DBBrowserDB::save()
if (!isOpen()) return false;
if (_db){
sqlite3_exec(_db,"COMMIT TRANSACTION RESTOREPOINT;",
sqlite3_exec(_db,"RELEASE RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
@@ -147,7 +155,7 @@ bool DBBrowserDB::revert()
if (!isOpen()) return false;
if (_db){
sqlite3_exec(_db,"ROLLBACK TRANSACTION RESTOREPOINT;",
sqlite3_exec(_db,"ROLLBACK TO SAVEPOINT RESTOREPOINT;",
NULL,NULL,NULL);
setDirty(false);
}
@@ -265,7 +273,7 @@ bool DBBrowserDB::dump( const QString & filename)
return true;
}
bool DBBrowserDB::executeSQL ( const QString & statement)
bool DBBrowserDB::executeSQL ( const QString & statement, bool dirtyDB, bool logsql)
{
char *errmsg;
bool ok=false;
@@ -273,32 +281,8 @@ bool DBBrowserDB::executeSQL ( const QString & statement)
if (!isOpen()) return false;
if (_db){
logSQL(statement, kLogMsg_App);
setDirty(true);
if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement),
NULL,NULL,&errmsg)){
ok=true;
}
}
if (!ok){
lastErrorMessage = QString(errmsg);
return false;
}else{
return true;
}
}
bool DBBrowserDB::executeSQLDirect ( const QString & statement)
{
//no transaction support
char *errmsg;
bool ok=false;
if (!isOpen()) return false;
if (_db){
logSQL(statement, kLogMsg_App);
if (logsql) logSQL(statement, kLogMsg_App);
if (dirtyDB) setDirty(true);
if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement),
NULL,NULL,&errmsg)){
ok=true;

View File

@@ -100,8 +100,7 @@ public:
bool revert ();
bool dump( const QString & filename);
bool reload( const QString & filename, int * lineErr);
bool executeSQL ( const QString & statement);
bool executeSQLDirect ( const QString & statement);
bool executeSQL ( const QString & statement, bool dirtyDB=true, bool logsql=true);
void updateSchema() ;
bool addRecord();
bool deleteRecord(int wrow);
@@ -120,6 +119,7 @@ public:
void logSQL(QString statement, int msgtype);
void setEncoding( int encoding );
void setDefaultNewData( const QString & data );
char * GetEncodedQStringAsPointer( const QString & input);
QString GetEncodedQString( const QString & input);
QString GetDecodedQString( const QString & input);
sqlite3 * _db;