mirror of
https://codeberg.org/Cyberpro123/AO3-DL.git
synced 2026-08-19 22:23:13 +00:00
did Unique Constraint Failed for postgres & mysql
This commit is contained in:
parent
27e842ee02
commit
d2ed46f9a6
1 changed files with 11 additions and 5 deletions
|
|
@ -83,7 +83,10 @@ def execute(
|
|||
for command in commands:
|
||||
logger.debug(command[0])
|
||||
logger.debug(str(command[1])[:100])
|
||||
cur.execute(str(command[0]).replace("?", "%s"), command[1])
|
||||
try:
|
||||
cur.execute(str(command[0]).replace("?", "%s"), command[1])
|
||||
except psycopg.errors.UniqueViolation as ex:
|
||||
raise UniqueConstraintFailed(str(ex))
|
||||
try:
|
||||
output.append(cur.fetchall())
|
||||
except psycopg.ProgrammingError:
|
||||
|
|
@ -107,10 +110,13 @@ def execute(
|
|||
for command in commands:
|
||||
logger.debug(command[0])
|
||||
logger.debug(str(command[1])[:100])
|
||||
cur.execute(
|
||||
command[0].replace("?", "%s").replace("ON CONFLICT DO NOTHING", "ON DUPLICATE KEY UPDATE id = id"),
|
||||
command[1],
|
||||
)
|
||||
try:
|
||||
cur.execute(command[0].replace("?", "%s").replace("ON CONFLICT DO NOTHING", "ON DUPLICATE KEY UPDATE id = id"), command[1])
|
||||
except MySQLdb._exceptions.IntegrityError as ex:
|
||||
if "Duplicate entry" in str(ex):
|
||||
raise UniqueConstraintFailed(str(ex))
|
||||
else:
|
||||
raise ex
|
||||
logger.debug("Executed")
|
||||
output.append(cur.fetchall())
|
||||
con.commit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue