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

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

Bug fix for row map. Added test for fetch lengths.

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