source: project/release/3/mysql/trunk/mysql-tests-body.scm @ 7943

Last change on this file since 7943 was 7943, checked in by Kon Lovett, 12 years ago

Chgd fetch row body to handle binary blob/string.

File size: 3.0 KB
Line 
1#!/usr/bin/csi
2; vim:ts=2:sw=2:et:
3; mysql-tests.scm,v 1.3 2005/08/04 09:14:44 tbutzon Exp
4
5(use mysql)
6
7;;;
8
9(define (collect-until proc pred)
10  (do ([val (proc) (proc)]
11       [lst '() (cons val lst)])
12      [(pred val) lst]) )
13
14(define (collect-while proc pred)
15  (collect-until proc (complement pred)) )
16
17;;;
18
19(define (mysql-fetch-field-item conn getter)
20  (collect-while (lambda () (mysql-fetch-field-slot conn getter)) identity) )
21
22#; ;UNUSED
23(define (mysql-fetch-field-items conn . getters)
24  (collect-while (lambda () (apply mysql-fetch-field-slots conn getters)) identity) )
25
26;;;
27
28(print "Opening the connection")
29(define *conn* (mysql-connect user: *user* passwd: *passwd* host: *host*))
30(print "Database: " *conn*)
31
32(unless *conn*
33  (print "Unable to connect to database.")
34  (print "You might want to edit \"mysql-tests.scm\" to set *user*, *passwd*, and *host*.")
35  (exit) )
36
37(print "MySQL errno: " (mysql-errno *conn*))
38(print "MySQL error: " (mysql-error *conn*))
39(newline)
40
41(define (mysql-print-and-query *conn* query)
42  (print "QUERY: " query)
43  (mysql-query *conn* query))
44
45(print "Performing query: SHOW DATABASES")
46(mysql-print-and-query *conn* "SHOW DATABASES")
47(print "Number of rows: " (mysql-num-rows *conn*))
48
49(newline)
50(print "The rows can be enumerated one-per-line, like this:")
51(mysql-row-for-each
52  *conn*
53  (lambda (row row-idx)
54    (display (conc row-idx ": " (row "Database") "\n"))))
55
56(newline)
57(display "Or they can just be comma-separated, like so:")
58(mysql-row-for-each
59  *conn*
60  (lambda (row row-idx)
61    (display (conc (row "Database")
62                   (if (< row-idx (mysql-num-rows *conn*)) ", " "\n")))))
63
64(mysql-print-and-query *conn* "DROP DATABASE IF EXISTS mysql_egg_test")
65
66(mysql-print-and-query *conn* "CREATE DATABASE mysql_egg_test")
67
68(print "selecting database: mysql_egg_test")
69(mysql-select-db *conn* "mysql_egg_test")
70
71(newline)
72(mysql-print-and-query *conn* "CREATE TABLE test1 (
73  id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
74  testboolnn BOOLEAN NOT NULL,
75  testbool BOOLEAN DEFAULT NULL
76  )")
77
78(newline)
79(mysql-print-and-query *conn*
80  "INSERT INTO test1 SET testboolnn=TRUE, testbool=NULL")
81(mysql-print-and-query *conn*
82  "INSERT INTO test1 SET testboolnn=FALSE, testbool=FALSE")
83
84(newline)
85(mysql-print-and-query *conn* "SELECT testboolnn, testbool FROM test1")
86(mysql-row-for-each
87  *conn*
88  (lambda (row idx)
89    (print "Row " idx " lengths: " (mysql-fetch-lengths *conn*))))
90
91(newline)
92(mysql-print-and-query *conn* "SELECT testboolnn, testbool FROM test1")
93(mysql-row-for-each *conn* (lambda (row idx)
94  (display (conc "row " idx ": testboolnn=" (row "testboolnn")
95                 ", testbool="
96                 (row "testbool") "\n"))))
97
98(newline)
99(mysql-print-and-query *conn* "SELECT testboolnn, testbool FROM test1")
100(let ([names (mysql-fetch-field-item *conn* mysql-field-name)])
101  (pretty-print
102   (mysql-row-map
103     *conn*
104     (lambda (row idx)
105       (map (lambda (f) (cons f (row f))) names)))) )
106
107;; Finished
108(newline)
109(print "Closing the connection")
110(mysql-close *conn*)
Note: See TracBrowser for help on using the repository browser.