Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to Dump sql database ?
Forum Updated to NodeBB v4.3 + New Features

How to Dump sql database ?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 978 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ramkumar Mohan
    wrote on 17 Aug 2022, 07:21 last edited by
    #1

    du.JPG

    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.

    J 1 Reply Last reply 17 Aug 2022, 07:41
    0
    • R Ramkumar Mohan
      17 Aug 2022, 07:21

      du.JPG

      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.

      J Offline
      J Offline
      JonB
      wrote on 17 Aug 2022, 07:41 last edited by
      #2

      @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.

      R 2 Replies Last reply 17 Aug 2022, 08:00
      1
      • J JonB
        17 Aug 2022, 07:41

        @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.

        R Offline
        R Offline
        Ramkumar Mohan
        wrote on 17 Aug 2022, 08:00 last edited by
        #3

        @JonB Ok

        1 Reply Last reply
        0
        • J JonB
          17 Aug 2022, 07:41

          @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.

          R Offline
          R Offline
          Ramkumar Mohan
          wrote on 19 Aug 2022, 09:29 last edited by
          #4

          @JonB

          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.

          J 1 Reply Last reply 19 Aug 2022, 10:35
          0
          • R Ramkumar Mohan
            19 Aug 2022, 09:29

            @JonB

            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.

            J Offline
            J Offline
            JonB
            wrote on 19 Aug 2022, 10:35 last edited by JonB
            #5

            @Ramkumar-Mohan
            You now write code to use sqlite3.exe.
            Your original question showed you running mysqldump for MySQL.
            You tell me: how could anybody know you want a SQLite backup if you ask about mysqldump? How did you expect anyone to answer if you don't say what SQL database you are using?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 19 Aug 2022, 18:05 last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              J 1 Reply Last reply 19 Aug 2022, 18:06
              0
              • SGaistS SGaist
                19 Aug 2022, 18:05

                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.

                J Offline
                J Offline
                JonB
                wrote on 19 Aug 2022, 18:06 last edited by JonB
                #7

                @SGaist
                Don't forget, @Ramkumar-Mohan has written

                Finally , This code works fine .

                so I guess it does work for him :)

                1 Reply Last reply
                0

                1/7

                17 Aug 2022, 07:21

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved