- Timestamp:
- 11/28/2007 03:51:51 AM (19 years ago)
- branch-nick:
- 64-bit
- revision id:
- dsowen@tux-20071128035151-uzhdpxc21lpq3a6p
- File:
-
- 1 edited
-
64-bit/src/odbc/odbc-functions.lisp (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
64-bit/src/odbc/odbc-functions.lisp
r3 r6 45 45 ()) 46 46 47 ;; ;; dso+47 ;; TODO: Why doesn't this use with-temporary-allocations? -dso 48 48 (defun handle-error (henv hdbc hstmt) 49 49 (let 50 ((sql-state (alloc-chars 256)) ; TODO: How do we know this is 51 ; big enough? 50 ((sql-state (alloc-chars 256)) 52 51 (error-message (alloc-chars #.$SQL_MAX_MESSAGE_LENGTH)) 53 52 (error-code (cffi:foreign-alloc 'sql-integer)) 54 53 (msg-length (cffi:foreign-alloc 'sql-small-int))) 55 ;; TODO: Does this include null-terminator for error-message?56 54 (SQLError henv 57 55 hdbc … … 70 68 ;; problem: calling SQLError clears the error state 71 69 ;#+ignore 72 ;;;; dso+73 70 (defun sql-state (henv hdbc hstmt) 74 71 (with-temporary-allocations … … 169 166 170 167 171 ;;;; dso+172 168 (defun %new-environment-handle () 173 (declare (ftype sql-h-env))174 169 (cffi:with-foreign-object (phenv 'sql-h-env) 175 170 (with-error-handling … … 178 173 (cffi:mem-ref phenv 'sql-h-env)))) 179 174 180 ;;;; dso+181 175 (defun %new-db-connection-handle (henv) 182 176 (cffi:with-foreign-object (phdbc 'sql-h-dbc) … … 186 180 (cffi:mem-ref phdbc 'sql-h-dbc)))) 187 181 188 ;;;; dso+189 182 (defun %free-statement (hstmt option) 190 183 (with-error-handling … … 221 214 222 215 ;; 223 ;;;; dso+224 216 (defun %sql-driver-connect (henv hdbc connection-string completion-option) 225 217 (declare (string connection-string)) … … 244 236 (length connection-string) ;$SQL_NTS 245 237 complete-connection-str-ptr 246 1024 ; TODO: Should this 1023, for 247 ; the terminating char? 238 1024 248 239 length-ptr 249 240 completion-option)) 250 241 (get-string-nts complete-connection-str-ptr))))) 251 242 252 ;;;; dso+253 243 (defun %disconnect (hdbc) 254 244 (with-error-handling … … 256 246 (SQLDisconnect hdbc))) 257 247 258 ;;;; dso+259 248 (defun %commit (henv hdbc) 260 249 (with-error-handling … … 263 252 henv hdbc $SQL_COMMIT))) 264 253 265 ;;;; dso+266 254 (defun %rollback (henv hdbc) 267 255 (with-error-handling … … 272 260 ; col-nr is zero-based in Lisp 273 261 ; col-nr = :bookmark retrieves a bookmark. 274 ;;;; dso+275 262 (defun %bind-column (hstmt column-nr c-type data-ptr precision out-len-ptr) 276 263 (declare ((integer 0) column-nr)) … … 282 269 283 270 ; parameter-nr is zero-based in Lisp 284 ;;;; dso+285 271 (defun %sql-bind-parameter (hstmt parameter-nr parameter-type c-type 286 272 sql-type precision scale data-ptr … … 300 286 ))) 301 287 302 ;;;; dso+303 288 (defun %sql-fetch (hstmt) 304 289 (with-error-handling … … 306 291 (SQLFetch hstmt))) 307 292 308 ;;;; dso+309 293 (defun %new-statement-handle (hdbc) 310 294 (with-temporary-allocations … … 315 299 (cffi:mem-ref hstmt-ptr 'sql-h-stmt)))) 316 300 317 ;;;; dso+318 301 (defun %sql-get-info (hdbc info-type) 319 302 (ecase info-type … … 450 433 #.$SQL_UNION) 451 434 (with-temporary-allocations 452 ((info-ptr (cffi:foreign-alloc :uint32)) ; TODO: It'd be nice 453 ; to have this as a 454 ; sql-* type. 435 ;; TODO: It'd be nice to have this as a sql-* type. However, 436 ;; while the X/Open spec is usually quiet about data sizes, 437 ;; it specifically says a 32-bit bitmask for these; so if 438 ;; SQL-INTEGER changes to 64-bit, these may or may not change 439 ;; as well. -dso 440 ((info-ptr (cffi:foreign-alloc :uint32)) 455 441 (info-length-ptr (cffi:foreign-alloc 'sql-small-int))) 456 442 (with-error-handling … … 481 467 (cffi:mem-ref info-ptr 'sql-integer)))))) 482 468 483 ;;;; dso+484 469 (defun %sql-exec-direct (sql hstmt henv hdbc) 485 470 (declare (string sql)) … … 489 474 (SQLExecDirect hstmt sql-ptr $SQL_NTS)))) 490 475 491 ;;;; dso+492 476 (defun %sql-execute (hstmt) 493 477 (with-error-handling … … 495 479 (SQLExecute hstmt))) 496 480 497 ;;;; dso+498 481 (defun result-columns-count (hstmt) 499 482 (with-temporary-allocations … … 503 486 (cffi:mem-ref columns-nr-ptr 'sql-small-int)))) 504 487 505 ;;;; dso+506 488 (defun result-rows-count (hstmt) 507 489 (with-temporary-allocations … … 516 498 517 499 ;; Column counting is 1-based 518 ;;;; dso+519 500 (defun %describe-column (hstmt column-nr) 520 501 (declare ((integer 1) column-nr)) … … 528 509 (with-error-handling (:hstmt hstmt) 529 510 (SQLDescribeCol hstmt column-nr column-name-ptr 256 530 ;; TODO: Does 256 leave room for terminating531 ;; nulls?532 511 column-name-length-ptr 533 512 column-sql-type-ptr … … 572 551 573 552 574 ;;;; dso+575 553 (defun %sql-prepare (hstmt sql) 576 554 (declare (string sql)) … … 579 557 (SQLPrepare hstmt sql-ptr $SQL_NTS)))) 580 558 581 ;;;; dso+582 559 (defun set-connection-option (hdbc option param) 583 560 (with-error-handling (:hdbc hdbc) … … 591 568 592 569 593 ***570 ;;;*** 594 571 ;;; rav, 11.6.2005 595 572 ;;; added tracing support 596 573 597 ;;;; dso+598 574 (defun set-connection-attr-integer (hdbc option val) 599 575 (with-error-handling (:hdbc hdbc) 600 576 (SQLSetConnectAttr_long hdbc option val 0))) 601 577 602 ;;;; dso+603 578 (defun set-connection-attr-string (hdbc option val) 604 579 (with-error-handling (:hdbc hdbc) … … 613 588 (defun %stop-connection-trace (hdbc) 614 589 (set-connection-attr-integer hdbc $SQL_ATTR_TRACE $SQL_OPT_TRACE_OFF)) 615 616 617 (defun get-connection-attr-integer (hdbc attr)618 (with-temporary-allocations619 ((ptr (cffi:foreign-alloc :long))620 (lenptr (cffi:foreign-alloc :long)))621 (with-error-handling (:hdbc hdbc)622 (SQLGetConnectAttr hdbc attr ptr 0 lenptr))623 (cffi:mem-ref ptr :long)))624 625 (defun get-connection-attr-string (hdbc attr)626 (with-temporary-allocations627 ((ptr (alloc-chars 256))628 (lenptr (cffi:foreign-alloc :long)))629 (with-error-handling (:hdbc hdbc)630 (SQLGetConnectAttr hdbc attr ptr 256 lenptr))631 (get-string ptr (cffi:mem-ref lenptr :long))))632 633 ;;; small test for the get-connection-attr634 (defun %get-current-catalog (hdbc)635 (get-connection-attr-string hdbc $SQL_ATTR_CURRENT_CATALOG))636 637 (defun %set-current-catalog (hdbc catalog)638 (set-connection-attr-string hdbc $SQL_ATTR_CURRENT_CATALOG catalog))639 640 641 642 (defun %connection-ok-p (hdbc)643 (with-error-handling (:hdbc hdbc)644 (ecase (get-connection-attr-integer hdbc $SQL_ATTR_CONNECTION_DEAD)645 (#.$sql_cd_true nil)646 (#.$sql_cd_false t))))647 590 648 591 ;;; 649 592 650 593 ; column-nr is zero-based 651 ;;;; dso+652 594 (defun %sql-get-data (hstmt column-nr c-type data-ptr precision out-len-ptr) 653 595 (declare ((integer 0) column-nr)) … … 657 599 c-type data-ptr precision out-len-ptr))) 658 600 659 ;;;; dso+660 601 (defun %sql-get-data-raw (hstmt position c-type data-ptr buffer-length ind-ptr) 661 602 (declare ((integer 0) position)) … … 664 605 665 606 666 ;;;; dso+667 607 (defun %sql-param-data (hstmt param-ptr) 668 608 (with-error-handling (:hstmt hstmt :print-info t) ;; nil … … 670 610 671 611 672 ;;;; dso+673 612 (defun %sql-put-data (hstmt data-ptr size) 674 613 (with-error-handling … … 677 616 678 617 679 ;;;; dso+680 618 (defun %sql-more-results (hstmt) 681 619 (let ((res (SQLMoreResults hstmt)))
Note: See TracChangeset
for help on using the changeset viewer.
