Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. SQLITE Database in Project
Forum Updated to NodeBB v4.3 + New Features

SQLITE Database in Project

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
sqlite
25 Posts 8 Posters 34.3k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #8

    As far as I know it's possible to add this to some settings in the qmake project files, at least for symbian. But I have no experience on this. Please use the forum search and/or Google - I'm sure this was asked before.

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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Matze5590
      wrote on last edited by
      #9

      Here's the solution for everybody who's interested in:

      use:
      @db = QSqlDatabase::addDatabase("QSQLITE");
      db.setDatabaseName("db.sqlite");@

      and add this to your .pro file:
      @symbian {
      ...
      addFiles.sources = db.sqlite
      addFiles.path = .
      DEPLOYMENT += addFiles
      ...
      }
      @

      Thanks to Volker!

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vsh.vshnu
        wrote on last edited by
        #10

        Hi All,
        I have tried in the same way.But i didnt get it.
        Basically i am developing the meego application in windows dev enviornment using Qt creator.

        Following are my pro file contents,

        @
        QT += core gui sql
        TARGET = AppName
        TEMPLATE = app
        target.path=/usr/local/bin
        INSTALLS=target
        SOURCES += ---
        ---
        HEADERS += ---
        ---
        FORMS += ---
        ---
        RESOURCES +=
        assests.qrc
        addFiles.sources =test.sqlite
        addFiles.path = .
        DEPLOYMENT += addFiles
        @

        So when i tried to build the file, automatically the other folde is added into my project directory and showing test.sqlite inside it;

        But when i tried with the following code

        @
        db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName(dbname);
        if(db.open())
        {
        // ITs always true;in the sense it automatically creates a new database name test.sqlite in the /usr/local/bin folder
        }
        @

        Please give some suggestions over this issue.

        Thanks,
        Vsh.Vshnu

        [EDIT: code formatting, please use @-tags, not stars (*), Volker]

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on last edited by
          #11

          Hi Vsh.Vshnu,

          Follow the SQLite examples given in Forum Nokia:
          "Creating an SQLite database in Qt":http://wiki.forum.nokia.com/index.php/CS001504_-Creating_an_SQLite_database_in_Qt
          "Searching for data in a database in Qt":http://wiki.forum.nokia.com/index.php/CS001507
          -_Searching_for_data_in_a_database_in_Qt

          Best regards,
          Leon

          http://anavi.org/

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vsh.vshnu
            wrote on last edited by
            #12

            [quote author="leon.anavi" date="1305634618"]Hi Vsh.Vshnu,

            Follow the SQLite examples given in Forum Nokia:
            "Creating an SQLite database in Qt":http://wiki.forum.nokia.com/index.php/CS001504_-Creating_an_SQLite_database_in_Qt
            "Searching for data in a database in Qt":http://wiki.forum.nokia.com/index.php/CS001507
            -_Searching_for_data_in_a_database_in_Qt

            Best regards,
            Leon[/quote]

            Hi leon.anavi,
            My problem is different.Its becasuse i am not able to open a existing sqlite database inside project main folder.
            I want the sqlite files to be inside my application package file??

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

              Then, what is the path stored in variable dbname?

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

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vsh.vshnu
                wrote on last edited by
                #14

                Hi Volker,
                Its simply
                QString dbName="test.sqlite";

                Iam developing for meego in windows developement enviorment using Qt creator

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

                  the target path of your app is /usr/local/bin, the path of your db is test.sqlite - so the complete path is /usr/local/bin/test.sqlite. Sounds quite ok for me (in regard to the setup, a database file in /usr/local/bin is a no-go!).

                  Do you have a test.sqlite that actually is packed in your setup?

                  And be aware, the packing options are Symbian only!. It is ignored for any other operating systems, including Meego! It is for reason, that Matze5590 has put them into the symbian scope!

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

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    leon.anavi
                    wrote on last edited by
                    #16

                    [quote author="vsh.vshnu" date="1305635099"]Hi Volker,
                    Its simply
                    QString dbName="test.sqlite";

                    Iam developing for meego in windows developement enviorment using Qt creator[/quote]

                    Try to use the absolute path. You can get the file path of the application executable using "QCoreApplication::applicationFilePath":http://doc.qt.nokia.com/latest/qcoreapplication.html#applicationFilePath

                    Cheers,
                    Leon

                    http://anavi.org/

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vsh.vshnu
                      wrote on last edited by
                      #17

                      [quote author="leon.anavi" date="1305635864"]
                      [quote author="vsh.vshnu" date="1305635099"]Hi Volker,
                      Its simply
                      QString dbName="test.sqlite";

                      Iam developing for meego in windows developement enviorment using Qt creator[/quote]

                      Try to use the absolute path. You can get the file path of the application executable using "QCoreApplication::applicationFilePath":http://doc.qt.nokia.com/latest/qcoreapplication.html#applicationFilePath
                      Cheers,
                      Leon

                      [/quote]

                      Hi Leon,
                      Thanks for the support ,
                      I have tried using the QCoreApplication::applicationFilePath
                      @QString dbName=QCoreApplication::applicationFilePath()+“\test.sqlite”;@
                      But it seems not opening the database.
                      All I wanted to pack the sqlite database inside my application so that i can install the applications as a single unit.

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        leon.anavi
                        wrote on last edited by
                        #18

                        [quote author="Volker" date="1305635745"]Do you have a test.sqlite that actually is packed in your setup?
                        [/quote]

                        [quote author="vsh.vshnu" date="1305636668"]
                        All I wanted to pack the sqlite database inside my application so that i can install the applications as a single unit.
                        [/quote]

                        I think you should follow Volker's hint :) Please read "MeeGo Packaging/Guidelines":http://wiki.meego.com/Packaging/Guidelines As you probably know MeeGo apps are distributed as rpm so you have to include your database into the rpm.

                        http://anavi.org/

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          vsh.vshnu
                          wrote on last edited by
                          #19

                          [quote author="leon.anavi" date="1305637109"][quote author="Volker" date="1305635745"]Do you have a test.sqlite that actually is packed in your setup?
                          [/quote]

                          [quote author="vsh.vshnu" date="1305636668"]
                          All I wanted to pack the sqlite database inside my application so that i can install the applications as a single unit.
                          [/quote]

                          I think you should follow Volker's hint :) Please read "MeeGo Packaging/Guidelines":http://wiki.meego.com/Packaging/Guidelines As you probably know MeeGo apps are distributed as rpm so you have to include your database into the rpm.

                          [/quote]

                          Thanks for the help.. i will look into it..

                          Thanks & Regards,
                          Vsh.Vshnu

                          1 Reply Last reply
                          0
                          • G goetz

                            SQLite databases cannot be stored in the Qt resource system. You must put it into regular files and distribute them along your application.

                            The reason is simple: The database name is just the path to the file. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the “path”), which in turn try to open that file – and will eventually fail, of course.

                            C Offline
                            C Offline
                            cawlfj
                            wrote on last edited by
                            #20

                            @goetz
                            some time , we need store a read-only database file in the QRC file. just need read no need change.
                            store in qrc file will avoid use change ,delete....etc it. and use database file (qsqlite3 ) will be fast get query result.

                            now qt version is 5.8. can we do it ?

                            best regards,

                            mrjjM 1 Reply Last reply
                            0
                            • C cawlfj

                              @goetz
                              some time , we need store a read-only database file in the QRC file. just need read no need change.
                              store in qrc file will avoid use change ,delete....etc it. and use database file (qsqlite3 ) will be fast get query result.

                              now qt version is 5.8. can we do it ?

                              best regards,

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #21

                              @cawlfj

                              Hi
                              If small database, you can just copy
                              it to file system upon run and
                              open it.

                              Just override it each time.

                              I do not think its possible to have a db in qrc.

                              C 1 Reply Last reply
                              1
                              • mrjjM mrjj

                                @cawlfj

                                Hi
                                If small database, you can just copy
                                it to file system upon run and
                                open it.

                                Just override it each time.

                                I do not think its possible to have a db in qrc.

                                C Offline
                                C Offline
                                cawlfj
                                wrote on last edited by
                                #22

                                @mrjj yes , you are right . we can do as your way. but i think if the db file in inside the qrc file will be more safety than copy out.
                                Some time , some data , we don't want some body to get it .

                                mrjjM 1 Reply Last reply
                                0
                                • C cawlfj

                                  @mrjj yes , you are right . we can do as your way. but i think if the db file in inside the qrc file will be more safety than copy out.
                                  Some time , some data , we don't want some body to get it .

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #23

                                  @cawlfj
                                  Well its not impossible to still dig it out using a hex editor.
                                  For dbs, something like
                                  https://www.zetetic.net/sqlcipher/about/
                                  might be better.
                                  Maybe you can use the dump trick to upload to a :mem based db.
                                  http://stackoverflow.com/questions/3826552/in-python-how-can-i-load-a-sqlite-db-completely-to-memory-before-connecting-to
                                  Disclaimer: i never tried this.

                                  1 Reply Last reply
                                  2
                                  • E Offline
                                    E Offline
                                    EdgarDinz
                                    wrote on last edited by EdgarDinz
                                    #24

                                    Consider using QTemporaryFile::createNativeFile:

                                    QTemporaryFile *QTemporaryFile::createNativeFile(QFile &file)
                                    QTemporaryFile *QTemporaryFile::createNativeFile(const QString &fileName)
                                    

                                    then you can pass a resource path as fileName.

                                    1 Reply Last reply
                                    0
                                    • G goetz

                                      SQLite databases cannot be stored in the Qt resource system. You must put it into regular files and distribute them along your application.

                                      The reason is simple: The database name is just the path to the file. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the “path”), which in turn try to open that file – and will eventually fail, of course.

                                      A Offline
                                      A Offline
                                      an_auto
                                      wrote on last edited by
                                      #25
                                      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