Răsfoiți Sursa

remove (need for) dummy prediction entry upon DB creation

George C. Privon 7 ani în urmă
părinte
comite
e5f9f8c37a
2 a modificat fișierele cu 5 adăugiri și 5 ștergeri
  1. 0 3
      code/create_database.rkt
  2. 5 2
      code/update_predictions.rkt

+ 0 - 3
code/create_database.rkt

@@ -21,9 +21,6 @@ categories TEXT DEFAULT '',
 forecast float DEFAULT NULL,
 forecast float DEFAULT NULL,
 outcome int DEFAULT NULL,
 outcome int DEFAULT NULL,
 comments TEXT DEFAULT '')")
 comments TEXT DEFAULT '')")
-  ; add a dummy entry
-  (query-exec conn "INSERT INTO predictions (ID, date, prediction, outcome) values (0, ?, \"\",0)"
-              (date->string (seconds->date (current-seconds))))
   (disconnect conn)
   (disconnect conn)
   (write-string (string-append "Database created at " dbloc "\n")))
   (write-string (string-append "Database created at " dbloc "\n")))
 
 

+ 5 - 2
code/update_predictions.rkt

@@ -49,8 +49,11 @@
 ; add a new prediction
 ; add a new prediction
 (define (addpred)
 (define (addpred)
   ; manually get incremented ID
   ; manually get incremented ID
-  (define nID (+ 1
-                (query-value conn "SELECT ID FROM predictions order by ID desc limit 1")))
+  (define lastID (query-maybe-value conn "SELECT ID FROM predictions ORDER BY ID DESC LIMIT 1"))
+  (define nID
+    (if lastID
+        (+ 1 lastID)
+        (+ 1 0)))
   (define prediction (getinput "Enter the prediction"))
   (define prediction (getinput "Enter the prediction"))
   (define fprob (getinput "What is your forecast probability? "))
   (define fprob (getinput "What is your forecast probability? "))
   (define comments (getinput "Comments on the forecast"))
   (define comments (getinput "Comments on the forecast"))