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,
workflow_id,
sort_order,
short_name,
pretty_name,
hide_fields
from workflow_fsm_states
where state_id = :state_id
select state_id
from workflow_fsm_states
where short_name = :short_name
and workflow_id = :workflow_id
select state_id,
sort_order,
short_name,
pretty_name,
hide_fields
from workflow_fsm_states
where workflow_id = :workflow_id
order by sort_order
select workflow_id
from workflow_fsm_states
where state_id = :state_id