1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: test-clsql.cl
6 ;;;; Purpose: Basic test of CLSQL
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Mar 2002
10 ;;;; $Id: test-clsql.cl,v 1.3 2002/03/24 18:31:05 kevin Exp $
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
23 (defvar *config-pathname* (make-pathname :name "test-clsql"
25 :defaults *load-truename*))
26 (defparameter *config* nil)
29 (if (probe-file *config-pathname*)
30 (with-open-file (stream *config-pathname* :direction :input)
31 (setq *config* (read stream))
32 (test-automated *config*))
35 (defun test-interactive ()
38 (multiple-value-bind (spec type) (get-spec-and-type)
40 (clsql-test-table spec type)
43 (defun test-automated (config)
45 (let ((type (car elem))
47 (clsql-test-table spec type))))
52 (defun clsql-test-table (spec type)
53 (when (eq type :mysql)
54 (test-clsql-mysql spec))
55 (let ((db (clsql:connect spec :database-type type :if-exists :new)))
59 (clsql:execute-command
60 "DROP TABLE test_clsql" :database db))
61 (clsql:execute-command
62 "CREATE TABLE test_clsql (i integer, sqrt float, sqrt_str CHAR(20))" :database db)
64 (clsql:execute-command
65 (format nil "INSERT INTO test_clsql VALUES (~d,~d,'~a')"
66 i (sqrt i) (format nil "~d" (sqrt i)))
68 (pprint (clsql:map-query 'vector #'list "select * from test_clsql" :database db))
69 (clsql:execute-command "DROP TABLE test_clsql"))
70 (clsql:disconnect :database db)))
73 (defun test-clsql-mysql (spec)
74 (let ((db (clsql-mysql::database-connect spec :mysql)))
75 (clsql-mysql::database-execute-command "DROP TABLE IF EXISTS test_clsql" db)
76 (clsql-mysql::database-execute-command
77 "CREATE TABLE test_clsql (i integer, sqrt double, sqrt_str CHAR(20))" db)
79 (clsql-mysql::database-execute-command
80 (format nil "INSERT INTO test_clsql VALUES (~d,~d,'~a')"
81 i (sqrt i) (format nil "~d" (sqrt i)))
83 (let ((res (clsql-mysql::database-query-result-set "select * from test_clsql" db :full-set t :field-types nil)))
84 (format t "~&Number rows: ~D~%" (mysql:mysql-num-rows (clsql-mysql::mysql-result-set-res-ptr res)))
85 (clsql-mysql::database-dump-result-set res db))
86 (clsql-mysql::database-execute-command "DROP TABLE test_clsql" db)
87 (clsql-mysql::database-disconnect db)))
90 (defun get-spec-and-type ()
91 (format t "~&Test CLSQL")
92 (format t "~&==========~%")
93 (format t "~&Enter connection type (:mysql :postgresql :postgresql-socket")
94 #+allegro (format t " :aodbc")
95 (format t ") [default END]: ")
96 (let ((type-string (read-line)))
97 (if (zerop (length type-string))
99 (get-spec-for-type (read-from-string type-string)))))
101 (defun get-spec-for-type (type)
102 (let ((spec (get-spec-using-format type
104 ((:mysql :postgresql :postgresql-socket)
105 '("host" "database" "user" "password"))
107 '("dsn" "user" "password"))))))
111 (defun get-spec-using-format (type spec-format)
113 (format t "~&Connection Spec for ~A" (symbol-name type))
114 (format t "~&------------------------------")
116 (dolist (elem spec-format)
117 (format t "~&Enter ~A: " elem)
118 (push (read-line) spec))