Re: Escaping Strings
"J.O. Aho" <[email protected]> Mon, 19 Aug 2024 11:24:06 +0200
| Newsgroups | comp.databases.mysql |
|---|---|
| Message-ID | <[email protected]> |
On 16/07/2024 00.46, Lawrence D'Oliveiro wrote:
> In standard SQL, backslashes have no special significance. String literals
> are delimited by single quotes, and any characters (except single quotes)
> are allowed in them; to include a single quote in the string, write it
> twice.
>
> So in Python, this expression is sufficient to turn a string āsā into a
> standard SQL string literal:
>
> "'" + s.replace("'", "''") + "'"
I would looked into using parameterized queries, here is a python example
https://pynative.com/python-mysql-execute-parameterized-query-using-prepared-statement/
--
//Aho