.net - MySQL Trigger Execution Order -
i have table has both after insert
, after update
trigger on it. if i, both insert records , update records in single command, in order triggers fire?
after building test project able answer. triggers fired in order in rows in table. if had table after insert, after update, , after delete triggers, fire in order rows triggering them in. tested in mysql 5.6.
here requested sample
public function updatetriggerrecords(byval dt datatable) boolean try return performupdate(dt, setuptriggerrecords_update(), setuptriggerrecords_insert(), setuptriggerrecords_delete(), false) catch ex exception throw ex end try end function private function setuptriggerrecords_update() mysqlcommand dim cmd new mysqlcommand("update tbltriggerrecords set strdescription=@strdescription, inttestingvalue=@inttestingvalue " & _ "where idtriggerrecords=@idtriggerrecords") createtriggerrecordsparameters(cmd) createtriggerrecordsidparameters(cmd) return cmd end function private function setuptriggerrecords_insert() mysqlcommand dim cmd new mysqlcommand("insert tbltriggerrecords(strdescription,inttestingvalue) " & _ "values(@strdescription,@inttestingvalue)") createtriggerrecordsparameters(cmd) return cmd end function private function setuptriggerrecords_delete() mysqlcommand dim cmd new mysqlcommand("delete tbltriggerrecords idtriggerrecords=@idtriggerrecords") createtriggerrecordsidparameters(cmd) return cmd end function private sub createtriggerrecordsidparameters(byval cmd mysqlcommand) cmd.parameters.add("@idtriggerrecords", mysqldbtype.int32).sourcecolumn = "idtriggerrecords" end sub private sub createtriggerrecordsparameters(byval cmd mysqlcommand) cmd.parameters.add("@strdescription", mysqldbtype.varchar).sourcecolumn = "strdescription" cmd.parameters.add("@inttestingvalue", mysqldbtype.int32).sourcecolumn = "inttestingvalue" end sub private function performupdate(byval dt datatable, byval cmdupdate mysqlcommand, byval cmdinsert mysqlcommand, byval cmddelete mysqlcommand, byval captureprimarykeyvalue boolean) boolean if connmysql nothing connmysql = new mysqlconnection(connstrmysql) end if using connmysql if connmysql.state <> connectionstate.open connmysql.connectionstring = connstrmysql connmysql.open() end if trans = connmysql.begintransaction dim da new mysqldataadapter("", connmysql) cmdupdate.connection = connmysql cmdupdate.transaction = trans cmdinsert.connection = connmysql cmdinsert.transaction = trans if cmddelete isnot nothing cmddelete.connection = connmysql cmddelete.transaction = trans end if try if captureprimarykeyvalue = true addhandler da.rowupdated, new mysqlrowupdatedeventhandler(addressof onrowupdatedmysql) end if da.updatecommand = cmdupdate da.insertcommand = cmdinsert if cmddelete isnot nothing da.deletecommand = cmddelete end if da.update(dt) if captureprimarykeyvalue = true removehandler da.rowupdated, addressof onrowupdatedmysql end if performupdate = true trans.commit() catch ex exception trans.rollback() performupdate = false if connmysql.state <> connectionstate.closed connmysql.close() end if end try end using end function
Comments
Post a Comment