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. Qt Sqlite question
Forum Updated to NodeBB v4.3 + New Features

Qt Sqlite question

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.4k 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.
  • C Offline
    C Offline
    cmessineo
    wrote on 6 Aug 2014, 17:59 last edited by
    #1

    I can't seem to trap an open error when I corrupt the database file on purpose.

    Here is my code:

    @
    // Find QSLite driver
    db = QSqlDatabase::addDatabase("QSQLITE", "connection");

    QString path(DATABASE_PATH);
    path.append(QDir::separator()).append(DATABASE_NAME);
    db.setDatabaseName(path);
    
    ret = db.open();
    

    @

    When I run this the first time it will create a sqlite database in my database path using the database name and the ret variable will equal true, but when I go in and corrupt the database file and run the code again it will still open the database and the ret variable will equal true like nothing is wrong. I've tried using db.isValid() but that also returns true. The database file is clearly invalid. I must be doing something wrong, can anyone tell me how to test if the sqlite database file is corrupted when opening?

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Aug 2014, 21:58 last edited by
      #2

      Hi,

      You should also add which version of Qt and OS you are currently running

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cmessineo
        wrote on 6 Aug 2014, 22:04 last edited by
        #3

        I'm using Qt 4.8.4 and I am using 32 bit Linux Mint 17.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Aug 2014, 11:42 last edited by
          #4

          What happens if you run queries on that corrupted database ?

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

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cmessineo
            wrote on 7 Aug 2014, 17:27 last edited by
            #5

            If I run queries on the corrupted database I get an error. I guess the only thing I can do is run a query something like "select sqlite_version()" and if I get an error then I know I have a corrupted database. The reason why I need to check if the db is corrupt is because sometimes on a power outage the db will get corrupted on my embedded system and I need to do a quick restore.

            I thought I'd get an error on open but that doesn't seem to be the case. It only errors on open if you don'y have the driver installed. Not sure if that is the case with Qt 5 but will try it later today.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 7 Aug 2014, 20:04 last edited by
              #6

              If not, you could create a suggestion on the but tracker (but first look whether there's already something about it)

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

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on 8 Aug 2014, 12:08 last edited by
                #7

                Sqlite databases should mot be corrupted by a simple power outage. From http://sqlite.org/about.html

                bq. SQLite responds gracefully to memory allocation failures and disk I/O errors. Transactions are ACID even if interrupted by system crashes or power failures. All of this is verified by the automated tests using special test harnesses which simulate system failures.

                If you have a repeatable scenario that corrupts a database you should raise it as a bug with Sqlite.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrdebug
                  wrote on 8 Aug 2014, 13:53 last edited by
                  #8

                  I'm using Sqlite in an intensive contest from many years with Qt and Freepascal. In the past I had problems with corrupted databases. You can follow some guides to restore them.
                  I have resolved the problems using transactions like this

                  begin exclusive transaction
                  commit

                  Using transactions I haven't got corrupted databases anymore.

                  Need programmers to hire?
                  www.labcsp.com
                  www.denisgottardello.it
                  GMT+1
                  Skype: mrdebug

                  1 Reply Last reply
                  0

                  1/8

                  6 Aug 2014, 17:59

                  • Login

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