Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Replace the table name in query with variabale value
Forum Updated to NodeBB v4.3 + New Features

Replace the table name in query with variabale value

Scheduled Pinned Locked Moved Solved Qt for Python
21 Posts 5 Posters 5.4k 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.
  • D Offline
    D Offline
    dvlpr.bernard
    wrote on last edited by dvlpr.bernard
    #11

    I didn't meant to offend you guys. I was working on a PyQt app it is just a small school project. Python is the required language, what do I mean is I don't have time to dig deeper on learning other python stuff. I learned the fundamentals and I also interested on the things that I needed. But in this case, I was hyped because I was about to finish my project. The only thing left is replacing the table name in query with variable value and then my project will get finished. That's maybe the reason why I was hyped to get the correct syntax for that.

    I apologize if I said something mean, English is not my first language. I hope you understand. Thank you for both of you :)

    1 Reply Last reply
    0
    • D dvlpr.bernard

      Thank you for your response :)
      But, I'm still getting an error. I apologize, I'm not familiar with the syntax of python.

      table_name = '1.0'
      queryStrTemplate = 'SELECT NO_EXERCISE from {}'
      c.execute(queryStrTemplate.format(table_name))
      
      c.execute('select NO_EXERCISE from {} \'.format(table_name) where SCHED_ID = ?', (1,))
      row = c.fetchone()
      print(row[0])
      

      36612b8b-8c2d-4a1e-bc69-fbafc0f11068-image.png

      D Offline
      D Offline
      dvlpr.bernard
      wrote on last edited by
      #12

      @dvlpr-bernard
      I finally noticed the problem. It must be

      table_name = "\'1.0\'"
      

      not

      table_name = '1.0'
      

      Thank you guys for your help :)

      JonBJ 1 Reply Last reply
      1
      • D dvlpr.bernard

        @dvlpr-bernard
        I finally noticed the problem. It must be

        table_name = "\'1.0\'"
        

        not

        table_name = '1.0'
        

        Thank you guys for your help :)

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #13

        @dvlpr-bernard
        One thing I meant to ask: what editor do you use when writing your Python code? If it's an IDE like PyCharm or VSCode it will helpfully show you when code is syntactically wrong, offer you methods/parameters to choose from etc.; if you are not using an editor with Python syntax you are missing out.

        D 1 Reply Last reply
        1
        • D Offline
          D Offline
          dvlpr.bernard
          wrote on last edited by
          #14

          @Denni-0 Thank you I will take note of that

          1 Reply Last reply
          0
          • JonBJ JonB

            @dvlpr-bernard
            One thing I meant to ask: what editor do you use when writing your Python code? If it's an IDE like PyCharm or VSCode it will helpfully show you when code is syntactically wrong, offer you methods/parameters to choose from etc.; if you are not using an editor with Python syntax you are missing out.

            D Offline
            D Offline
            dvlpr.bernard
            wrote on last edited by
            #15

            @JonB I actually using IDLE hahaha. I do have PyCharm but I got used to the IDLE environment. Prob would gonna try them.

            JonBJ 1 Reply Last reply
            0
            • D dvlpr.bernard

              @JonB I actually using IDLE hahaha. I do have PyCharm but I got used to the IDLE environment. Prob would gonna try them.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #16

              @dvlpr-bernard
              I imagine IDLE, being a Python editor, shows you errors, no? The point was, in your earlier erroneous code, I would have expected your editor to be showing you those lines were incorrect.

              D 1 Reply Last reply
              1
              • JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #17

                @Denni-0
                You would actively choose a generic editor without Python syntax/library knowledge over one which corrects, completes and so on? And you would recommend that to a self-proclaimed beginner?

                1 Reply Last reply
                0
                • JonBJ JonB

                  @dvlpr-bernard
                  I imagine IDLE, being a Python editor, shows you errors, no? The point was, in your earlier erroneous code, I would have expected your editor to be showing you those lines were incorrect.

                  D Offline
                  D Offline
                  dvlpr.bernard
                  wrote on last edited by
                  #18

                  @JonB HAHAHAHAHAH it works fine to me, IDLE also shows where the error is, but not as powerful as other IDE's can do. It would have been a little bit easier if I use other IDE's like PyCharm. But just like I what I have said I had so much fun and excitement using IDLE. Next time I would prob use PyCharm to put myself at ease.

                  1 Reply Last reply
                  0
                  • JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #19

                    @Denni-0
                    No problem. I am surprised you choose a non-Python-environment editor, but that is your choice. :) I am also glad you are happy for the OP or a beginner to use the help he can get from one.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dvlpr.bernard
                      wrote on last edited by
                      #20

                      @Denni-0 I'm sorry sir. I felt bad about the replies(they were indirectly telling me that I don't belong or I shouldn't be here), so I decided to delete it. Forget about it, I appreciate your help sir :).

                      JKSHJ 1 Reply Last reply
                      0
                      • D dvlpr.bernard

                        @Denni-0 I'm sorry sir. I felt bad about the replies(they were indirectly telling me that I don't belong or I shouldn't be here), so I decided to delete it. Forget about it, I appreciate your help sir :).

                        JKSHJ Online
                        JKSHJ Online
                        JKSH
                        Moderators
                        wrote on last edited by
                        #21

                        @dvlpr-bernard said in Replace the table name in query with variabale value:

                        I felt bad about the replies(they were indirectly telling me that I don't belong or I shouldn't be here)

                        Hi @dvlpr-bernard, the Qt Forum is a place which welcomes everybody who wants to learn how to write software using Qt. If anyone says that you shouldn't be here, please let the Moderators know (click the triple-dots at the bottom-right of the post, and select "Flag this post for moderation") because we want to build a helpful and professional environment.

                        Anyway, I reviewed the replies in your other thread (Moderators can see deleted posts). I agree with @Denni-0 -- None of the replies were (directly or indirectly) saying that you don't belong here. Instead, they were saying that you should redesign your SQL database schema in order to solve your problem.

                        @Denni-0 said in Replace the table name in query with variabale value:

                        I would have contacted you directly but cannot figure out how to do that on this forum or even if its possible

                        You can send a Private Message from the user's profile page. Click the triple-dots and select "Start a new chat with <USERNAME>".

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        1 Reply Last reply
                        2

                        • Login

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