I have a list consisting of dictionaries memberthat I inserted into such a database
cursor.executemany("INSERT INTO `Citizens` (`Handle`,`Org`,`Role`, "
"`Rank`,`Visibility`,`Stars`,`Type`) VALUES "
"(%(handle)s,%(sid)s,%(roles)s,%(rank)s,"
"%(visibility)s,%(stars)s,%(type)s)", member)
# Commits changes to the database.
conn.commit()
It worked fine, but when I had problems with duplicate members, I decided to add a sentence ON DUPLICATE. The idea is that if a member is duplicated, we want to update its column Orgby combining the new data. So I changed the code to this
cursor.executemany("INSERT INTO `Citizens` (`Handle`,`Org`,`Role`, "
"`Rank`,`Visibility`,`Stars`,`Type`) VALUES "
"(%(handle)s,%(sid)s,%(roles)s,%(rank)s,"
"%(visibility)s,%(stars)s,%(type)s) ON DUPLICATE"
" KEY UPDATE `Org`=concat(ifnull(`Org`, \"\"), "
"\", \", %(sid)s);", member)
conn.commit()
However, I received the following error:
There was a problem inserting member(s): (1064, "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 '('real_lethality','000',0,'Master','visible',5,'affiliate') ON DUPLICATE KEY UPD' at line 3")
Would you like to see the failed SQL query?[Y/n]
b'INSERT INTO `Citizens` (`Handle`,`Org`,`Role`, `Rank`,`Visibility`,`Stars`,`Type`) VALUES \n(\'fullmetaljim\',\'000\',\'Founder\',\'Master\',\'visible\',5,\'main\') ON DUPLICATE KEY UPDATE `Org`=concat(ifnull(`Org`, ""), ", ", \'000\'),\n(\'real_lethality\',\'000\',0,\'Master\',\'visible\',5,\'affiliate\') ON DUPLICATE KEY UPDATE `Org`=concat(ifnull(`Org`, ""), ", ", \'000\')\n;'
Am I doing it wrong ON DUPLICATE? How can I do this job right?
An example member:
[
{'roles': [],
'rank': 'No SCB account',
'type': 'main',
'stars': 2,
'visibility': 'visible',
'sid': 'imperium',
'handle': 'freakyeagle'
},
{'roles': [],
'rank': 'Fleet Member',
'type': 'main',
'stars': 1,
'visibility': 'visible',
'sid': 'imperium',
'handle': 'cadimus'},
{'roles': [],
'rank': 'Fleet Member',
'type': 'main',
'stars': 1,
'visibility': 'visible',
'sid': 'imperium',
'handle': 'belleal'}
]
EDIT: It seems like this might be a PyMySQL error itself, can anyone confirm this?