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. SQLITE, I delete que sqlite file and the database still loading data from the file...
Forum Updated to NodeBB v4.3 + New Features

SQLITE, I delete que sqlite file and the database still loading data from the file...

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 4.2k 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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #6

    Well... I try rename the the database on disk, and still loading then!

    I try this: change the return of "getDataBaseName()" to “C:\ProgramData\MyApp\database.sqlite123”, and I got no database because there is no database with this name...
    I really can't understand that... I reading some docs and examples to see the problem...

    1 Reply Last reply
    0
    • C Offline
      C Offline
      clochydd
      wrote on last edited by
      #7

      Can you collect more information by using
      @
      qDebug() << database.databaseName();
      qDebug() << database.hostName()
      @

      I presume your database is in memory - see "In-Memory SQLite":https://www.sqlite.org/inmemorydb.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on last edited by
        #8

        Well... I as thinking about in memory sqlite, but the file is updated... I open in FireFox addon "Sqlite Manager" and query stuff and works well!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dcbasso
          wrote on last edited by
          #9

          Result:
          @
          qDebug() << database.databaseName();
          qDebug() << database.hostName();
          @

          "C:\ProgramData\MyApp\database.sqlite"
          ""

          Another very interesting thing is, the return of this code is TRUE:

          @
          static bool isDataBaseCreated()
          {
          QFile* arquivo = new QFile(getDataBaseName());
          bool retorno = arquivo->exists();
          qDebug() << "File name: " << getDataBaseName();
          qDebug() << "File exists: " << retorno;
          arquivo->close();
          delete arquivo;
          return retorno;
          }

          File name: "C:\ProgramData\MyApp\database.sqlite"
          File exists: true
          @

          The problem is... the file is really not there!!!

          1 Reply Last reply
          0
          • C Offline
            C Offline
            clochydd
            wrote on last edited by
            #10

            I do not work with Windows very often so I hope its not a silly question: Can a hidden file of that name exist?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #11

              Well check it and nothing there!
              I always use Linux, but in this project I make everything on windows...
              I'm change my way to connect the database right now... maybe I can solve that...

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dcbasso
                wrote on last edited by
                #12

                Well...
                I try and Try... and...
                Appears some kind of cache, I not really sure or maybe some bug on Qt 5.2...
                I really don't know what do to anymore...

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andreyc
                  wrote on last edited by
                  #13

                  Did you try to check if file exists in command shell (cmd.exe)?
                  An explorer may hide some files.

                  Run the following commands in cmd.exe
                  @
                  dir C:\ProgramData\MyApp\database.sqlite
                  dir C:\ProgramData\MyApp*
                  @

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dcbasso
                    wrote on last edited by
                    #14

                    well guys...
                    after some suffering I make some crazy code:

                    @
                    static QSqlDatabase getDatabase()
                    {
                    QSqlDatabase database = QSqlDatabase::database(getDataBaseName());
                    qDebug() << "isOpen: " << database.isOpen();
                    qDebug() << "isValid: " << database.isValid();
                    if (! database.isValid())
                    {
                    database = QSqlDatabase::addDatabase(DRIVER, getDataBaseName());
                    database.setHostName(DB_HOSTNAME);
                    database.setDatabaseName(getDataBaseName());
                    database.removeDatabase();
                    isDataBaseCreated(database);

                        }
                        qDebug() << "Database host: " << database.hostName();
                        qDebug() << "Database name: " << database.databaseName();
                        return database;
                    }
                    

                    @
                    @
                    static bool isDataBaseCreated(QSqlDatabase db)
                    {
                    bool exists = false;
                    QFile* arquivo = new QFile(getDataBaseName());
                    exists = arquivo->exists();
                    if (exists)
                    {
                    arquivo.remove();
                    }
                    delete arquivo;
                    return exists;
                    }
                    @

                    In resume:

                    Using my app, with "same code" and force the file to be deleted and force to database be removed...

                    Now appears to be solve my problem...

                    Question: It's recommend before close app do this:

                    @
                    database.close();
                    database.removeDatabase();
                    @

                    Thanks all!

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dcbasso
                      wrote on last edited by
                      #15

                      Yes I check, with and without Administrator cmd!

                      [quote author="andreyc" date="1396027781"]Did you try to check if file exists in command shell (cmd.exe)?
                      An explorer may hide some files.

                      Run the following commands in cmd.exe
                      @
                      dir C:\ProgramData\MyApp\database.sqlite
                      dir C:\ProgramData\MyApp*
                      @[/quote]

                      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