X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=db-odbc%2Fodbc-dbi.lisp;h=2a60462ae0b8517530b285a2e7df173443a8228c;hb=1b07d2fd927cf8f1943ac0a0b8c980d1dc707076;hp=4bafb1f64b1aa2861b715bb4c5621f79e3d8b2a6;hpb=f716bb1161cf9e89a96945c4a444244f9d303691;p=clsql.git diff --git a/db-odbc/odbc-dbi.lisp b/db-odbc/odbc-dbi.lisp index 4bafb1f..2a60462 100644 --- a/db-odbc/odbc-dbi.lisp +++ b/db-odbc/odbc-dbi.lisp @@ -7,7 +7,7 @@ ;;;; Author: Kevin M. Rosenberg ;;;; Create: April 2004 ;;;; -;;;; $Id: odbc-sql.lisp 8983 2004-04-12 21:16:48Z kevin $ +;;;; $Id$ ;;;; ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -124,12 +124,21 @@ the query against." )) ;;; AODBC Compatible interface -(defun connect (&key data-source-name user password (autocommit t)) +(defun connect (&key data-source-name user password connection-string completion window-handle (autocommit t)) (let ((db (make-instance 'odbc-db))) (unless (henv db) ;; has class allocation! (setf (henv db) (%new-environment-handle))) (setf (hdbc db) (%new-db-connection-handle (henv db))) - (%sql-connect (hdbc db) data-source-name user password) + (if connection-string + (%sql-driver-connect (hdbc db) + connection-string + (ecase completion + (:no-prompt odbc::$SQL_DRIVER_NOPROMPT) + (:complete odbc::$SQL_DRIVER_COMPLETE) + (:prompt odbc::$SQL_DRIVER_PROMPT) + (:complete-required odbc::$SQL_DRIVER_COMPLETE_REQUIRED)) + window-handle) + (%sql-connect (hdbc db) data-source-name user password)) #+ignore (setf (db-hstmt db) (%new-statement-handle (hdbc db))) (when (/= (get-odbc-info db odbc::$SQL_TXN_CAPABLE) odbc::$SQL_TC_NONE) (if autocommit @@ -176,7 +185,8 @@ the query against." )) ((zerop count) (close-query query) (when eof-errorp - (error 'clsql-odbc-error :odbc-message "Ran out of data in fetch-row")) + (error 'clsql:sql-database-data-error + :message "ODBC: Ran out of data in fetch-row")) eof-value) (t (car row))))) @@ -216,7 +226,7 @@ the query against." )) (defun list-all-table-columns (table &key db hstmt) (declare (ignore hstmt)) - (db-describe-columns db "" "" table "")) + (db-describe-columns db nil nil table nil)) ;; use nil rather than "" for unspecified values (defun list-all-data-sources () (let ((db (make-instance 'odbc-db))) @@ -357,7 +367,7 @@ the query against." )) "get-free-query finds or makes a nonactive query object, and then sets it to active. This makes the functions db-execute-command and db-query thread safe." (with-slots (queries hdbc) database - (or (clsql-base-sys:without-interrupts + (or (clsql-sys:without-interrupts (let ((inactive-query (find-if (lambda (query) (not (query-active-p query))) queries))) @@ -423,7 +433,8 @@ This makes the functions db-execute-command and db-query thread safe." ;; allocate space to bind result rows to (multiple-value-bind (c-type data-ptr out-len-ptr size long-p) (%allocate-bindings sql-type precision) - (unless long-p ;; if long-p we fetch in chunks with %sql-get-data + (if long-p ;; if long-p we fetch in chunks with %sql-get-data but must ensure that out_len_ptr is non zero + (setf (uffi:deref-pointer out-len-ptr #.odbc::$ODBC-LONG-TYPE) #.odbc::$SQL_NO_TOTAL) (%bind-column hstmt col-nr c-type data-ptr (1+ size) out-len-ptr)) (vector-push-extend name column-names) (vector-push-extend sql-type column-sql-types) @@ -454,10 +465,11 @@ This makes the functions db-execute-command and db-query thread safe." (#.odbc::$SQL_C_DOUBLE :double) (#.odbc::$SQL_C_FLOAT :float) (#.odbc::$SQL_C_SSHORT :short) + (#.odbc::$SQL_C_STINYINT :short) (#.odbc::$SQL_BIGINT :short) (t t)))) (t - t))))) + t))))) query) (defun db-close-query (query &key drop-p) @@ -553,13 +565,13 @@ This makes the functions db-execute-command and db-query thread safe." (ecase sql-type ((#.odbc::$SQL_CHAR #.odbc::$SQL_VARCHAR #.odbc::$SQL_LONGVARCHAR) :string) ((#.odbc::$SQL_NUMERIC #.odbc::$SQL_DECIMAL #.odbc::$SQL_BIGINT) :string) ; ?? - (#.odbc::$SQL_INTEGER :long) + (#.odbc::$SQL_INTEGER #.odbc::$ODBC-LONG-TYPE) (#.odbc::$SQL_SMALLINT :short) - ((#.odbc::$SQL_FLOAT #.odbc::$SQL_DOUBLE) :long) - (#.odbc::$SQL_REAL :long) - (#.odbc::$SQL_DATE 'sql-c-date) - (#.odbc::$SQL_TIME 'sql-c-time) - (#.odbc::$SQL_TIMESTAMP 'sql-c-timestamp) + ((#.odbc::$SQL_FLOAT #.odbc::$SQL_DOUBLE) #.odbc::$ODBC-LONG-TYPE) + (#.odbc::$SQL_REAL #.odbc::$ODBC-LONG-TYPE) + ((#.odbc::$SQL_DATE #.odbc::$SQL_TYPE_DATE) 'sql-c-date) + ((#.odbc::$SQL_TIME #.odbc::$SQL_TYPE_TIME) 'sql-c-time) + ((#.odbc::$SQL_TIMESTAMP #.odbc::$SQL_TYPE_TIMESTAMP) 'sql-c-timestamp) ;;((#.odbc::$SQL_BINARY #.odbc::$SQL_VARBINARY #.odbc::$SQL_LONGVARBINARY) odbc::$SQL_C_BINARY) ; ?? (#.odbc::$SQL_TINYINT :short) ;;(#.odbc::$SQL_BIT odbc::$SQL_C_BIT) ; ?? @@ -582,7 +594,9 @@ This makes the functions db-execute-command and db-query thread safe." ;; support SQLDescribeParam. To do: put code in here for drivers that do ;; support it. (unless (string-equal sql "insert" :end1 6) - (error "Only insert expressions are supported in literal ODBC: '~a'." sql)) + (error 'clsql:sql-database-error + (format nil + "Only insert expressions are supported in literal ODBC: '~a'." sql))) (%db-execute query (format nil "select ~{~a~^,~} from ~a where 0 = 1" (or parameter-columns '("*")) parameter-table)) (%initialize-query query nil nil)