/*************************************************************************** * Copyright (C) 2005 by * * Jason Kivlighn (jkivlighn@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "convert_sqlite3.h" #include #include #include #include #include #include #include //FIXME: Some messages should be given to the user about success/failure, but that can't be done in the 0.8.x branch due to i18n. ConvertSQLite3::ConvertSQLite3( const TQString &db_file ) : TQObject(), error(false) { TQString file = db_file; if ( file.isEmpty() ) { TDEConfig *config = TDEGlobal::config(); config->setGroup("Server"); file = config->readEntry("DBFile"); } KProcIO *p = new KProcIO; p->setUseShell(true); //sqlite OLD.DB .dump | sqlite3 NEW.DB *p << "sqlite" << file << ".dump" << "|" << "sqlite3" << file+".new"; TQApplication::connect( p, SIGNAL(readReady(KProcIO*)), this, SLOT(processOutput(KProcIO*)) ); bool success = p->start( TDEProcess::Block, true ); if ( !success ) { kdDebug()<<"Conversion failed... unable to start TDEProcess"<readln(buffer) != -1 ) { error_str += buffer; } KMessageBox::error( 0, error_str ); error = true; p->ackRead(); } bool ConvertSQLite3::copyFile( const TQString &oldFilePath, const TQString &newFilePath ) { //load both files TQFile oldFile(oldFilePath); TQFile newFile(newFilePath); bool openOld = oldFile.open( IO_ReadOnly ); bool openNew = newFile.open( IO_WriteOnly ); //if either file fails to open bail if(!openOld || !openNew) { return false; } //copy contents uint BUFFER_SIZE = 16000; char* buffer = new char[BUFFER_SIZE]; while(!oldFile.atEnd()) { TQ_ULONG len = oldFile.readBlock( buffer, BUFFER_SIZE ); newFile.writeBlock( buffer, len ); } //deallocate buffer delete[] buffer; buffer = NULL; return true; } #include "convert_sqlite3.moc"