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

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 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
    • JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on 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
        • JonBJ JonB
          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 last edited by
          #4

          @JNBarchan It must return true but return false

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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
            1
            • SGaistS SGaist

              Did you print the error ?

              M Offline
              M Offline
              mark_ua_1999
              wrote on 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
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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
                0
                • SGaistS SGaist

                  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 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
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 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
                    0
                    • SGaistS SGaist

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

                      M Offline
                      M Offline
                      mark_ua_1999
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 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
                        0
                        • SGaistS SGaist

                          What do you mean by that ?

                          M Offline
                          M Offline
                          mark_ua_1999
                          wrote on 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
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 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
                            0
                            • SGaistS SGaist

                              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 last edited by
                              #14

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

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 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
                                1
                                • SGaistS SGaist

                                  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 last edited by mark_ua_1999
                                  #16

                                  @SGaist yes you are right sorry

                                  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