select count(*)
from workflow_fsm_states
where workflow_id = :workflow_id
and sort_order = :sort_order
update workflow_fsm_states
set sort_order = sort_order + 1
where workflow_id = :workflow_id
and sort_order >= :sort_order
insert into workflow_fsm_states
(state_id, workflow_id, sort_order, short_name, pretty_name, hide_fields)
values (:state_id, :workflow_id, :sort_order, :short_name, :pretty_name, :hide_fields)
select state_id
from workflow_fsm_states
where short_name = :short_name
and workflow_id = :workflow_id
select s.workflow_id,
s.state_id,
s.sort_order,
s.short_name,
s.pretty_name,
s.hide_fields,
s.parent_action_id,
(select short_name from workflow_actions where action_id = s.parent_action_id) as parent_action
from workflow_fsm_states s
where s.workflow_id = :workflow_id
order by s.sort_order
select workflow_id
from workflow_fsm_states
where state_id = :state_id
delete from workflow_fsm_action_en_in_st
where state_id = :state_id
and assigned_p = :assigned_p
insert into workflow_fsm_action_en_in_st
(action_id, state_id, assigned_p)
values (:enabled_action_id, :state_id, :assigned_p)