Python Forum

Full Version: updating a field of sql table from a variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
]
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)