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. Got problem with prepare statement in sqlite
QtWS25 Last Chance

Got problem with prepare statement in sqlite

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 4.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.
  • M Offline
    M Offline
    mark_ua_1999
    wrote on 15 Nov 2017, 19:29 last edited by mark_ua_1999
    #1

    this is my code the prepare statement return false but why
    do you have any ideas how to resolve the problem (I notice that my code dont execute step by step the Add function is executed last although is first(db functions is eqecuted firstly) why )

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JonB
      wrote on 15 Nov 2017, 19:50 last edited by
      #2
      93.  if( r_3.prepare("INSERT INTO "+dataB+" (depart_city,arrival_city,firstname,lastname,bot,vagon,place,privileges,distance,ticket_price)"
      
      
      94.                                  "VALUES (?,?,?,?,?,?,?,?,?,?)"))// return false
      

      Where do you bind the values for the INSERT?

      M 1 Reply Last reply 15 Nov 2017, 20:03
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 15 Nov 2017, 19:51 last edited by
        #3

        Hi,

        You should check that all your prepare and exec call are successful and if its not the case, print the error. That's the only way we might be able to help you.

        You should also consider re-writing your string building code. It's hard to read and easily error prone. Take advantage of QString's arg methods to help build your query strings.

        On a side note, why are you re-creating the same database connection again and again ?

        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
        • J JonB
          15 Nov 2017, 19:50
          93.  if( r_3.prepare("INSERT INTO "+dataB+" (depart_city,arrival_city,firstname,lastname,bot,vagon,place,privileges,distance,ticket_price)"
          
          
          94.                                  "VALUES (?,?,?,?,?,?,?,?,?,?)"))// return false
          

          Where do you bind the values for the INSERT?

          M Offline
          M Offline
          mark_ua_1999
          wrote on 15 Nov 2017, 20:03 last edited by
          #4

          @JNBarchan It must return true but return false

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 15 Nov 2017, 20:09 last edited by
            #5

            Did you print the error ?

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

            M 1 Reply Last reply 15 Nov 2017, 20:37
            1
            • S SGaist
              15 Nov 2017, 20:09

              Did you print the error ?

              M Offline
              M Offline
              mark_ua_1999
              wrote on 15 Nov 2017, 20:37 last edited by
              #6

              @SGaist I rearrange my code an it began to work but I have got another problem my working code the code is to slow from user vision (firstly it inserts new records to db table and only than add the row (Add function although) it goes first and returns bool result)
              what is your ideas about it
              0_1510778233346_Capture.PNG

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 15 Nov 2017, 20:43 last edited by
                #7

                You are trying to open your database twice.

                Again, like already wrote before: open your connection once at application startup and then just do your queries. You'll avoid losing time with that.

                As for performance, what else is your application doing ?

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

                M 1 Reply Last reply 15 Nov 2017, 20:47
                0
                • S SGaist
                  15 Nov 2017, 20:43

                  You are trying to open your database twice.

                  Again, like already wrote before: open your connection once at application startup and then just do your queries. You'll avoid losing time with that.

                  As for performance, what else is your application doing ?

                  M Offline
                  M Offline
                  mark_ua_1999
                  wrote on 15 Nov 2017, 20:47 last edited by
                  #8

                  @SGaist I understand you but I failed to do it it doesnt see the db as opened (I opened it in constructor)

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 15 Nov 2017, 20:50 last edited by
                    #9

                    Then fix your database initialisation in the constructor rather than trying to work around.

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

                    M 1 Reply Last reply 15 Nov 2017, 20:53
                    0
                    • S SGaist
                      15 Nov 2017, 20:50

                      Then fix your database initialisation in the constructor rather than trying to work around.

                      M Offline
                      M Offline
                      mark_ua_1999
                      wrote on 15 Nov 2017, 20:53 last edited by
                      #10

                      @SGaist And what about not line by line code execution?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 15 Nov 2017, 20:56 last edited by
                        #11

                        What do you mean by that ?

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

                        M 1 Reply Last reply 15 Nov 2017, 20:59
                        0
                        • S SGaist
                          15 Nov 2017, 20:56

                          What do you mean by that ?

                          M Offline
                          M Offline
                          mark_ua_1999
                          wrote on 15 Nov 2017, 20:59 last edited by
                          #12

                          @SGaist I mean by that that the code is to slow from user vision (firstly it inserts new records to db table and only than add the row (Add function although) it goes first and returns bool result)the code

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 15 Nov 2017, 21:03 last edited by
                            #13

                            There's no way to evaluate why your application is slow based only on one function.

                            Do some profiling on your application to understand what takes so much time.

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

                            M 1 Reply Last reply 15 Nov 2017, 21:08
                            0
                            • S SGaist
                              15 Nov 2017, 21:03

                              There's no way to evaluate why your application is slow based only on one function.

                              Do some profiling on your application to understand what takes so much time.

                              M Offline
                              M Offline
                              mark_ua_1999
                              wrote on 15 Nov 2017, 21:08 last edited by
                              #14

                              @SGaist ADD function must execute first!!! But not

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 15 Nov 2017, 21:19 last edited by
                                #15

                                Full uppercased words and many exclamation marks are not the best way to communicate when people are trying to help you on their own time.

                                You are only providing a small part of your code and stating that your users find it slow. I already gave you some suggestions to make it a bit faster but you said that you couldn't make it work in some other unknown part of your code.

                                Now, how can you expect anybody to provide you with advices based on that ?

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

                                M 1 Reply Last reply 15 Nov 2017, 21:26
                                1
                                • S SGaist
                                  15 Nov 2017, 21:19

                                  Full uppercased words and many exclamation marks are not the best way to communicate when people are trying to help you on their own time.

                                  You are only providing a small part of your code and stating that your users find it slow. I already gave you some suggestions to make it a bit faster but you said that you couldn't make it work in some other unknown part of your code.

                                  Now, how can you expect anybody to provide you with advices based on that ?

                                  M Offline
                                  M Offline
                                  mark_ua_1999
                                  wrote on 15 Nov 2017, 21:26 last edited by mark_ua_1999
                                  #16

                                  @SGaist yes you are right sorry

                                  1 Reply Last reply
                                  0

                                  1/16

                                  15 Nov 2017, 19:29

                                  • Login

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