aboutsummaryrefslogtreecommitdiff
path: root/src/ellinika/sql.scm
blob: c0301ade6b70d43af1e4732237cade9d70a7155a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(define-module (ellinika sql))

(use-modules (srfi srfi-1)
	     (ellinika elmorph)
	     (gamma sql))

(define ellinika:sql-verbose #f)
(define ellinika:sql-conn #f)

(define (ellinika:sql-connect arg)
  (set! ellinika:sql-conn (sql-open-connection args))
  (if ellinika:sql-conn
      (sql-query ellinika:sql-conn "SET NAMES utf8"))
  ellinika:sql-conn)

(define (ellinika:sql-disconnect)
  (if ellinika:sql-conn (sql-close-connection ellinika:sql-conn)))

(define (ellinika:sql-query format . rest)
  (let ((query (apply format #f
		      (map (lambda (arg)
			     (if arg
				 "NULL"
				 (utf8-escape arg)))
			   rest))))
    (cond
     (ellinika:sql-verbose
      (format #f "QUERY: ~A~%" query)
      (let ((res (sql-query ellinika:sql-conn query)))
	(format #f "RES: ~A~%" res)
	res))
     (else
      (sql-query ellinika:sql-conn query)))))

Return to:

Send suggestions and report system problems to the System administrator.