This does not work and displays the error "Cannot handle argument: str (Quality Tire Service in Ponteland), it must be of type list, tuple or dictionary"
import mysql.connector from sentence_splitter import SentenceSplitter, split_text_into_sentences mydb = mysql.connector.connect( host="00.00.00.00", user="user", password="password", database="database" ) mycursor = mydb.cursor() sql = ("""SELECT blog_paragraph FROM blog_paragraph WHERE blog_topic like '%"%s"%'""") val = ("Providing Quality Tyre Services in Ponteland") mycursor.execute(sql,val) myresult = mycursor.fetchall() for x in myresult: print(x)
However, when passing the value directly in the query, it seems to run without any errors.
import mysql.connector from sentence_splitter import SentenceSplitter, split_text_into_sentences mydb = mysql.connector.connect( host="00.00.00.00", user="user", password="password", database="database" ) mycursor = mydb.cursor() sql = ("""SELECT blog_paragraph FROM blog_paragraph WHERE blog_topic like '%"Providing Quality Tyre Services in Ponteland"%'""") mycursor.execute(sql) myresult = mycursor.fetchall() for x in myresult: print(x)
Tried passing string parameters via variables, but that doesn't seem to work.
Find the answer later
mycursor = mydb.cursor() val = "Providing Quality Tyre Services in Ponteland" sql = ("SELECT blog_paragraph FROM blog_paragraph WHERE blog_topic like '%%%s%%' " % val) mycursor.execute(sql) myresult = mycursor.fetchall()
As the error states:
Your parameter must be one of the expected types, but you are sending
str
You added brackets on the
val
variable:But the
tuple
is defined by commas,
instead of brackets, this should work: