How to restore a backed up sqlite database ?
-
Hi,
QString strError; QString strPathSqlite; QString fileName = "Dump.sql"; QProcess p; p.setStandardOutputFile(fileName); p.setWorkingDirectory("/home/pi/git/"); strPathSqlite = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/sqlite3"); strPathSqlite.replace("\\","\\\\"); p.start(strPathSqlite + " /home/pi/bc.db < " + fileName); qDebug()<<strPathSqlite; qDebug()<<fileName; if (!p.waitForStarted() || !p.waitForFinished(-1) || (p.exitStatus() != QProcess::NormalExit)) { switch (p.error()) { case (QProcess::FailedToStart) : strError = tr("The process failed to start. Either the invoked " "program is missing, or you may have insufficient permissions to invoke the program."); break; case (QProcess::Crashed) : strError = tr("The process crashed some time after starting successfully."); break; case (QProcess::WriteError) : strError = tr("An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel."); break; case (QProcess::ReadError): strError = tr("An error occurred when attempting to read from the process. For example, the process may not be running."); break; default: strError = tr("An unknown error occurred."); } QMessageBox msgBox; msgBox.setWindowTitle(tr("!!!")); msgBox.setIcon(QMessageBox::Warning); msgBox.setText(strError); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); }
I Wrote this code, but this code not working properly for me.
I want to recover from a dumped SQLite database. this code
This code just restores the normal txt file at 0 bytes only, and also shows the dumped file as 0 bytes in size.
I don't know what is going wrong.
Any answers you know are welcome.Thank
-
@Ramkumar-Mohan said in How to restore a backed up sqlite database ?:
strPathSqlite.replace("\\","\\\\");
You are under Linux, right? (Would really help if you said so, I have to guess this from
"/home/pi/git/"
....) What in the world is this for?p.start(strPathSqlite + " /home/pi/bc.db < " + fileName);
Your command line contains a redirection symbol. You must run it through a shell to have that interpreted.
-
@Ramkumar-Mohan said in How to restore a backed up sqlite database ?:
It's working fine now,
And how did you achieve that?
-
I just ran the shell command via qprocess.
QProcess p;
p.setWorkingDirectory("/home/pi/git/Biochemistry-Updates/BCUID/");
p.start("sh",QStringList()<<"-c"<<"sudo sqlite3 /home/pi/git/bc.db < /home/pi/Dump.sql");
if (!p.waitForStarted())
{
qDebug()<<"ERROR";
}
qDebug()<<"No ERROR";
p.waitForFinished(-1); -
@Ramkumar-Mohan said in How to restore a backed up sqlite database ?:
p.start("sh",QStringList()<<"-c"<<"sudo sqlite3 /home/pi/git/bc.db < /home/pi/Dump.sql");
Perfect, well done!
Amongst other cases, you must do this if you command line contains the
>
,>>
,<
,|
,&
and a few other shell symbols. -
This post is deleted!