i send to get http://localhost/myquery?id=3&type1=3,2,1
# i need to get from frontend values only like this 1,2,3 D:
this is my code:
app.get("/myurl")
async def read_few_types_by_id(type1: str, id: int):
type1 = type1.split(',')
conn = mysql_connection()
cursor = conn.cursor(dictionary=True)
query_inc_params = {'id' : id,'type1': one_type }
query_inc = ("SELECT * from mytable WHERE id=%(id)s and type IN (%(type1)s);")
cursor.execute(query_inc, query_inc_params)
print(cursor._executed)
result = cursor.fetchall()
print(result)
i got error mysql.connector.errors.ProgrammingError: Failed processing pyformat-parameters; Python 'list' cannot be converted to a MySQL type
but i got only one row from DB when im using this thing
type1 = type1.split(',')
type_list = ', '.join(type1)
. when i release sql query in DB i get 3 rows, but this query_inc always get only one row for the 1st value in my list.
i checked what i have in values it is str
3,2,1
- this is type1 value before split.
<class 'str'>
- this is print(type(type1[0])
this is my cursor executed b"SELECT * from mytable WHERE inc_id=3 and type IN ('3, 2, 1');"
what i do wrong?