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 919 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.
  • Ramkumar MohanR Offline
    Ramkumar MohanR Offline
    Ramkumar Mohan
    wrote on 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.

    JonBJ 1 Reply Last reply
    0
    • Ramkumar MohanR Ramkumar Mohan

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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.

      Ramkumar MohanR 2 Replies Last reply
      1
      • JonBJ JonB

        @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 MohanR Offline
        Ramkumar MohanR Offline
        Ramkumar Mohan
        wrote on last edited by
        #3

        @JonB Ok

        1 Reply Last reply
        0
        • JonBJ JonB

          @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 MohanR Offline
          Ramkumar MohanR Offline
          Ramkumar Mohan
          wrote on 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.

          JonBJ 1 Reply Last reply
          0
          • Ramkumar MohanR Ramkumar Mohan

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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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 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

              JonBJ 1 Reply Last reply
              0
              • SGaistS SGaist

                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.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on 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

                • Login

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