mysql - Error 1442 (HY000): Can't update table in stored function/trigger because it is already used by a statement which invoked this stored function/trigger -
hope well.
i trying move data 1 table i'm getting below error, literally driving me insane can't see logical reason why won't work - infact i've ran same query in past no problem @ all!
error 1442 (hy000): can't update table 'bb_events' in stored function/trigger because used statement invoked stored function/trigger.
the query running is:
insert `bb_events` ( `account_id`, `device_id`, `timestamp`, `status_code`, `latitude`, `longitude`, `speed`, `heading`, `odometer`, `address`, `street`, `city`, `state`, `postcode`, `country`, `geozone_id`, `battery_volts`, `driver_id`, `engine_time`, `idle_time`, `work_time`) select `accountid` `account_id`, `deviceid` `device_id`, `timestamp` `timestamp`, `statuscode` `status_code`, `latitude`, `longitude`, `speedkph`*0.621371192 `speed`, `heading`, `odometerkm`*0.621371192 `odometer`, `address`, `streetaddress` `street`, `city`, `stateprovince` `state`, `postalcode` `postcode`, `country`, `geozoneid` `geozone_id`, `batteryvolts` `battery_volts`, `driverid` `driver_id`, `enginehours`*3600 `engine_time`, `idlehours`*3600 `idle_time`, `workhours`*3600 `work_time` `eventdata`; on bb_events table have trigger setup follows:-
delimiter $$ drop trigger /*!50032 if exists */ `event_insert_after` $$ create trigger `event_insert_after` after insert on `bb_events` each row begin update `bb_device` set `latitude` = new.`latitude`, `longitude` = new.`longitude`, `status_code` = new.`status_code`, `timestamp` = new.`timestamp`, `speed` = new.`speed`, `driver_id` = new.`driver_id`, `heading` = new.`heading` `account_id` = new.`account_id` , `device_id` = new.`device_id`; if new.`status_code` = 62465 insert `bb_journey` (`account_id`, `device_id`, `start_timestamp`, `start_street`, `start_city`, `start_state`, `start_country`, `start_latitude`, `start_longitude`, `start_geozone`, `start_odometer`) values (new.`account_id`, new.`device_id`, new.`timestamp`, new.`street`, new.`city`, new.`state`, new.`country`, new.`latitude`, new.`longitude`, new.`geozone_id`, new.`odometer`); update `bb_device` set `current_journey` = (select `id` `bb_journey` `account_id` = new.`account_id` , `device_id` = new.`device_id` order `id` desc limit 1) `account_id` = new.`account_id` , `device_id` = new.`device_id`; end if; if new.`status_code` = 62467 update `bb_journey` set `end_timestamp` = new.`timestamp`, `end_street` = new.`street`, `end_city` = new.`city`, `end_state` = new.`state`, `end_country` = new.`country`, `end_latitude` = new.`latitude`, `end_longitude` = new.`longitude`, `end_geozone` = new.`geozone_id`, `end_odometer` = new.`odometer` `id` = (select `current_journey` `bb_device` `account_id` = new.`account_id` , `device_id` = new.`device_id` order `id` desc limit 1); update `bb_device` set `current_journey` = '' `account_id` = new.`account_id` , `device_id` = new.`device_id`; end if; end; $$ i have tried running trigger before insert, didn't work either. surely has got simple fix :s.
thanks in advance,
paul
Comments
Post a Comment