X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=test-clsql.cl;h=316c1ae995b4283437407670e361ff614ea1d6f2;hb=c60de8741d11ae54f2bfcadf87c8703ad7da0970;hp=2aed1633e5f0729d74634f9803fa3491a3cd113b;hpb=33401393ccc0a9567da4104b3c2e7608956a8624;p=clsql.git diff --git a/test-clsql.cl b/test-clsql.cl index 2aed163..316c1ae 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.10 2002/03/27 05:04:19 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) @@ -51,7 +53,26 @@ (clsql-test-table spec type))) ) +(defun make-test-float (i) + (* i (expt 10 (* i 4)))) + +(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, flt float, flt_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:number-to-sql-string (make-test-float n)) + (clsql:number-to-sql-string (make-test-float 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 +80,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 nil)) (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 +101,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)