Answer the question
In order to leave comments, you need to log in
Is it possible to do something similar in python?
Good evening, I worked on the site and thought about how to make it easier to access the database, yes, I know about sqlalchemy and so on. but since I'm a beginner I need to learn everything!
class Set(object):
def __init__(self, table, column, value, value_id):
conn = db.connect()
cursor = conn.cursor()
cursor.execute('''UPDATE %s SET %s = %s WHERE id = %s''', (table, column, value, value_id))
conn.commit()
@Init.route('/')
def init():
Set(table = "app", column = "state", value = "true", value_id = 1)
return ('success')
Flask-MySQL
, from below I have a router that transmits the very information necessary for the class to work. pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''app' SET 'state' = 'true' WHERE id = 1' at line 1")
Set(table = "app", column = "state", value = "true", value_id = 1)
namely, with quotes, MySQL does not accept them, and if you try without them, then this is tantamount to assigning a variable to a variable. Answer the question
In order to leave comments, you need to log in
if state is in the database as a BooleanField, then it is not a string that needs to be passed there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question