aboutsummaryrefslogtreecommitdiff
path: root/src/ellinika/sql.scm
diff options
context:
space:
mode:
Diffstat (limited to 'src/ellinika/sql.scm')
-rw-r--r--src/ellinika/sql.scm33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/ellinika/sql.scm b/src/ellinika/sql.scm
new file mode 100644
index 0000000..c0301ad
--- /dev/null
+++ b/src/ellinika/sql.scm
@@ -0,0 +1,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.