Skip to content

Instantly share code, notes, and snippets.

@hito-asa
Created June 28, 2013 02:41
Show Gist options
  • Select an option

  • Save hito-asa/5882082 to your computer and use it in GitHub Desktop.

Select an option

Save hito-asa/5882082 to your computer and use it in GitHub Desktop.

Revisions

  1. Hitoshi Asai created this gist Jun 28, 2013.
    22 changes: 22 additions & 0 deletions dblv2.scm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    (use dbi)
    (use gauche.collection)
    (let* ((data (list (cons "Curry" 750) (cons "Omelette" 700) (cons "Tempura" 300)))
    (conn (dbi-connect "dbi:mysql:sample_db_lv2;host=127.0.0.1" :username "user"))
    (insert (dbi-prepare conn
    "INSERT INTO menus (name, price) VALUES (?, ?)"))
    (query (dbi-prepare conn
    "SELECT id, name, price FROM menus ORDER BY id DESC"))
    (insert-result (map (lambda (datum)
    (dbi-execute insert (car datum) (cdr datum))) data))
    (result (dbi-execute query))
    (getter (relation-accessor result)))
    (map (lambda (row)
    (display "id: ")
    (display (getter row "id"))
    (newline)
    (display "name: ")
    (display (getter row "name"))
    (newline)
    (display "price: ")
    (display (getter row "price"))
    (newline) (newline)) result))