update_proposals.rkt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #lang racket
  2. (require db)
  3. ; load configuration file
  4. (require (file "config.rkt"))
  5. ; set up command line arguments
  6. (define mode (command-line
  7. #:program "update_proposals"
  8. #:args (updatetype) ; (add, update)
  9. updatetype))
  10. ; set up a condensed prompt for getting information
  11. (define (getinput prompt)
  12. (write-string prompt)
  13. (write-string ": ")
  14. (read-line))
  15. (define (addnew)
  16. (write-string "Adding new proposal to database.\n")
  17. ; user inputs proposal data
  18. (define proptype (getinput "Proposal type"))
  19. (define org (getinput "Submitting organization"))
  20. (define solic (getinput "Solitation/call"))
  21. (define tele (getinput "Telescope"))
  22. (define title (getinput "Proposal title"))
  23. (define pi (getinput "PI"))
  24. (define coi (getinput "CoIs"))
  25. ; assume all these proposals are submitted, don't ask the user
  26. (define status "submitted")
  27. (define submitdate (getinput "Submit date"))
  28. (define oID (getinput "Organization's proposal ID"))
  29. ; do the INSERT into the Sqlite database
  30. (query-exec conn "INSERT INTO proposals (type, organization, solicitation, telescope, PI, title, CoI, status, submitdate, orgpropID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
  31. proptype org solic tele pi title coi status submitdate oID))
  32. ; update an entry
  33. (define (update)
  34. (write-string "Updating entry")
  35. )
  36. ; make sure we can use the sqlite3 connection
  37. (cond (not (sqlite3-available?))
  38. (error "Sqlite3 library not available."))
  39. ; open the database file
  40. (define conn (sqlite3-connect #:database dbloc))
  41. ; determine which mode we're in
  42. (cond
  43. [(regexp-match "add" mode) (addnew)]
  44. [(regexp-match "update" mode) (update)])
  45. ; close the databse
  46. (disconnect conn)