X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=test-clsql.cl;h=1d58cd5b95c252e300e3152a40c8a74934aa3de1;hb=6be46e38c9a7e08ed5c974c66bfdbd4dfad9a34d;hp=2aed1633e5f0729d74634f9803fa3491a3cd113b;hpb=33401393ccc0a9567da4104b3c2e7608956a8624;p=clsql.git diff --git a/test-clsql.cl b/test-clsql.cl index 2aed163..1d58cd5 100644 --- a/test-clsql.cl +++ b/test-clsql.cl @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Mar 2002 ;;;; -;;;; $Id: test-clsql.cl,v 1.6 2002/03/25 14:13:41 kevin Exp $ +;;;; $Id: test-clsql.cl,v 1.9 2002/03/26 14:12:12 kevin Exp $ ;;;; ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -25,13 +25,15 @@ :defaults *load-truename*)) (defparameter *config* nil) -(defun do-test () - (if (probe-file *config-pathname*) - (with-open-file (stream *config-pathname* :direction :input) - (setq *config* (read stream)) - (test-automated *config*)) - (test-interactive))) - +(defun do-test (&optional (interactive nil)) + (if interactive + (test-interactive) + (if (probe-file *config-pathname*) + (with-open-file (stream *config-pathname* :direction :input) + (setq *config* (read stream)) + (test-automated *config*)) + (test-interactive)))) + (defun test-interactive () (do ((done nil)) (done) @@ -52,6 +54,23 @@ ) +(defun create-test-table (db) + (ignore-errors + (clsql:execute-command + "DROP TABLE test_clsql" :database db)) + (clsql:execute-command + "CREATE TABLE test_clsql (n integer, n_pi float, n_pi_str CHAR(20))" + :database db) + (dotimes (i 11) + (let ((n (- i 5))) + (clsql:execute-command + (format nil "INSERT INTO test_clsql VALUES (~a,~a,'~a')" + n (clsql:float-to-sql-string (* pi n)) + (clsql:float-to-sql-string (* pi n))) + :database db)))) + +(defun drop-test-table (db) + (clsql:execute-command "DROP TABLE test_clsql")) (defun clsql-test-table (spec type) (when (eq type :mysql) @@ -59,20 +78,14 @@ (let ((db (clsql:connect spec :database-type type :if-exists :new))) (unwind-protect (progn - (ignore-errors - (clsql:execute-command - "DROP TABLE test_clsql" :database db)) - (clsql:execute-command - "CREATE TABLE test_clsql (i integer, sqrt float, sqrt_str CHAR(20))" :database db) - (dotimes (i 10) - (clsql:execute-command - (format nil "INSERT INTO test_clsql VALUES (~d,~d,'~a')" - i (sqrt i) (format nil "~d" (sqrt i))) - :database db)) + (create-test-table db) + (pprint (clsql:query "select * from test_clsql" + :database db + :types :auto)) (pprint (clsql:map-query 'vector #'list "select * from test_clsql" :database db - :field-types :auto)) ;;'(:int :double t))) - (clsql:execute-command "DROP TABLE test_clsql")) + :types :auto)) ;;'(:int :double t))) + (drop-test-table db)) (clsql:disconnect :database db))) ) @@ -86,7 +99,7 @@ (format nil "INSERT INTO test_clsql VALUES (~d,~d,'~a')" i (sqrt i) (format nil "~d" (sqrt i))) db)) - (let ((res (clsql-mysql::database-query-result-set "select * from test_clsql" db :full-set t :field-types nil))) + (let ((res (clsql-mysql::database-query-result-set "select * from test_clsql" db :full-set t :types nil))) (format t "~&Number rows: ~D~%" (mysql:mysql-num-rows (clsql-mysql::mysql-result-set-res-ptr res))) (clsql-mysql::database-dump-result-set res db)) (clsql-mysql::database-execute-command "DROP TABLE test_clsql" db)