ソースを参照

remove (need for) dummy prediction entry upon DB creation

George C. Privon 6 年 前
コミット
e5f9f8c37a
2 ファイル変更5 行追加5 行削除
  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,
 outcome int DEFAULT NULL,
 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)
   (write-string (string-append "Database created at " dbloc "\n")))
 

+ 5 - 2
code/update_predictions.rkt

@@ -49,8 +49,11 @@
 ; add a new prediction
 (define (addpred)
   ; 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 fprob (getinput "What is your forecast probability? "))
   (define comments (getinput "Comments on the forecast"))