1
0

create_database.rkt 985 B

1234567891011121314151617181920212223242526272829303132
  1. #lang racket/base
  2. ;; This program creates a sqlite3 database and then creates an empty table
  3. ;; for predictions.
  4. (require db)
  5. ; create the database and create the table
  6. (define (createdb dbloc)
  7. (write-string (string-append "Creating database " dbloc "\n"))
  8. (define conn (sqlite3-connect #:database dbloc
  9. #:mode 'create))
  10. (query-exec conn "CREATE TABLE proposals (ID INTEGER NOT NULL,
  11. prediction TEXT NOT NULL,
  12. categories TEXT DEFAULT '',
  13. forecast float,
  14. outcome int,
  15. comments TEXT DEFAULT '')")
  16. (disconnect conn)
  17. (write-string (string-append "Database created at " dbloc "\n")))
  18. ; load configuration file
  19. (require (file "../config.rkt"))
  20. ; make sure we can use the sqlite3 connection
  21. (cond (not (sqlite3-available?))
  22. (error "Sqlite3 library not available."))
  23. ; create the database and add the `proposals` table if it doesn't exist
  24. (if (not (file-exists? dbloc))
  25. (createdb dbloc)
  26. (write-string "Database exists. Exiting."))