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. In window XP, I failed to open a database file comes from Android phone.
Qt 6.11 is out! See what's new in the release blog

In window XP, I failed to open a database file comes from Android phone.

Scheduled Pinned Locked Moved General and Desktop
20 Posts 4 Posters 13.1k 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.
  • P Offline
    P Offline
    pico
    wrote on last edited by
    #1

    Hi, Sir:
    I got a database file comes from Android phone, and I tried to do something on this file.
    So, I implement an AP to handle this file.

    My original code is developed on Ubuntu, and this AP works fine.
    Then, I move this codebase to Window XP, and use Qt-Window version to recompile it.
    Everything is OK until I try to execute this AP to open an existing database file.

    @
    QSqlDatabase db = QSqlDatabase::database(SESSION_NAME_SECOND);
    if (db.isValid()) {
    db.close();
    QSqlDatabase::removeDatabase(SESSION_NAME_SECOND);
    }

    //QMessageBox::warning(0,"Warning0",SESSION_NAME);
    db = QSqlDatabase::addDatabase("QSQLITE", SESSION_NAME_SECOND);
    db.setDatabaseName(fileName);
    
    QString msg = tr("Unable to open or create file %1. It is probably not a database").arg(QFileInfo(fileName).fileName());
    if(!db.open())  {
        QMessageBox::warning(0, "BatchWindow", msg);
        return;
    }
    /* Qt database open() (exactly the sqlite API sqlite3_open16())
       method does not check if it is really database. So the dummy
       select statement should perform a real "is it a database" check
       for us. */
    _*QSqlQuery q("select 1 from sqlite_master where 1=2", db);*_
    if (!q.exec())  {
        *QMessageBox::warning(0, "DBList", msg);*__
        return;
    }   else    {
        isOpened = true;
    

    @

    When I try to use QSqlQuery and perform "exec()", it would get failed. Then, post a warning dialog to show
    "Unable to open or create file XXX.db. It is probably not a database".

    Could you tell me what I do wrong???

    BR,

    Pico

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pico
      wrote on last edited by
      #2

      Hi, Sir:

      Could anyone help me to solve this issue?
      I really need to port my AP on windowXP with Qt-SDK 4.7.

      Thanks a lot.

      BR,
      Pico

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Would you PLEASE be patient!
        3 and half hours and you're moaning about no response. You're not serious, are you?

        If you want to know what's going on, call "QSqlDatabase::lastError() ":http://doc.qt.nokia.com/latest/qsqldatabase.html#lastError on your db on the open and "QSqlQuery::lastError() ":http://doc.qt.nokia.com/latest/qsqlquery.html#lastError on the failed query. They will tell you what happened.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pico
          wrote on last edited by
          #4

          Hi, Volker:
          Thanks for your reminders!!
          I am just too emotional...

          And, after checking the error, it shows "No query Unable to fetch row".

          But, I have no idea on why I get this error.

          Again, I have to say this AP works well under Ubuntu.
          So, Do I need to modify anything for that?

          Thanks a lot.

          BR,
          Pico

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zester
            wrote on last edited by
            #5

            Sounds like sqlite isn't setup properly on windows. Is it only this database file or do others also give you problems?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              [quote author="pico" date="1297428894"] And, after checking the error, it shows "No query Unable to fetch row".

              But, I have no idea on why I get this error.

              Again, I have to say this AP works well under Ubuntu.
              So, Do I need to modify anything for that?
              [/quote]

              Is the database file available?
              Is it in the right directory?
              Is the sqlite version the same?

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pico
                wrote on last edited by
                #7

                Hi, Volker:

                [quote author="Volker" date="1297464678"]

                Is the database file available?
                Is it in the right directory?
                Is the sqlite version the same?
                [/quote]

                This database is OK to perform action on Ubuntu on the same codes.
                And, for the version, I have no many ideas on that.
                However, I think it is 3.6.22.

                In addition, opening the database seems no error...

                Thanks a lot.

                BR,
                Pico

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  No clue here what's going wrong. I cannot even assure that the file is opened correctly.

                  Regearding sqlite version, its not the exact version but more a sqlite2 or sqlite3 question. Can you open the file with the sqlite command line tool?

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pico
                    wrote on last edited by
                    #9

                    Hi, Volker:
                    I also guess this is a sqlite question, however, I am not familiar with sqlite.
                    And, I also download the sqlite command line tool to test it.
                    It works well...

                    And, I also use some other commercial tool to open it.
                    It is OK, too.

                    In addition, I find a command "Repair" in a tool. If I do it on those database files, I can open them by Qt's sql dll.

                    So, I would like to know if Qt's sqlite driver doesn't have error tolerance on mismatched SQL files.

                    If so, does it mean I have to use another sqlite driver?

                    Thanks a lot.

                    BR,
                    Pico

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #10

                      If you use SQL databases, you should at least make yourself comfortable with using the command line tools.

                      Without the actual files I cannot comment any further. It's completely unclear what's going wrong.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pico
                        wrote on last edited by
                        #11

                        Hi, Volker:
                        Is there anyway to send you the database file?
                        Could you help me to check it?
                        Because I use the sqlite tool downloaded from the SQL web, it works well.

                        So, I can not understand why I can not use the Qt's SQL dll to handle that.

                        Thanks a lot.

                        BR,
                        Pico

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          Well, you could always put it up on one of the many free services for such things. Perhaps using dropbox in a public folder?
                          Please just post the link here, so others than just Volker can take a look at your issue if they are interested.

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            pico
                            wrote on last edited by
                            #13

                            Hi, Sir:
                            The link to this database file is http://dl.dropbox.com/u/21382345/blake_cruiser.db
                            If possible, please help me to know what I do wrong.

                            Thanks a lot.

                            BR,
                            Pico

                            [EDIT: fixed link, Volker]

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              goetz
                              wrote on last edited by
                              #14

                              I cannot open the database file on Ubuntu (sqlite 3.4.2 and 3.6.16) nor on Mac OS X (sqlite 3.6.12).

                              Is the OS/lib/program that creates the database file using some kind of encryption?

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                pico
                                wrote on last edited by
                                #15

                                Hi, Volker:
                                This database file comes from Android phone.
                                I just copy it out, and try to parse it.

                                But, I can use sqlite3_analyzer downloaded from "www.sqlite.org" to open it.

                                So, I guess this might be related to version.

                                If so, could you give me a piece of advice to solve the version issue?
                                For example, could I get the updated library from Qt's web for SQL?
                                Or, something like that...

                                BR,
                                Pico

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  goetz
                                  wrote on last edited by
                                  #16

                                  Ok, problem found: The SQLite version in Android is newer than that bundled with Qt. Actual problem is, that it is too new and contains a "WAL feature":http://www.sqlite.org/wal.html that older versions cannot deal with.

                                  • Android has SQLite 3.7.x
                                  • Qt 4.7.1 has SQLite 3.6.19

                                  I can easily change a working database file to be locked out of a 3.6.x client by changing that mentioned WAL flag.

                                  The good news is: You can build the SQLite plugin of Qt with a newer version of SQLite. The docs have instructions on how to do this in section "QSQLITE for SQLite (Version 3 and Above)":http://doc.qt.nokia.com/4.7/sql-driver.html#qsqlite of the "SQL Database Drivers":http://doc.qt.nokia.com/4.7/sql-driver.html page. Just use the newest SQLite version from the webpage.

                                  On Jira, there is an open bug report "QTBUG-16607":http://bugreports.qt.nokia.com/browse/QTBUG-16607 which requests an update of the built in SQLite version to 3.7.x. You can vote for it, this may accelerate it a bit.

                                  http://www.catb.org/~esr/faqs/smart-questions.html

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    pico
                                    wrote on last edited by
                                    #17

                                    Hi, Volker:
                                    I really appreciate your great help.
                                    What you said make me know lots of things about database file.

                                    Thanks a lot.

                                    BR,
                                    Pico

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      pico
                                      wrote on last edited by
                                      #18

                                      Hi, Volker:
                                      Although I followed what you showed to me, I failed to generate a QtSql4.dll.
                                      I could get libqsqlite4.a, qsqlite4.dll, and something else.
                                      However, I can still NOT make a sql query successfully.

                                      Could you give me more details for how to build a new sql driver and install it?

                                      Thanks a lot.

                                      BR,
                                      Pico

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        goetz
                                        wrote on last edited by
                                        #19

                                        It could be, that your application grabs an old version of the plugin. Make sure, that
                                        "QCoreApplication::addLibraryPath() ":http://doc.qt.nokia.com/4.7/qcoreapplication.html#addLibraryPath

                                        You can check the version of the used SQLite with

                                        @
                                        select sqlite_version();
                                        @

                                        Issue this in your program and check that you actually use the newly built plugin, not the old one.

                                        http://www.catb.org/~esr/faqs/smart-questions.html

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          goetz
                                          wrote on last edited by
                                          #20

                                          Just for the records, if anyone stumbles over this old thread: In the recent release 4.8 of Qt the included SQLite has been updated to version 3.7.7.1.

                                          http://www.catb.org/~esr/faqs/smart-questions.html

                                          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