I'm working on a project of a simple chatting app, using python. In order to save the data of each client, I use a MySql database. When a new member signs up, a column is added to one of my tables, in the database. Everything worked fine. I decided to support usernames containing emojis. I thought it would be useful to convert the emojis to strings. For that, I use the demojize() function:
client_name = qwer😜
name2save = emoji.demojize(client_name)
# name2save = qwer:winking_face_with_tongue:
Then, in order to add the column to my table, I use the follwing SQL qwery:
"ALTER TABLE private_chats ADD COLUMN '" + emoji.demojize(name2save) + "' TEXT(6000)"
When I run the qwery I get the follwing error:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''qwer:winking_face_with_tongue:' TEXT(6000)' at line 1
I think the problem is the colons in that username. My question is how am I supposed to add a column name, containing colons or any other reserved chars, to a MySql table?
I am not sure but you may not use single quotation marks
'
for column identifiers but backtick
`
instead.