(* Implement 'retire' subcommand. *) open CalendarLib open Todo_types open Todo_utils open Printf let cmd_retire dbh anon_params = let ids = match anon_params with | [] -> error "give a list of IDs (#ID) to retire" | ids -> List.map Int32.of_string ids in PGOCaml.begin_work dbh; (* It's an error to retire a task which is already retired. *) List.iter ( fun taskid -> let rows = PGSQL(dbh) "select 1 from retired where taskid = $taskid" in if rows = [Some 1_l] then error "task %ld is already retired" taskid; ) ids; (* Drop the tasks from every other table. *) PGSQL(dbh) "delete from imminent where taskid in $@ids"; PGSQL(dbh) "delete from todo where taskid in $@ids"; PGSQL(dbh) "delete from ideas where taskid in $@ids"; (* Add them to the retired table. *) List.iter ( fun taskid -> PGSQL(dbh) "insert into retired (taskid) values ($taskid)" ) ids; PGOCaml.commit dbh