Changeset 21138 in project for demonstrations/awful


Ignore:
Timestamp:
10/30/10 19:47:15 (11 years ago)
Author:
Mario Domenech Goulart
Message:

demonstrations/awful/fortune: bug fix and improved `random-fortune' (excellent tips from Peter Bex)

Location:
demonstrations/awful/fortune
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • demonstrations/awful/fortune/create-database.scm

    r20676 r21138  
    127127
    128128(let ((db (open-database "fortunes.db")))
    129   (exec (sql db "create table fortunes(id integer primary key autoincrement, sentence text, author text)"))
     129  (exec (sql db "create table fortunes(sentence text, author text)"))
    130130  (for-each (lambda (fortune)
    131131              (let* ((sentence (car fortune))
  • demonstrations/awful/fortune/fortune-server.scm

    r20676 r21138  
    66(db-credentials "fortunes.db")
    77
    8 (define random-fortune
    9   (let ((num-fortunes #f))
    10     (lambda ()
    11       (unless num-fortunes
    12         (set! num-fortunes (caar ($db "select count(id) from fortunes"))))
    13       (car ($db (conc "select sentence, author from fortunes where id="
    14                       (random num-fortunes)))))))
     8(define (random-fortune)
     9  (car ($db "select sentence, author from fortunes order by random() limit 1")))
    1510
    1611(define-page (main-page-path)
Note: See TracChangeset for help on using the changeset viewer.