X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=db-aodbc%2Faodbc-sql.lisp;h=7994892302efb0dd29b06f330e32c32fd1cafc11;hp=56472113b5d34f7f01c9784c07a38717e627988d;hb=e622ee6f4bf2b9fe81af59d566e651c983a4833b;hpb=02c30e92614a52c892cc678933586f71c76fcf30 diff --git a/db-aodbc/aodbc-sql.lisp b/db-aodbc/aodbc-sql.lisp index 5647211..7994892 100644 --- a/db-aodbc/aodbc-sql.lisp +++ b/db-aodbc/aodbc-sql.lisp @@ -16,30 +16,26 @@ ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL. ;;;; ************************************************************************* -(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0))) -(in-package :clsql-aodbc) - +(in-package #:clsql-aodbc) ;; interface foreign library loading routines -(defmethod clsql-base-sys:database-type-library-loaded ((database-type (eql :aodbc))) +(defmethod clsql-sys:database-type-library-loaded ((database-type (eql :aodbc))) "T if foreign library was able to be loaded successfully. " (when (find-package :dbi) ;; finds Allegro's DBI (AODBC) package t)) -(defmethod clsql-base-sys:database-type-load-foreign ((databae-type (eql :aodbc))) +(defmethod clsql-sys:database-type-load-foreign ((databae-type (eql :aodbc))) t) (when (find-package :dbi) - (clsql-base-sys:database-type-load-foreign :aodbc)) - -(defmethod database-initialize-database-type ((database-type (eql :aodbc))) - t) + (clsql-sys:database-type-load-foreign :aodbc)) ;; AODBC interface -(defclass aodbc-database (database) - ((aodbc-conn :accessor database-aodbc-conn :initarg :aodbc-conn))) +(defclass aodbc-database (generic-odbc-database) + ((aodbc-conn :accessor database-aodbc-conn :initarg :aodbc-conn) + (aodbc-db-type :accessor database-aodbc-db-type :initform :unknown))) (defmethod database-name-from-spec (connection-spec (database-type (eql :aodbc))) @@ -55,97 +51,41 @@ (handler-case (make-instance 'aodbc-database :name (database-name-from-spec connection-spec :aodbc) + :database-type :aodbc + :dbi-package (find-package '#:dbi) :aodbc-conn (dbi:connect :user user :password password :data-source-name dsn)) + (sql-error (e) + (error e)) (error () ;; Init or Connect failed - (error 'clsql-connect-error + (error 'sql-connection-error :database-type database-type :connection-spec connection-spec - :errno nil - :error "Connection failed"))))) + :message "Connection failed"))))) -(defmethod database-disconnect ((database aodbc-database)) - #+aodbc-v2 - (dbi:disconnect (database-aodbc-conn database)) - (setf (database-aodbc-conn database) nil) - t) -(defmethod database-query (query-expression (database aodbc-database) types) - #+aodbc-v2 - (handler-case - (dbi:sql query-expression :db (database-aodbc-conn database) - :types types) - (error () - (error 'clsql-sql-error - :database database - :expression query-expression - :errno nil - :error "Query failed")))) - -(defmethod database-execute-command (sql-expression - (database aodbc-database)) - #+aodbc-v2 - (handler-case - (dbi:sql sql-expression :db (database-aodbc-conn database)) - (error () - (error 'clsql-sql-error - :database database - :expression sql-expression - :errno nil - :error "Execute command failed")))) - -(defstruct aodbc-result-set - (query nil) - (types nil :type cons) - (full-set nil :type boolean)) - -(defmethod database-query-result-set ((query-expression string) - (database aodbc-database) - &key full-set types) - #+aodbc-v2 - (handler-case - (multiple-value-bind (query column-names) - (dbi:sql query-expression - :db (database-aodbc-conn database) - :row-count nil - :column-names t - :query t - :types types - ) - (values - (make-aodbc-result-set :query query :full-set full-set - :types types) - (length column-names) - nil ;; not able to return number of rows with aodbc - )) - (error () - (error 'clsql-sql-error - :database database - :expression query-expression - :errno nil - :error "Query result set failed")))) - -(defmethod database-dump-result-set (result-set (database aodbc-database)) - #+aodbc-v2 - (dbi:close-query (aodbc-result-set-query result-set)) + +(defmethod database-create (connection-spec (type (eql :aodbc))) + (warn "Not implemented.")) + +(defmethod database-destroy (connection-spec (type (eql :aodbc))) + (warn "Not implemented.")) + +(defmethod database-probe (connection-spec (type (eql :aodbc))) + (warn "Not implemented.")) + +;;; Backend capabilities + +(defmethod database-underlying-type ((database aodbc-database)) + (database-aodbc-db-type database)) + +(defmethod db-backend-has-create/destroy-db? ((db-type (eql :aodbc))) + nil) + +(defmethod database-initialize-database-type ((database-type (eql :aodbc))) t) -(defmethod database-store-next-row (result-set - (database aodbc-database) - list) - #+aodbc-v2 - (let ((row (dbi:fetch-row (aodbc-result-set-query result-set) nil 'eof))) - (if (eq row 'eof) - nil - (progn - (loop for elem in row - for rest on list - do - (setf (car rest) elem)) - list)))) - -#+ignore -(when (clsql-base-sys:database-type-library-loaded :aodbc) - (clsql-base-sys:initialize-database-type :database-type :aodbc)) +(when (clsql-sys:database-type-library-loaded :aodbc) + (clsql-sys:initialize-database-type :database-type :aodbc))