- Timestamp:
- 08/23/2008 11:23:53 AM (18 years ago)
- revision id:
- svn-v3-trunk1:1c22b0a8-4d0b-0410-a296-af6a2e6f35e3:plain-odbc%2Ftrunk:14
- Location:
- vendor/src
- Files:
-
- 1 added
- 5 edited
-
test/test-postgresql.lisp (added)
-
odbc/ffi-support.lisp (modified) (1 diff)
-
odbc/odbc-functions.lisp (modified) (5 diffs)
-
odbc/odbc-main.lisp (modified) (4 diffs)
-
odbc/parameter.lisp (modified) (1 diff)
-
test/test-sql-server.lisp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/src/odbc/ffi-support.lisp
r5 r8 4 4 5 5 6 (defun get-string (ptr length) 7 (cffi:foreign-string-to-lisp ptr length nil) 8 ) 6 (defmacro cffi-0.10-or-0.9 (form-0.10 form-0.9) 7 (if (BOUNDP 'cffi::*foreign-string-mappings*) 8 form-0.10 9 form-0.9)) 9 10 10 (defun get-string-nts (ptr) 11 (cffi:foreign-string-to-lisp ptr MOST-POSITIVE-FIXNUM t)) 11 (cffi-0.10-or-0.9 12 (defun get-string (ptr length) 13 (cffi:foreign-string-to-lisp ptr :count length :encoding :iso-8859-1) 14 ) 15 (defun get-string (ptr length) 16 (cffi:foreign-string-to-lisp ptr length nil) 17 ) 18 ) 19 20 (cffi-0.10-or-0.9 21 (defun get-string-nts (ptr) 22 (cffi:foreign-string-to-lisp ptr :max-chars MOST-POSITIVE-FIXNUM :encoding :iso-8859-1)) 23 (defun get-string-nts (ptr) 24 (cffi:foreign-string-to-lisp ptr MOST-POSITIVE-FIXNUM t))) 12 25 13 (defun put-string (ptr vector) 14 (cffi:lisp-string-to-foreign vector ptr (1+ (length vector)))) 26 (cffi-0.10-or-0.9 27 (defun put-string (ptr vector) 28 (cffi:lisp-string-to-foreign vector ptr (1+ (length vector)) :encoding :iso-8859-1)) 29 (defun put-string (ptr vector) 30 (cffi:lisp-string-to-foreign vector ptr (1+ (length vector))))) 15 31 16 32 (defun %null-ptr () 17 33 (cffi:null-pointer)) 34 35 36 (cffi-0.10-or-0.9 37 (defmacro with-foreign-string-alloc ((ptr text) &body body) 38 `(cffi:with-foreign-string (,ptr ,text :encoding :iso-8859-1) 39 ,@body)) 40 41 (defmacro with-foreign-string-alloc ((ptr text) &body body) 42 `(cffi:with-foreign-string (,ptr ,text) 43 ,@body))) 44 18 45 19 46 (defun get-byte-vector (ptr length) -
vendor/src/odbc/odbc-functions.lisp
r5 r8 97 97 (#.$SQL_INVALID_HANDLE 98 98 (values result-code 99 (make-condition 'sql-error :error-message "[ODBC error] Invalid handle"))) 99 (make-condition 'sql-error :error-message "[ODBC error] Invalid handle" 100 :sql-state nil 101 :error-code nil 102 ))) 100 103 ;; maybe this should raise an error immediately 101 104 (#.$SQL_STILL_EXECUTING 102 105 (values result-code 103 (make-condition 'sql-error :error-message"[ODBC error] Still executing"))) 106 (make-condition 'sql-error :error-message"[ODBC error] Still executing" 107 :sql-state nil 108 :error-code nil))) 104 109 (#.$SQL_NEED_DATA 105 110 (values result-code nil)) … … 167 172 (:prompt $SQL_DRIVER_PROMPT) 168 173 (:noprompt $SQL_DRIVER_NOPROMPT)))) 169 ( cffi:with-foreign-string(connection-str-ptr connection-string)174 (with-foreign-string-alloc (connection-str-ptr connection-string) 170 175 (with-temporary-allocations 171 176 ((complete-connection-str-ptr (alloc-chars 1024)) … … 414 419 (defun %sql-exec-direct (sql hstmt henv hdbc) 415 420 (declare (string sql)) 416 ( cffi:with-foreign-string(sql-ptr sql)421 (with-foreign-string-alloc (sql-ptr sql) 417 422 (with-error-handling 418 423 (:hstmt hstmt :henv henv :hdbc hdbc) … … 498 503 (defun %sql-prepare (hstmt sql) 499 504 (declare (string sql)) 500 ( cffi:with-foreign-string(sql-ptr sql)505 (with-foreign-string-alloc (sql-ptr sql) 501 506 (with-error-handling (:hstmt hstmt) 502 507 (SQLPrepare hstmt sql-ptr $SQL_NTS)))) … … 523 528 (defun set-connection-attr-string (hdbc option val) 524 529 (with-error-handling (:hdbc hdbc) 525 ( cffi:with-foreign-string(ptr val)530 (with-foreign-string-alloc (ptr val) 526 531 ;; TODO: Null-terminator with length? 527 532 (SQLSetConnectAttr_string hdbc option ptr (length val))))) -
vendor/src/odbc/odbc-main.lisp
r6 r8 204 204 (nreverse res))) 205 205 206 (defun bind-columns (query )206 (defun bind-columns (query columncount) 207 207 (with-slots (hstmt 208 208 columns 209 209 column-count) 210 210 query 211 (let ((cc (result-columns-count hstmt))) 212 (when (zerop cc) 211 (when (zerop columncount) 213 212 (error "can not bind columns, there is no result set")) 214 (setf column-count c c)213 (setf column-count columncount) 215 214 (setf columns (make-array column-count)) 216 215 (dotimes (pos column-count) 217 216 ;; the columns are 0 based, at least here 218 217 (let ((col (create-column hstmt pos))) 219 (setf (aref columns pos) col))))) )218 (setf (aref columns pos) col))))) 220 219 221 220 (defun unbind-columns (query) … … 344 343 (row-count (result-rows-count (hstmt query)))) 345 344 (loop 346 (when (zerop (result-columns-count (hstmt query))) (return)) 347 (bind-columns query) 345 (let ((column-count (result-columns-count (hstmt query)))) 346 (when (zerop column-count) (return)) 347 (bind-columns query column-count) 348 348 (let ((res (fetch-query-results query )) 349 349 (names (coerce (column-names query) 'list))) … … 351 351 (unbind-columns query) 352 352 (unless (%sql-more-results (hstmt query)) 353 (return)))) 353 (return))))) 354 354 (let ((return-parameters (get-parameters query))) 355 355 (values row-count (nreverse res-list) return-parameters)))) … … 493 493 (unless (= (column-count query) no-of-columns) 494 494 (error "the number of columns has changed")) 495 (bind-columns query )))495 (bind-columns query no-of-columns))) 496 496 (values (fetch-query-results query) 497 497 (coerce (column-names query) 'list))) -
vendor/src/odbc/parameter.lisp
r6 r8 114 114 (put-string (slot-value param 'value-ptr) "")) 115 115 (t 116 (cffi:lisp-string-to-foreign value 117 (slot-value param 'value-ptr) 118 (1+ (length value))) 116 (put-string (slot-value param 'value-ptr) value) 119 117 (setf (cffi:mem-ref (slot-value param 'ind-ptr) 'sql-len) 120 118 (length value))))) -
vendor/src/test/test-sql-server.lisp
r6 r8 30 30 ss-test20 31 31 ss-test21 32 ss-test22)) 32 ss-test22 33 ss-test23 34 ss-test24 35 ss-test25 36 ss-test26)) 33 37 (pprint sym) 34 38 (funcall sym con))) … … 502 506 503 507 504 508 (defun ss-test24 (con) 509 (dolist (x '(234 123 237)) 510 (let ((res (exec-query con (format nil "select char(~A)as a" x)))) 511 (assert (= x (char-code (char (first (first res)) 0))))))) 512 513 (defun ss-test25 (con) 514 (dolist (x '(234 123 237)) 515 (let ((res (exec-query con (format nil "select ascii('~A') as a" (code-char x))))) 516 (assert (= x (first (first res))))))) 517 518 (defun ss-test26 (con) 519 (dolist (x '(234 123 237)) 520 (let ((res (exec-query con "select ? as a" (string (code-char x))))) 521 (assert (= x (char-code (char (first (first res)) 0))))))) 522 523 524 525 526 527 528
Note: See TracChangeset
for help on using the changeset viewer.
