source: project/release/3/mysql/tags/1.3/mysql-tests-body.scm @ 7930

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

1.3 release. Moved aux C code into .scm file. Added mysql-options conn arg helper.

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-foreach-row *conn* (lambda (row row-idx)
52  (display (conc row-idx ": " (row "Database") "\n"))))
53
54(newline)
55(display "Or they can just be comma-separated, like so:")
56(mysql-foreach-row *conn* (lambda (row row-idx)
57  (display (conc (row "Database")
58                 (if (< row-idx (mysql-num-rows *conn*)) ", " "\n")))))
59
60(mysql-print-and-query *conn* "DROP DATABASE IF EXISTS mysql_egg_test")
61
62(mysql-print-and-query *conn* "CREATE DATABASE mysql_egg_test")
63
64(print "selecting database: mysql_egg_test")
65(mysql-select-db *conn* "mysql_egg_test")
66
67(newline)
68(mysql-print-and-query *conn* "CREATE TABLE test1 (
69  id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
70  testboolnn BOOLEAN NOT NULL,
71  testbool BOOLEAN DEFAULT NULL
72  )")
73
74(newline)
75(mysql-print-and-query *conn*
76  "INSERT INTO test1 SET testboolnn=TRUE, testbool=NULL")
77(mysql-print-and-query *conn*
78  "INSERT INTO test1 SET testboolnn=FALSE, testbool=FALSE")
79
80(newline)
81(mysql-print-and-query *conn* "SELECT testboolnn, testbool FROM test1")
82(mysql-foreach-row *conn* (lambda (row idx)
83  (display (conc "row " idx ": testboolnn=" (row "testboolnn")
84                 ", testbool="
85                 (row "testbool") "\n"))))
86
87(newline)
88(mysql-print-and-query *conn* "SELECT testboolnn, testbool FROM test1")
89(let ([names (mysql-fetch-field-item *conn* mysql-field-name)])
90  (pretty-print
91   (mysql-row-map
92     *conn*
93     (lambda (row idx)
94       (map (lambda (f) (cons f (row f))) names)))) )
95
96(newline)
97(mysql-print-and-query *conn* "SELECT testboolnn, testbool FROM test1")
98(mysql-row-for-each
99  *conn*
100  (lambda (row idx)
101    (print "Row " idx " lengths: " (mysql-fetch-lengths *conn*))))
102
103;; Finished
104(newline)
105(print "Closing the connection")
106(mysql-close *conn*)
Note: See TracBrowser for help on using the repository browser.