(* Implement 'move' subcommand. *) open CalendarLib open Todo_types open Todo_utils open Printf (* The form of the command is one of: * move ID today * move ID [todo|task] deadline * move ID ideas * move ID retired * move ID unsorted *) let cmd_move dbh anon_params = let id, anon_params = match anon_params with | id :: rest -> Int32.of_string id, rest | _ -> error "incorrect parameters to 'move' subcommand" in let dest = match anon_params with | ["today"|"imminent"] -> `Today | ["todo"|"task"; deadline] -> `Todo (Printer.Calendar.from_string deadline) | ["idea"|"ideas"] -> `Ideas | ["retire"|"retired"] -> `Retired | ["none"|"unsorted"] -> `Unsorted | _ -> error "incorrect destination for 'move' subcommand" in PGOCaml.begin_work dbh; (* Remove it from any other table. *) PGSQL(dbh) "delete from imminent where taskid = $id"; PGSQL(dbh) "delete from todo where taskid = $id"; PGSQL(dbh) "delete from ideas where taskid = $id"; PGSQL(dbh) "delete from retired where taskid = $id"; (* Add it to the destination table. *) (match dest with | `Today -> PGSQL(dbh) "insert into imminent (taskid) values ($id)" | `Todo deadline -> PGSQL(dbh) "insert into todo (taskid, deadline) values ($id, $deadline)" | `Ideas -> PGSQL(dbh) "insert into ideas (taskid) values ($id)" | `Retired -> PGSQL(dbh) "insert into retired (taskid) values ($id)" | `Unsorted -> () (* Nothing - unsorted items are not present in any table. *) ); PGOCaml.commit dbh