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 restore a backed up sqlite database ?
Forum Updated to NodeBB v4.3 + New Features

How to restore a backed up sqlite database ?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 877 Views 1 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 19 Aug 2022, 10:38 last edited by
    #1

    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

    J 1 Reply Last reply 19 Aug 2022, 10:43
    0
    • R Ramkumar Mohan
      19 Aug 2022, 10:38

      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

      J Offline
      J Offline
      JonB
      wrote on 19 Aug 2022, 10:43 last edited by JonB
      #2

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

      R 1 Reply Last reply 19 Aug 2022, 10:57
      0
      • J JonB
        19 Aug 2022, 10:43

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

        R Offline
        R Offline
        Ramkumar Mohan
        wrote on 19 Aug 2022, 10:57 last edited by
        #3

        @JonB

        Your command line contains a redirection symbol. You must run it through a shell to have that interpreted.

        It's working fine now,

        Thank you.

        J 1 Reply Last reply 19 Aug 2022, 11:12
        0
        • R Ramkumar Mohan
          19 Aug 2022, 10:57

          @JonB

          Your command line contains a redirection symbol. You must run it through a shell to have that interpreted.

          It's working fine now,

          Thank you.

          J Offline
          J Offline
          JonB
          wrote on 19 Aug 2022, 11:12 last edited by
          #4

          @Ramkumar-Mohan said in How to restore a backed up sqlite database ?:

          It's working fine now,

          And how did you achieve that?

          R 1 Reply Last reply 19 Aug 2022, 12:50
          0
          • J JonB
            19 Aug 2022, 11:12

            @Ramkumar-Mohan said in How to restore a backed up sqlite database ?:

            It's working fine now,

            And how did you achieve that?

            R Offline
            R Offline
            Ramkumar Mohan
            wrote on 19 Aug 2022, 12:50 last edited by
            #5

            @JonB

            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);

            J 1 Reply Last reply 19 Aug 2022, 13:31
            0
            • R Ramkumar Mohan
              19 Aug 2022, 12:50

              @JonB

              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);

              J Offline
              J Offline
              JonB
              wrote on 19 Aug 2022, 13:31 last edited by JonB
              #6

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

              R 1 Reply Last reply 19 Aug 2022, 13:52
              0
              • J JonB
                19 Aug 2022, 13:31

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

                R Offline
                R Offline
                Ramkumar Mohan
                wrote on 19 Aug 2022, 13:52 last edited by
                #7

                @JonB

                Amongst other cases, you must do this if you command line contains the >, >>, <, |, & and a few other shell symbols.

                Ok, Thank you.

                1 Reply Last reply
                0
                • sysinfotoolsS Offline
                  sysinfotoolsS Offline
                  sysinfotools
                  wrote on 10 Feb 2024, 05:23 last edited by
                  #8
                  This post is deleted!
                  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