Ignore:
Timestamp:
02/03/2008 08:14:49 PM (18 years ago)
Author:
raverkamp
revision id:
svn-v3-trunk1:1c22b0a8-4d0b-0410-a296-af6a2e6f35e3:plain-odbc%2Ftrunk:10
Message:

adding exec-sql, changes to documentation, more tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • error-handling/src/test/test-oracle.lisp

    r2.1.1 r2.1.3  
    1515                 ora-test6
    1616                 ora-test7
    17                  #+ignore  ;; unicode support does not work for oracle
    1817                 ora-test8
    1918                 ora-test9
    2019                 ora-test10
    2120                 ora-test11
     21                 ora-test12
    2222                 ))
    2323    (pprint sym)
     
    3939  t_number number,
    4040  t_char char(2000) ,
    41   t_varchar varchar(4000),
     41  t_varchar varchar2(4000),
     42  t_nvarchar NVARCHAR2(200),
    4243  t_date date,
    4344  t_raw raw(2000),
    4445  t_blob blob,
    45   t_clob clob)
     46  t_clob clob,
     47  t_nclob nclob
     48  )
    4649")
    4750
     51
     52
     53(defun ora-drop-test-proc (con proc)
     54  (unless (zerop (caar (exec-query con (format nil "select count(*)
     55    from user_objects where object_name='~A'" proc))))
     56    (exec-command con (format nil "drop procedure ~A" proc))))
     57
     58(defun ora-drop-test-table (con proc)
     59  (unless (zerop (caar (exec-query con (format nil "select count(*)
     60    from user_objects where object_name='~A'" proc))))
     61    (exec-command con (format nil "drop table ~A" proc))))
     62
     63
    4864(defun oracle-type-test (con)
    49   (if (not (zerop (caar (exec-query con "select count(*) from user_tables where table_name ='TYPE_TEST'"))))
    50     (exec-command con "drop table type_test"))
     65  (ora-drop-test-table con "TYPE_TEST")
    5166  (exec-command con *oracle-type_test-ddl*)
    5267  (exec-update con "insert into type_test (id) values(1)")
    5368  (exec-update con "
    5469   update type_test set
    55       t_integer= 123456789012345677989,
     70      t_integer= 12345678901234,
    5671      t_number = 1.0/3.0,
    5772      t_char=rpad('1',1999),
    58       t_varchar =lpad('1',3999),
    59       t_date = sysdate,
     73      t_varchar =lpad('1',39),
     74      t_nvarchar = lpad(nchr(1234),200,nchr(1234)),
     75      t_date = to_date('1.3.2005 12:23:14','dd.mm.yyyy hh24:mi:ss'),
    6076      t_raw =hextoraw('11223344556677889900')
    6177    where id =1")
    62   (exec-query con "select * from type_test")
    6378  (let ((stm (prepare-statement
    64               con "update type_test set t_blob=?,t_clob=? where id =1"
    65               '(:blob :in) '(:clob :in))))
     79              con "update type_test set t_blob=?,t_clob=?,t_nclob=? where id =1"
     80              '(:blob :in) '(:clob :in) '(:UNICODE-CLOB :in))))
    6681  (exec-prepared-update
    6782   stm ;; sizes were 100000 and 100001
    6883   (make-array 100000 :element-type '(unsigned-byte 8) :initial-element 33)
    69    (make-string 1000001 :initial-element #\o)))
     84   (make-string 1000001 :initial-element #\o)
     85   (make-string 1234567 :initial-element (code-char 3217))))
     86  (let ((res (exec-query con "
     87      select id,t_integer,t_number,t_char,t_varchar,t_date,t_raw, t_nvarchar from type_test where id=1")))
     88    (assert (= (length res) 1))
     89    (setf res (first res))
     90    (assert (equal (nth 0 res) 1d0))
     91    (assert (equal (nth 1 res) 12345678901234d0))
     92    (assert (equal (nth 2 res) (/ 1d0 3)))
     93    ;;  t_char is of type char and therefor has always length 2000,
     94    ;; although we inserted a string of length 1999
     95    (assert (equal (nth 3 res)
     96                   (let ((a (make-string 2000 :initial-element #\space)))
     97                     (setf (schar a 0) #\1)
     98                     a)))
     99    (assert (equal (nth 4 res)
     100                   (let ((a (make-string 39 :initial-element #\space)))
     101                     (setf (schar a 38) #\1)
     102                     a)))
     103    (assert (equal (nth 5 res)
     104                   (encode-universal-time 14 23 12 1 3 2005)))
     105    (assert (equal (coerce (nth 6 res) 'list)
     106                   '(#x11 #x22 #x33 #x44 #x55 #x66 #x77 #x88 #x99 #x00)))
     107    (assert (equal (nth 7 res) (make-string 200 :initial-element (code-char 1234))))
     108    (let ((a (caar (exec-query con "select t_blob from type_test where id =1"))))
     109      (assert (equalp a (make-array 100000 :element-type '(unsigned-byte 8) :initial-element 33))))
     110    (let ((b (caar (exec-query con "select t_clob from type_test where id=1"))))
     111      (assert (equal b (make-string 1000001 :initial-element #\o))))
     112
     113    (let ((c (caar (exec-query con "select t_nclob from type_test where id=1"))))
     114      (assert (equal c (make-string 1234567 :initial-element (code-char 3217))))))
     115   
    70116  (commit con))
    71 
    72  
    73 
    74 (defun ora-drop-test-proc (con proc)
    75   (unless (zerop (caar (exec-query con (format nil "select count(*)
    76     from user_objects where object_name='~A'" proc))))
    77     (exec-command con (format nil "drop procedure ~A" proc))))
    78 
    79117
    80118(defun ora-test1 (con)
     
    200238;; works only with oracle 9 ?
    201239;; this does not work. mybe with the oracle odbc driver?
     240;; it works with oracle 10gr2
    202241(defun ora-test8 (con)
    203242  (ignore-errors (exec-command con "drop table testtab99"))
     
    208247    (exec-prepared-update stm 1 str))
    209248  (let ((res (exec-query con "select txt from testtab99 where id =1")))
    210     (assert (equal (list str) res)))))
     249    (assert (equal (list str) (first res))))))
    211250
    212251
     
    244283
    245284       
    246 
     285(defun ora-test12 (con)
     286  (ora-drop-test-proc con "TEST99")
     287  (exec-command con  (fix13 "create procedure test99 (a in out nvarchar2 ,b in out nvarchar2) as
     288        x  nvarchar2(1000);
     289        begin x:=a; a:=b; b:=x; end;"))
     290  (with-prepared-statement (stm con "{call test99(?,?)}"
     291                                '(:unicode-string :inout)
     292                                '(:unicode-string :inout))
     293    (let ((str1 (make-funny-string 700  (coerce (list (code-char 2341) (code-char 2347) #\a) 'vector )  ))
     294          (str2 (make-funny-string 900   (coerce (list (code-char 2341) (code-char 2347) #\a) 'vector ))))
     295     
     296      (let ((res (exec-prepared-command stm str1 str2)))
     297        (assert (equal res (list str2 str1)))))))
     298 
     299(defun ora-test13 (con)
     300  (ora-drop-test-table con "TESTTAB99")
     301  (exec-command con "create table testtab99 (x integer,y varchar2(200))")
     302  (multiple-value-bind (rc res params)
     303      ;; if columns x and y are set by triggers they can also be retrieved by this method
     304      (exec-sql con "insert into testtab99 (x,y) values(?+12,?||'a') returning x,y into ?,?" 13 "a" '(nil :integer :out) '(nil :string :out) )
     305    (assert (= rc 1))
     306    (assert (equal res nil))
     307    (assert (equal (list 25 "aa") params))))
Note: See TracChangeset for help on using the changeset viewer.