Skip to content

Instantly share code, notes, and snippets.

@hito-asa
Created June 28, 2013 02:41
Show Gist options
  • Save hito-asa/5882082 to your computer and use it in GitHub Desktop.
Save hito-asa/5882082 to your computer and use it in GitHub Desktop.
(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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment