#sql DELETE

15 messages · Page 1 of 1 (latest)

stark sand
#

Hello I want to delete data from a SQLite database but for some reason unknown to me this only works if I don't use a variable but I need this variable does anyone have an idea?

pure pike
#

Thanks for your question :clap:, if someone gives you an answer it would be great if you thanked them with a :white_check_mark: in response. This response will earn you both points for special roles on this server.

stark sand
#

my code is:
async def delete_code_after_delay(dcnamen, ingamenamen):
print("testsdöf.ü#xgclgr")
await asyncio.sleep(10) # Warte für 600 Sekunden (10 Minuten)
try:
ingamenamen = "'" + ingamenamen + "'"
print(ingamenamen)
cur.execute(f"DELETE FROM verify_code WHERE mcplayer = ?", (ingamenamen,))
con.commit()
res = cur.execute("SELECT * FROM verify_code")
res = res.fetchall()
print(res)
print(f"Verifizierungscode für {dcnamen} und {ingamenamen} wurde nach 10 Minuten gelöscht.")
except Exception as e:
print(f"Ein Fehler ist aufgetreten: {e}")

def verifycode(dcnamen, ingamenamen):
code = random.randint(10000, 99999)
print(code)
cur.execute("""
INSERT INTO verify_code VALUES
(?, ?, ?)
""", (dcnamen, ingamenamen, code))
con.commit()

asyncio.ensure_future(delete_code_after_delay(dcnamen, ingamenamen))
balmy dome
#

yo wiredwolf445347

stark sand
#

hey

balmy dome
#

seems like ur problem is with the way ur handling variables in the sql query

#

try doing this:

#

cur.execute('DELETE FROM verify_code WHERE mcplayer = ?', (ingamenamen,))

stark sand
#

with the word python ore without xd

#

wait i will try

balmy dome
#

instead of using f-strings directly in the query

#

also make sure ingamenamen isn't empty or null when ur calling the function

#

good luck dude