example.scm 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. ;;; Code adapted from
  2. ;;; https://htmlpreview.github.io/?https://github.com/opencog/guile-dbi/blob/master/website/guile-dbi.html
  3. (import (dbi dbi))
  4. ;; Log into the database.
  5. (define db-obj (dbi-open "sqlite3" "database"))
  6. (display db-obj) (newline)
  7. ;; Create a table.
  8. (dbi-query db-obj "create table hellotable(id int, name varchar(15))")
  9. ;; Look at the return status of the last SQL command
  10. (display db-obj) (newline)
  11. ;; Populate the table with values.
  12. (dbi-query db-obj "insert into hellotable ('id', 'name') values('33', 'ola')")
  13. (dbi-query db-obj "insert into hellotable ('id', 'name') values('34', 'dzien dobre')")
  14. (dbi-query db-obj "insert into hellotable ('id', 'name') values('44', 'annyong haseyo')")
  15. (display db-obj) (newline)
  16. ;; Display each of the rows of the table, in turn.
  17. (dbi-query db-obj "select * from hellotable")
  18. (display db-obj) (newline)
  19. (write (dbi-get_row db-obj)) (newline)
  20. (write (dbi-get_row db-obj)) (newline)
  21. (write (dbi-get_row db-obj)) (newline)
  22. (write (dbi-get_row db-obj)) (newline)
  23. ;; Close the database.
  24. (dbi-close db-obj)
  25. (display db-obj) (newline)