(require "../spgsql.ss"
(lib "class.ss"))
(print-struct #t)
(define HOST "localhost")
(define PORT 5432)
(define DATABASE "ryan")
(define USER "ryan")
(define PASSWORD "secret")
(define cx (connect HOST PORT DATABASE USER PASSWORD))
(send cx set-notice-handler display)
(define q-table-create
(send cx exec
"create temporary table the_numbers
(name integer, description varchar(80))"))
(send cx exec "insert into the_numbers values (0, 'nothing')")
(send cx exec
"insert into the_numbers (name, description)
values (1, 'multiplicative identity');
insert into the_numbers
values (2, 'the loneliest number since the number 1')")
(define q-select-even
(send cx query
"select name, description from the_numbers
where name % 2 = 0"))
q-select-even
(define q-fetch
(send cx query-general
"begin transaction;
declare MC cursor for select * from the_numbers;
move forward 1 in MC;
fetch 1 in MC;
commit transaction"))
q-fetch
(send cx query-value "select 17")
(send cx use-type-conversions #t)
(send cx query-value "select 17")
(send cx query-list "select name from the_numbers order by name")
(send cx query-value "select count(name) from the_numbers")
(send cx query-value "select now()")
(begin (with-handlers [(exn:spgsql?
(lambda (e) (printf "~a~n" (exn-message e))))]
(send cx query-value "select foo from NoSuchTable"))
(send cx query-value "select 'okay to proceed!'"))
(send cx disconnect)