I'm struggling to write this SQL query into a Python script.
All the variables are stored in Python. I need the SQL statement to pass my python variables and then execute the query.
The SQL statement should query col1, col2, col3 in the DB for 'this_string', and then update field1, field2 and field3 with string1, string2, and string3.
But I can't figure it out..
mystring = 'this_string'
string1 = 'test1'
string2 = 'test2'
string3 = 'test3'
UPDATE databaseb.name SET field1 = string1, field2 = string2, field3 = string3 WHERE CONCAT_WS('', column1,column2,column3) LIKE '%this_string%'
I tried this
conn = MySQLdb.connect(host= "1.2.3.4",
user="me",
passwd="passwd",
db="dbname",
use_unicode=True,
charset="utf8")
x = conn.cursor()
x.execute(UPDATE databaseb.name SET field1 = string1, field2 = string2, field3 = string3 WHERE CONCAT_WS('', column1,column2,column3) LIKE '%this_string%'
)
conn.commit()
conn.close()