How to Dump sql database ?
-
wrote on 17 Aug 2022, 07:21 last edited by
-
I wrote this code, but this is not working for me,
I want to backup & restore a SQL database, Please send the sample code you know.
Thanks in advance.wrote on 17 Aug 2022, 07:41 last edited by@Ramkumar-Mohan said in How to Dump sql database ?:
I wrote this code, but this is not working for me,
First, please copy & paste code, not screenshots which make it harder for those of us who try to answer.
Define "not working"? I see no error checking, for all I know an error or a message is being generated and you would not know. Also you do not show your code in context and waht happens after the
dumpProcess.start()
.mysqldump
is indeed probably the best way to backup a MySQL database. Look around for examples of backing up and restoring for MySQL, this has nothing to do with Qt. -
@Ramkumar-Mohan said in How to Dump sql database ?:
I wrote this code, but this is not working for me,
First, please copy & paste code, not screenshots which make it harder for those of us who try to answer.
Define "not working"? I see no error checking, for all I know an error or a message is being generated and you would not know. Also you do not show your code in context and waht happens after the
dumpProcess.start()
.mysqldump
is indeed probably the best way to backup a MySQL database. Look around for examples of backing up and restoring for MySQL, this has nothing to do with Qt.wrote on 17 Aug 2022, 08:00 last edited by@JonB Ok
-
@Ramkumar-Mohan said in How to Dump sql database ?:
I wrote this code, but this is not working for me,
First, please copy & paste code, not screenshots which make it harder for those of us who try to answer.
Define "not working"? I see no error checking, for all I know an error or a message is being generated and you would not know. Also you do not show your code in context and waht happens after the
dumpProcess.start()
.mysqldump
is indeed probably the best way to backup a MySQL database. Look around for examples of backing up and restoring for MySQL, this has nothing to do with Qt.wrote on 19 Aug 2022, 09:29 last edited byHi,
void frmMain::dumpSqliteDatabase()
{
QString strError;
QString strPathSqlite;QString fileName = "Dump.sql";
QProcess p;
p.setStandardOutputFile(fileName);
p.setWorkingDirectory("/home/pi/");
strPathSqlite = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/data/sqlite3.exe");
strPathSqlite.replace("\","\\");p.start(strPathSqlite + " Scrab.db .dump > " + 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();
}
}Finally , This code works fine .
Thank you.
-
Hi,
void frmMain::dumpSqliteDatabase()
{
QString strError;
QString strPathSqlite;QString fileName = "Dump.sql";
QProcess p;
p.setStandardOutputFile(fileName);
p.setWorkingDirectory("/home/pi/");
strPathSqlite = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/data/sqlite3.exe");
strPathSqlite.replace("\","\\");p.start(strPathSqlite + " Scrab.db .dump > " + 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();
}
}Finally , This code works fine .
Thank you.
wrote on 19 Aug 2022, 10:35 last edited by JonB@Ramkumar-Mohan
You now write code to usesqlite3.exe
.
Your original question showed you runningmysqldump
for MySQL.
You tell me: how could anybody know you want a SQLite backup if you ask aboutmysqldump
? How did you expect anyone to answer if you don't say what SQL database you are using? -
Hi,
In addition to @JonB, your code shows a path named "/home/pi" which hints at a RaspberryPi running Linux so highly unlikely to have .exe files on it since it's a Windows thing.
-
Hi,
In addition to @JonB, your code shows a path named "/home/pi" which hints at a RaspberryPi running Linux so highly unlikely to have .exe files on it since it's a Windows thing.
wrote on 19 Aug 2022, 18:06 last edited by JonB@SGaist
Don't forget, @Ramkumar-Mohan has writtenFinally , This code works fine .
so I guess it does work for him :)
1/7