Indeed, the best approach is to allow the module to shield the values ββon its own. If you absolutely need to do this manually (for example, I want to print SQL only in script debugging mode, and mysql.connector does not seem to implement mogrify() ), there is another option:
>>>> import mysql.connector >>>> cnx = mysql.connector.connect() >>>> cur = cnx.cursor() >>>> cur._connection.converter.escape("tic ' toc") "tic \\' toc"
Admittedly, it still uses the "non-public API", but at least it does not contradict the latest versions (for now; tested on 2.0.4, 2.1.3, 2.2.9, 8.0.16).
Klas Ε .
source share