mysql - python MySQLDb insert with prepared Statements -


this question has answer here:

i have table fields

table_paste(       user_text longtext not null,       number integer not null  ) 

i trying insert row in table table_paste python using mysqldb driver.

text="large_text" value = 1 cursor.execute("update table_paste set user_text = ? number = ?",(text,value)) 

am getting error

query = query % db.literal(args) typeerror: not arguments converted during string formatting 

with mysqldb want use parameterized (prepared statements technically don't exist in python) statements similar string formatting in python 2.x.

cursor.execute("update table_paste set user_text = %s number = %s",(text,value)) 

note though value int still must use %s format in query.

you can find tutorial on mysqldb here.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -