how add 'x' charactor in front of str?

Viewed 44

table structure

update account set salt=x'9237F5E6A074213B3903B913E7DB3DA46253F6006DF486D87F818A07CCB094EC' where username='abcde';

command update is ok in mysql-cli.

salt = a.hex().upper()

print(salt): 

Prints: '9237F5E6A074213B3903B913E7DB3DA46253F6006DF486D87F818A07CCB094EC'

but error in python3 sqlalchemy: sqlalchemy.exc.StatementError: (builtins.TypeError) string argument without an encoding

1 Answers

x added before the literal claims that the string provided is not a string but hexadecimal literal value.

You cannot do this - add the datatype qualifying literal - programmatically. You must convert the value as-is treating it as hexadecimal literal using according function:

update account 
set salt = UNHEX( {string with hex value as a parameter} )

Of course, salt column must be binary string datatype column.

Related