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 use SQLite's PRAGMA application_id
QtWS25 Last Chance

How to use SQLite's PRAGMA application_id

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 2.1k Views
  • 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.
  • L Offline
    L Offline
    l3u_
    wrote on 15 Nov 2019, 17:02 last edited by
    #5

    Well okay, I already did quite some wicked stuff with that ? syntax and bindValue, so I thought it would simply escape the data bound to it in a proper/safe way and built a query … still, I think for this very use-case, it would be quite useful. I filed a bug about this ( https://bugreports.qt.io/browse/QTBUG-80082 ), let's see what the Trolls say …

    J 1 Reply Last reply 15 Nov 2019, 18:05
    0
    • L l3u_
      15 Nov 2019, 17:02

      Well okay, I already did quite some wicked stuff with that ? syntax and bindValue, so I thought it would simply escape the data bound to it in a proper/safe way and built a query … still, I think for this very use-case, it would be quite useful. I filed a bug about this ( https://bugreports.qt.io/browse/QTBUG-80082 ), let's see what the Trolls say …

      J Offline
      J Offline
      JonB
      wrote on 15 Nov 2019, 18:05 last edited by JonB
      #6

      @l3u_
      What output do you get with:

      query.prepare(QStringLiteral("NONSENSE piffle_bottom = ?"));
      

      ?

      L 1 Reply Last reply 16 Nov 2019, 06:54
      1
      • J JonB
        15 Nov 2019, 18:05

        @l3u_
        What output do you get with:

        query.prepare(QStringLiteral("NONSENSE piffle_bottom = ?"));
        

        ?

        L Offline
        L Offline
        l3u_
        wrote on 16 Nov 2019, 06:54 last edited by l3u_
        #7

        @JonB According to the surprisingly fast answer in the bug report, it's already the prepare statement that fails. I actually didn't check for this … so seems that SQLite doesn't like prepared statements in a PRAGMA call.

        J 1 Reply Last reply 16 Nov 2019, 10:01
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 16 Nov 2019, 06:58 last edited by
          #8

          @l3u_ said in How to use SQLite's PRAGMA application_id:

          According to the surprisingly fast answer in the bug report

          When you would have waited some hours before opening the report I would have told you the problem here.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          L 1 Reply Last reply 16 Nov 2019, 16:44
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 16 Nov 2019, 07:33 last edited by
            #9

            Hi,

            Just a side note, the PRAGMA statement is also SQLite specific and may run at different execution stage and that may change at any point in time with an SQLite release.

            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
            3
            • L l3u_
              16 Nov 2019, 06:54

              @JonB According to the surprisingly fast answer in the bug report, it's already the prepare statement that fails. I actually didn't check for this … so seems that SQLite doesn't like prepared statements in a PRAGMA call.

              J Offline
              J Offline
              JonB
              wrote on 16 Nov 2019, 10:01 last edited by
              #10

              @l3u_
              Although I have yet to find a list of what you can/cannot prepare/bind, my understanding is that it is not Qt but instead the database level/driver which does binding, e.g. SQLite C Interface. If Qt supports bind across all SQL drivers, I don't know if it has a "fallback" of doing the binding itself (in the driver perhaps) if there is a SQL backend which does not support it natively.

              1 Reply Last reply
              1
              • C Christian Ehrlicher
                16 Nov 2019, 06:58

                @l3u_ said in How to use SQLite's PRAGMA application_id:

                According to the surprisingly fast answer in the bug report

                When you would have waited some hours before opening the report I would have told you the problem here.

                L Offline
                L Offline
                l3u_
                wrote on 16 Nov 2019, 16:44 last edited by l3u_
                #11

                @Christian-Ehrlicher Sorry again for bothering you with the bug report, but from an end-user's point of view, without knowing the very internals of Qt's SQL implementation, the internals of SQLite, at which point what is processed where, and without any hint in the documentation that binding values doesn't work for all queries but only for a subset of commands … it simply looked like a bug.

                But at least one will possibly find this bug report if one searches for why binding values doesn't work with a QSqlQuery (or at all) now, not like when I searched why this doesn't work when I really thought it should.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 16 Nov 2019, 19:37 last edited by
                  #12

                  @l3u_ said in How to use SQLite's PRAGMA application_id:

                  and without any hint in the documentation

                  See https://www.sqlite.org/pragma.html

                  Some pragmas take effect during the SQL compilation stage, not the execution stage. This means if using the C-language sqlite3_prepare(), sqlite3_step(), sqlite3_finalize() API (or similar in a wrapper interface), the pragma may run during the sqlite3_prepare() call, not during the sqlite3_step() call as normal SQL statements do. Or the pragma might run during sqlite3_step() just like normal SQL statements. Whether or not the pragma runs during sqlite3_prepare() or sqlite3_step() depends on the pragma and on the specific release of SQLite.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  L 1 Reply Last reply 17 Nov 2019, 07:54
                  2
                  • C Christian Ehrlicher
                    16 Nov 2019, 19:37

                    @l3u_ said in How to use SQLite's PRAGMA application_id:

                    and without any hint in the documentation

                    See https://www.sqlite.org/pragma.html

                    Some pragmas take effect during the SQL compilation stage, not the execution stage. This means if using the C-language sqlite3_prepare(), sqlite3_step(), sqlite3_finalize() API (or similar in a wrapper interface), the pragma may run during the sqlite3_prepare() call, not during the sqlite3_step() call as normal SQL statements do. Or the pragma might run during sqlite3_step() just like normal SQL statements. Whether or not the pragma runs during sqlite3_prepare() or sqlite3_step() depends on the pragma and on the specific release of SQLite.

                    L Offline
                    L Offline
                    l3u_
                    wrote on 17 Nov 2019, 07:54 last edited by l3u_
                    #13

                    @Christian-Ehrlicher I meant the Qt documentation concerning binding values. WIthout further knowledge/investigstion, one could think that binding values to SQL statements does nothing else than escaping the values properly. At least this is what I thought; now I know better. I simpy didn't know that it's not Qt that handles the binding, but the underlying SQL engine.

                    When I now read this SQLite doc, I (think I) understand what it means. Maybe, PRAGMA application_id is executed when preparing it, SQLite gets that ? instead of an integer and silently ignores the query. The subsequent bindValue call fails, as there's nothing to bind anything to, as the statement already has been executed during the prepare stage.

                    Or whatever. After all, the quintessence is that one can't bind values to an SQLite PRAGMA application_id query, and it's caused by SQLite's implementation, not by a Qt.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 17 Nov 2019, 09:02 last edited by
                      #14

                      @l3u_ said in How to use SQLite's PRAGMA application_id:

                      one could think that binding values to SQL statements does nothing else than escaping the values properly

                      Then you should start understanding the tools you're using - in this case the sql database. Qt can't do anything for you here.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      L 1 Reply Last reply 17 Nov 2019, 09:26
                      0
                      • C Christian Ehrlicher
                        17 Nov 2019, 09:02

                        @l3u_ said in How to use SQLite's PRAGMA application_id:

                        one could think that binding values to SQL statements does nothing else than escaping the values properly

                        Then you should start understanding the tools you're using - in this case the sql database. Qt can't do anything for you here.

                        L Offline
                        L Offline
                        l3u_
                        wrote on 17 Nov 2019, 09:26 last edited by
                        #15
                        This post is deleted!
                        1 Reply Last reply
                        0

                        14/15

                        17 Nov 2019, 09:02

                        • Login

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