0

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?

flamixx
  • 57
  • 5
  • You have to iterate over the cursor to get the value. A cursor is a pointer which holds the location of the data in memory and not the entire data. – innocent May 16 '22 at 17:13
  • how to do that? im using `cursor.execute(query_inc, query_inc_params)` – flamixx May 16 '22 at 17:16
  • read the docs for the mysql related to python cursor you will know. Time spent researching this is time utilised – innocent May 16 '22 at 17:17

0 Answers0