0

Im having a problem inserting a variable into sqlite3 and the variable is hashed. Here's my code:

if passadefinir == passadefinir2:
    maindb.execute("DELETE FROM Password WHERE ID = 'not'")
    maindb.execute("INSERT INTO Password(ID) VALUES ('set')")
    encriptacao = hashlib.sha1(passadefinir2.encode())
    encriptado = (encriptacao.hexdigest(),)
    maindb.execute("INSERT INTO Password(Password) VALUES (?)" (encriptado,))
    conn.commit()

Here's the error:

Traceback (most recent call last): File "sqlitetesting.py", line 28, in maindb.execute("INSERT INTO Password(Password) VALUES (?)" (encriptado,)) TypeError: 'str' object is not callable

Have a nice day :D, Luis Duarte.

Luís Duarte
  • 39
  • 1
  • 7

1 Answers1

0

You can substitute using String's format method

password_var = 'your password'
insert_statement = 'INSERT INTO Password(Password) VALUES ({0})'.format('\'' + password_var + '\'')

then run the execute method as:

maindb.execute(insert_statement)
somesingsomsing
  • 3,182
  • 4
  • 29
  • 46