r9450: 22 May 2004 Kevin Rosenberg
[clsql.git] / db-odbc / odbc-dbi.lisp
index c81f0842a9e78f347d0bd68d8bc50723185873bf..634a43e2601f101cc9b19e51d6aea0be108925a5 100644 (file)
@@ -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
 ;;;;
@@ -176,7 +176,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)))))
@@ -334,7 +335,7 @@ the query against." ))
        (if (plusp (column-count free-query)) ;; KMR: Added check for commands that don't return columns
            (values
             (db-fetch-query-results free-query nil)
-            (column-names free-query))
+            (map 'list #'identity (column-names free-query)))
          (values
           (result-rows-count (hstmt free-query))
           nil)))
@@ -357,7 +358,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)))
@@ -454,10 +455,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)
@@ -469,6 +471,7 @@ This makes the functions db-execute-command and db-query thread safe."
         (dotimes (col-nr count)
           (let ((data-ptr (aref column-data-ptrs col-nr))
                 (out-len-ptr (aref column-out-len-ptrs col-nr)))
+           (declare (ignorable data-ptr out-len-ptr))
            ;; free-statment :unbind frees these
            #+ignore (when data-ptr (uffi:free-foreign-object data-ptr))
            #+ignore (when out-len-ptr (uffi:free-foreign-object out-len-ptr)))))
@@ -492,7 +495,7 @@ This makes the functions db-execute-command and db-query thread safe."
               column-data-ptrs column-out-len-ptrs column-precisions
               computed-result-types)
       query
-    (unless (= (SQLFetch hstmt) odbc::$SQL_NO_DATA_FOUND)
+    (unless (= (odbc::SQLFetch hstmt) odbc::$SQL_NO_DATA_FOUND)
       (values
        (loop for col-nr from 0 to (- column-count 
                                      (if (eq ignore-columns :last) 2 1))
@@ -552,10 +555,10 @@ 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_FLOAT #.odbc::$SQL_DOUBLE) #.odbc::$ODBC-LONG-TYPE)
+    (#.odbc::$SQL_REAL #.odbc::$ODBC-LONG-TYPE)
     (#.odbc::$SQL_DATE 'sql-c-date)
     (#.odbc::$SQL_TIME 'sql-c-time)
     (#.odbc::$SQL_TIMESTAMP 'sql-c-timestamp)
@@ -581,7 +584,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)