I am using a connection/cursor to migrate data from an old database/schema into a new one built with Django models. I encounter a problem with names that have an apostrophe
to simplify
business = "Tom's Diner"
cursor.execute("select * from businesses where name = '" + business + "'")
This would obviously fail as I'm forcing a single quote which causes an SQL syntax problem. It would work if I did this:
business = "Tom''s Diner"
But as this is an automated process that deals with migrating millions of rows. I am looking for a way to escape my string before applying it to the direct MySQL query.
My question: is that something I have to do manually, or is there some function in Django/Python that escapes strings, and may handle cases I haven't even thought of yet, like double quotes in the string, etc.