Ignore:
Timestamp:
12/31/2007 02:17:16 PM (18 years ago)
Author:
raverkamp
revision id:
svn-v3-trunk1:1c22b0a8-4d0b-0410-a296-af6a2e6f35e3:plain-odbc%2Ftrunk:9
Message:

minor changes, test for mysql, delete of ffc dir

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/src/test/test-mysql.lisp

    r3 r4  
    11;;; -*- Mode: lisp -*-
     2
     3
     4; to run these tests you need to use a schema/database with "use schema".
     5
     6
    27
    38(in-package :test-plain-odbc)
     
    1217  (mysql-test4 con)
    1318  (mysql-test5 con)
    14   (mysql-test6 con)
     19  (mysql-test6a con)
     20  (mysql-test6b con)
     21  (mysql-test7 con)
     22  (mysql-test9 con)
     23  (mysql-test10 con)
     24  (mysql-test15 con)
     25  (mysql-test20 con)
     26  (mysql-test22 con)
     27  (mysql-test23 con)
     28  (mysql-test23b con)
    1529  )
    1630
     
    198212    (exec-command con (format nil "drop procedure ~A" proc))))
    199213
    200 
     214(defun mysql-drop-test-table (con proc)
     215  (unless (zerop (caar (exec-query con (format nil
     216                                               "
     217    select count(*)
     218    from information_schema.tables
     219    where table_name ='~A'
     220    and table_schema='test'" proc))))
     221    (exec-command con (format nil "drop table ~A" proc))))
     222
     223
     224
     225
     226;; this fails since myodbc can not deal with out parameters
    201227(defun mysql-test6 (con)
    202228  (mysql-drop-test-proc con "test99")
     
    207233     END;")
    208234  (commit con)
    209   (pprint
    210235  (let ((stm (prepare-statement con "{call test.test99(?,?)}"
    211236                                '(:integer :in)
     
    213238    (assert (= 6 (first (exec-prepared-command stm 1))))
    214239    (free-statement stm)))
     240
     241
     242(defun mysql-test6a (con)
     243  (mysql-drop-test-proc con "test99")
     244  (exec-command con "
     245CREATE PROCEDURE test99 (in p1 int, out p2 INT)
     246     BEGIN
     247       set p2=p1+5;
     248     END;")
     249  (commit con)
     250  (plain-odbc:exec-command con "set @p2=1000")
     251  (let ((stm (prepare-statement con "call test.test99(?,@p2)"
     252                                '(:integer :in))))
     253    (exec-prepared-command stm 1)
     254    (assert (= 6 (first (first     (exec-query con "select cast(@p2 as signed)")))))
     255    (free-statement stm)))
     256
     257(defun mysql-test6b (con)
     258  (mysql-drop-test-proc con "test99")
     259  (exec-command con "
     260CREATE PROCEDURE test99 (in p1 int, out p2 INT)
     261     BEGIN
     262       set p2=p1+5;
     263     END;")
     264  (commit con)
     265  (plain-odbc:exec-command con "set @p2=1000")
     266  (plain-odbc:exec-command con "set @p1=1")
     267  (let ((stm (prepare-statement con "call test.test99(@p1,@p2)" )))
     268    (exec-prepared-command stm)
     269    (assert (= 6 (first (first  (exec-query con "select cast(@p2 as signed)")))))
     270    (free-statement stm)))
     271
     272(defun mysql-test7 (con)
     273   (let ((*universal-time-to-date-dataype* 'universal-time-list)
     274         (*date-datatype-to-universal-time* 'list-universal-time)
     275         (*date-type-predicate* 'date-lisp-p))
     276     (let ((res (exec-query con "select date_add(cast(? as date),interval 1 day)"
     277                            '((:date 2005 4 5) :date))))
     278           (assert (equal res '(((:date 2005 4 6 0 0 0))))))))
     279
     280
     281
     282;;;
     283(defun mysql-test9 (con)
     284  (ignore-errors
     285    (exec-command con "drop table test999"))
     286  (exec-command con "create table test999 (a int,b LONGTEXT)")
     287  (commit con)
     288  (with-prepared-statement (stm con "insert into test999 (a,b) values(?,?)"
     289                                '(:integer :in)
     290                                '(:clob :in))
     291    (let ((mp plain-odbc::*max-precision*))
     292      (dolist (len (list 0 1 2 3 4 5 900 9000 8192 8000
     293                         (1- mp)
     294                         mp
     295                         (1+ mp)
     296                         (* 2 mp)
     297                         (1- (* 2 mp))
     298                         (1+ (* 2 mp))))
     299        (let ((string (make-funny-string len)))
     300          (exec-prepared-update stm len string)
     301          (let ((res (exec-query con (format nil "select b from test999 where a=~A" len))))
     302            (assert (equal res
     303                           (list (list string)))))))))
     304    (exec-command con "drop table test999")
     305    (commit con)
     306    )
     307
     308
     309(defun mysql-test10 (con)
     310  (ignore-errors
     311    (exec-command con "drop table test999"))
     312  (exec-command con "create table test999 (a int,b longblob)")
     313  (commit con)
     314  (with-prepared-statement (stm con "insert into test999 (a,b) values(?,?)"
     315                                '(:integer :in)
     316                                '(:blob :in))
     317    (let ((mp plain-odbc::*max-precision*))
     318      (dolist (len (list 0 1 2 3 4 5 900 9000 8192 8000
     319                         (1- mp)
     320                         mp
     321                         (1+ mp)
     322                         (* 2 mp)
     323                         (1- (* 2 mp))
     324                         (1+ (* 2 mp))))
     325        (let ((byte-vec (make-funny-bytes len)))
     326          (exec-prepared-update stm len byte-vec)
     327          (let ((res (exec-query con (format nil "select b from test999 where a=~A" len))))
     328          (assert (equalp res
     329                         (list (list byte-vec)))))))))
     330    (exec-command con "drop table test999")
     331    (commit con)
     332    )
     333
     334
     335(defun mysql-test15(con)
     336  (let ((res (exec-query con "select (cast('2005-6-7 13:04:45' as datetime)) as a")))
     337    (assert (= (encode-universal-time 45 4 13 7 6 2005) (caar res)))))
     338
     339
     340(defun mysql-test20 (con)
     341  (ignore-errors (exec-command con  "drop table type_test"))
     342  (exec-command con *mysql-type_test-ddl*)
     343  (dotimes (i 100)
     344    (let* ((str (make-string 100 :initial-element #\p))
     345           (binary (make-array 1000 :initial-element (random 256)))
     346           (id (random 1000)))
     347      (exec-update con "delete from type_test where id =?" id)
     348      (exec-update con "insert into type_test (t_longblob,id,t_longtext) values(?,?,?)"
     349                   (list binary :blob) id (list str :clob))
     350      (multiple-value-bind (r1 m1)
     351          (exec-query con
     352                      "select id aaa,t_longblob bbb,t_longtext ccc from type_test where id=?"
     353                      id)
     354        (assert (equalp r1 (list (list id (coerce binary '(vector (unsigned-byte 8))) str))))
     355        (assert (equal m1 '("aaa" "bbb" "ccc")))
     356        (commit con)))))
     357
     358
     359(defun mysql-test22 (con)
     360  (let ((res (first
     361              (exec-query con "
     362          select
     363           ? as t_double,
     364           ? as t_integer,
     365           ? as t_varchar,
     366           cast(? as binary) as t_varbinary"
     367                          1223455.334 12345 "blablablub" #(1 2 3 4)))))
     368    (assert (equal
     369             '(1223455 12345 "blablablub" (1 2 3 4))
     370             (list (truncate (first res))
     371                   (second res)
     372                   (third res)
     373                   (coerce (fourth res) 'list))))))
     374
     375
     376;; be carefull with double and float in lisp to!
     377(defun mysql-test23 (con)
     378  (mysql-drop-test-table con "testtab99")
     379  (exec-command con "create table testtab99 (a double)")
     380  (mysql-drop-test-proc con "test99")
     381  (exec-command con "
     382   create procedure test99 (a double)
     383    begin
     384    insert into testtab99 (a) values(a+1);
     385    end;")
     386  (with-prepared-statement
     387   (stm con "{call test99(?)}"
     388        '(:double :in))
     389    (let ((nix (exec-prepared-command stm 1.8d0))
     390          (nix2  (commit con))
     391          (res (exec-query con "select * from testtab99")))
     392      (assert (= (caar res) 2.8d0)))))
     393
     394(defun mysql-test23b (con)
     395  (mysql-drop-test-table con "testtab99")
     396  (exec-command con "create table testtab99 (a int)")
     397  (mysql-drop-test-proc con "test99")
     398  (exec-command con "
     399   create procedure test99 (a int)
     400    begin
     401    insert into testtab99 (a) values(a+1);
     402    end;")
     403  (with-prepared-statement
     404   (stm con "{call test99(?)}"
     405        '(:integer :in))
     406    (let ((nix (exec-prepared-command stm 7))
     407          (res (exec-query con "select * from testtab99")))
     408      (assert (= (caar res) 8)))))
     409
     410
     411(defun mysql-test24 (con)
     412  (mysql-drop-test-table con "testtab99")
     413  (exec-command con "create table testtab99 (a decimal)")
     414  (mysql-drop-test-proc con "test99")
     415  (exec-command con "
     416   create procedure test99 (a decimal)
     417    begin
     418    insert into testtab99 (a) values(a+1);
     419    end;")
     420  (with-prepared-statement
     421   (stm con "{call test99(?)}"
     422        '(:integer :in))
     423    (let ((nix (exec-prepared-command stm 7))
     424          (res (exec-query con "select * from testtab99")))
     425      (assert (= (caar res) 8)))))
     426
     427
     428(defun mysql-test25 (con)
     429  (mysql-drop-test-proc con "test99")
     430  (exec-command con "
     431   create procedure test99 (a decimal,b varchar(200))
     432    begin
     433      select 3*a as a, 'x' + b +'y' as b, cast('2003-4-1' as datetime) as c;
     434      select uuid() as x,cast(123456789012345678 as signed) as y,cast('abcdefghijklmnop' as binary) as z;
     435    end;")
     436  (with-prepared-statement
     437   (stm con "{call test99(?,?)}"
     438        '(:integer :in) '(:string :in))
     439   (multiple-value-bind (r1 c1 r2 c2) (exec-prepared-query stm 123456789 "abcdefghijklmn")
     440     
     441     (assert (equal c1 '("a" "b" "c")))
     442     (assert (equal c2 '("x" "y" "z")))
     443     (assert (equal r1 (list (* 3.0d   123456789) "xabcdefghijklmny"
     444                             (encode-universal-time 0 0 0 1 4 2003))))
     445     (assert (equal (rest r2 ) (list 123456789012345678
     446                                     (map vector 'char-code "abcdefghijklmn")))))))
     447
Note: See TracChangeset for help on using the changeset viewer.