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 write this correctly? Update query in pyqt string and int
Forum Update on Monday, May 27th 2025

How to write this correctly? Update query in pyqt string and int

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 2 Posters 5.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 22 Jan 2017, 08:04 last edited by
    #1

    query = ("""UPDATE test_table SET name = '%s' WHERE num = '%i'"""%str(data),int(num))

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 22 Jan 2017, 08:38 last edited by
      #2

      Hi
      There are samples here.
      http://pythoncentral.io/introduction-to-sqlite-in-python/

      and
      http://www.qtcentre.org/threads/16413-Extracting-QSqlQuery-results-in-PyQt4

      ? 1 Reply Last reply 22 Jan 2017, 08:56
      0
      • M mrjj
        22 Jan 2017, 08:38

        Hi
        There are samples here.
        http://pythoncentral.io/introduction-to-sqlite-in-python/

        and
        http://www.qtcentre.org/threads/16413-Extracting-QSqlQuery-results-in-PyQt4

        ? Offline
        ? Offline
        A Former User
        wrote on 22 Jan 2017, 08:56 last edited by
        #3

        @mrjj
        my code is invalid syntax

        query = ("UPDATE test_table SET name = '%s' WHERE age = %i"%str(data),%int(num))

        M 1 Reply Last reply 22 Jan 2017, 09:01
        0
        • ? A Former User
          22 Jan 2017, 08:56

          @mrjj
          my code is invalid syntax

          query = ("UPDATE test_table SET name = '%s' WHERE age = %i"%str(data),%int(num))

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 22 Jan 2017, 09:01 last edited by
          #4

          @Gelo
          Yes :)
          You should read the docs and look at the samples.
          There are many examples on the net for pyt.

          ? 2 Replies Last reply 22 Jan 2017, 09:02
          0
          • M mrjj
            22 Jan 2017, 09:01

            @Gelo
            Yes :)
            You should read the docs and look at the samples.
            There are many examples on the net for pyt.

            ? Offline
            ? Offline
            A Former User
            wrote on 22 Jan 2017, 09:02 last edited by
            #5

            @mrjj please help me correct it

            M 1 Reply Last reply 22 Jan 2017, 09:04
            0
            • M mrjj
              22 Jan 2017, 09:01

              @Gelo
              Yes :)
              You should read the docs and look at the samples.
              There are many examples on the net for pyt.

              ? Offline
              ? Offline
              A Former User
              wrote on 22 Jan 2017, 09:03 last edited by
              #6

              @mrjj i am using MySql

              1 Reply Last reply
              0
              • ? A Former User
                22 Jan 2017, 09:02

                @mrjj please help me correct it

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 22 Jan 2017, 09:04 last edited by
                #7

                @Gelo

                query_str = 'SELECT %s FROM track %s'%(select_string, where_string)
                

                Thats how they do for the select. You can do the same for UPDATE

                ? 1 Reply Last reply 22 Jan 2017, 09:06
                0
                • M mrjj
                  22 Jan 2017, 09:04

                  @Gelo

                  query_str = 'SELECT %s FROM track %s'%(select_string, where_string)
                  

                  Thats how they do for the select. You can do the same for UPDATE

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on 22 Jan 2017, 09:06 last edited by
                  #8

                  @mrjj still invalid sysntax

                  M 1 Reply Last reply 22 Jan 2017, 09:07
                  0
                  • ? A Former User
                    22 Jan 2017, 09:06

                    @mrjj still invalid sysntax

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 22 Jan 2017, 09:07 last edited by
                    #9

                    @Gelo
                    well look at the links :)
                    Tons of samples.
                    Some must be valid.

                    U are also new to python ?
                    Most of this is not Qt related but python syntax.

                    ? 3 Replies Last reply 22 Jan 2017, 09:12
                    0
                    • M mrjj
                      22 Jan 2017, 09:07

                      @Gelo
                      well look at the links :)
                      Tons of samples.
                      Some must be valid.

                      U are also new to python ?
                      Most of this is not Qt related but python syntax.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on 22 Jan 2017, 09:12 last edited by
                      #10

                      @mrjj if convert int to string? is that valid to MySql ?

                      query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%str(data,data1))
                      Traceback (most recent call last):
                      File "<pyshell#12>", line 1, in <module>
                      query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%str(data,data1))
                      TypeError: decoding str is not supported

                      1 Reply Last reply
                      0
                      • M mrjj
                        22 Jan 2017, 09:07

                        @Gelo
                        well look at the links :)
                        Tons of samples.
                        Some must be valid.

                        U are also new to python ?
                        Most of this is not Qt related but python syntax.

                        ? Offline
                        ? Offline
                        A Former User
                        wrote on 22 Jan 2017, 09:14 last edited by
                        #11

                        @mrjj i only found dynamic input for Sqlite not MySql

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 22 Jan 2017, 09:14 last edited by mrjj
                          #12

                          Hi
                          Use str for the int NOT for all of it

                          query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%(data,str(THE INT)))

                          str convert to string. but it only takes one parameter.

                          ? 2 Replies Last reply 22 Jan 2017, 09:17
                          0
                          • M mrjj
                            22 Jan 2017, 09:14

                            Hi
                            Use str for the int NOT for all of it

                            query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%(data,str(THE INT)))

                            str convert to string. but it only takes one parameter.

                            ? Offline
                            ? Offline
                            A Former User
                            wrote on 22 Jan 2017, 09:17 last edited by
                            #13

                            @mrjj do you think it will accept by MySql? in my variable type int ?

                            UPDATE test_table SET name = 'aaaaa' WHERE age = '10101'??

                            M 1 Reply Last reply 22 Jan 2017, 09:22
                            0
                            • ? A Former User
                              22 Jan 2017, 09:17

                              @mrjj do you think it will accept by MySql? in my variable type int ?

                              UPDATE test_table SET name = 'aaaaa' WHERE age = '10101'??

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 22 Jan 2017, 09:22 last edited by
                              #14

                              @Gelo
                              Yes it should accept int if the table have it.
                              if age is int. The table defines types for each column so age have to be declared as int.

                              1 Reply Last reply
                              0
                              • M mrjj
                                22 Jan 2017, 09:14

                                Hi
                                Use str for the int NOT for all of it

                                query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%(data,str(THE INT)))

                                str convert to string. but it only takes one parameter.

                                ? Offline
                                ? Offline
                                A Former User
                                wrote on 22 Jan 2017, 09:33 last edited by
                                #15

                                @mrjj Thank you so much for your help!

                                1 Reply Last reply
                                1
                                • M mrjj
                                  22 Jan 2017, 09:07

                                  @Gelo
                                  well look at the links :)
                                  Tons of samples.
                                  Some must be valid.

                                  U are also new to python ?
                                  Most of this is not Qt related but python syntax.

                                  ? Offline
                                  ? Offline
                                  A Former User
                                  wrote on 22 Jan 2017, 09:33 last edited by
                                  #16

                                  @mrjj can you explain me this one?

                                  query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%(data,str(THE INT)))

                                  M 1 Reply Last reply 22 Jan 2017, 09:41
                                  0
                                  • ? A Former User
                                    22 Jan 2017, 09:33

                                    @mrjj can you explain me this one?

                                    query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%(data,str(THE INT)))

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 22 Jan 2017, 09:41 last edited by
                                    #17

                                    @Gelo

                                    well THE INT should be an int variable

                                    query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%(data,str(data2)))

                                    data2 is then the int

                                    Other that that the SQL says ,
                                    Change the value of name for all where age is data2

                                    ? 1 Reply Last reply 22 Jan 2017, 09:45
                                    0
                                    • M mrjj
                                      22 Jan 2017, 09:41

                                      @Gelo

                                      well THE INT should be an int variable

                                      query = ("UPDATE test_table SET name = '%s' WHERE age = '%s'"%(data,str(data2)))

                                      data2 is then the int

                                      Other that that the SQL says ,
                                      Change the value of name for all where age is data2

                                      ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on 22 Jan 2017, 09:45 last edited by
                                      #18

                                      @mrjj Thank you so much sir GodBless! You! :)

                                      1 Reply Last reply
                                      1

                                      4/18

                                      22 Jan 2017, 09:01

                                      topic:navigator.unread, 14
                                      • Login

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