Handling mysql trigger using python
Loading
Handling mysql trigger using python
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Md SarfarajPosted Jul 1, 2022, 6:43 AM
Jay Krishna ReddyPosted Jun 30, 2022, 8:53 AM
For anyone else coming along with this problem (or on the off-chance that this is still an issue for the asker nearly 11 months later):
DELIMITER is a feature only of the CLI (not the server itself), so the various connectors won't know what to do with it. I ended up solving my same problem by removing the DELIMITER statement and anything that relied on it and moving the entire trigger statement onto one line to execute at once. Because it's all in one execution, the connector determines that the semicolons don't end the statement.
cursor.execute(" drop trigger if exists mytrigger")
## NEW CODE ##
qrystr = "CREATE TRIGGER mytrigger BEFORE INSERT ON MYTABLE FOR EACH ROW BEGIN IF (select COUNT(*) from MYTABLE) = 12 THEN SET NEW.COL2 = 10; END IF; END"
##############
cursor.execute(qrystr)
cnx.commit()
cnx.close()
Hope this helps you