Python Forum
updating a field of sql table from a variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
updating a field of sql table from a variable
#1
how can i update a field of sql table from a variable not a string? my table name is variabless.this table contains 2 columns : (name & value) i have the following line in my code:
[
global fasele 
c.execute("UPDATE variabless SET value=fasele WHERE name='fas'")
the point is fasele is a global variable...i think my syntax about inserting a variable(not fixed string) in a field of sql table is not correct (when using from update command) i get the following error
[
 Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__
    return self.func(*args)
  File "/home/pi/start/gui/jus-submeno-image-refreshh.py", line 963, in saving4
    c.execute("UPDATE variabless SET value=fasele WHERE name='fas'")
sqlite3.OperationalError: no such column: fasele
]
Reply
#2
Didn't look very hard, did you?  It's literally the first result: http://lmgtfy.com/?q=python+sql+variable

You're just executing a string.  Try using the variable:
c.execute("update variabless set value=%s where name='fas'", fasele)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating button text based upon different variable values knoxvilles_joker 0 2,231 Apr-18-2021, 04:13 AM
Last Post: knoxvilles_joker
  Updating a variable within a class MC2020 2 2,579 Apr-17-2020, 11:31 AM
Last Post: MC2020
  [Tkinter] Radiobutton in Tkinter not Updating Variable from Value Aidan54321 1 7,364 Jun-16-2017, 11:08 PM
Last Post: Larz60+
  which column of sql table is equal to a variable gray 7 6,034 Mar-20-2017, 04:11 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020