sqlite3 “OperationalError: near ”)“: syntax error” python -
this function supposed check ingredient user entered following prompt. when try query statement in sqlite (without user input of course) works. in python says there error!
def checkingredient(): usringredient = input("\nenter ingredient make drink with: \n\n") query = c.execute("select drdesc drinks drdrid in " "(select dtdrid detail ingid =" "(select ingid ingredients indesc like))", (usringredient,)) resultset = c.fetchall() result in resultset: if resultset not none: print(result) else: print("sorry, there no drinks ingredient")
you haven't included sql parameter placeholder in query. you'll have place ? in query each value want interpolate:
query = c.execute(""" select drdesc drinks drdrid in (select dtdrid detail ingid = (select ingid ingredients indesc ?)) """, (usringredient,)) you may want making joins, doubt using nested selects going perform well. suspect following work better:
query = c.execute(""" select dr.drdesc drinks dr inner join detail dtd on dr.drdrid == dtd.dtdrid inner join ingredients ing on dtd.ingid = ing.ingid ing.indesc ? """, (usringredient,)) if wanted usringredient treated substring search, you'll have add wildcards like work correctly. surround value % characters:
usringredient = '%{}%'.format(usringredient) this replaces string eggs %eggs% find matching ingredient descriptions contain text eggs.
Comments
Post a Comment