;; AODBC interface
(defclass aodbc-database (database)
- ((aodbc-conn :accessor database-aodbc-conn :initarg :aodbc-conn)))
+ ((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)))
(handler-case
(make-instance 'aodbc-database
:name (database-name-from-spec connection-spec :aodbc)
+ :database-type :aodbc
:aodbc-conn
(dbi:connect :user user
:password password
:data-source-name dsn))
+ (clsql-error (e)
+ (error e))
(error () ;; Init or Connect failed
(error 'clsql-connect-error
:database-type database-type
(handler-case
(dbi:sql query-expression :db (database-aodbc-conn database)
:types result-types)
+ (clsql-error (e)
+ (error e))
(error ()
(error 'clsql-sql-error
:database database
#+aodbc-v2
(handler-case
(dbi:sql sql-expression :db (database-aodbc-conn database))
+ (clsql-error (e)
+ (error e))
(error ()
(error 'clsql-sql-error
:database database
(length column-names)
nil ;; not able to return number of rows with aodbc
))
+ (clsql-error (e)
+ (error e))
(error ()
(error 'clsql-sql-error
:database database
;;; Sequence functions
(defun %sequence-name-to-table (sequence-name)
- (concatenate 'string "_clsql_seq_" (sql-escape sequence-name)))
+ (concatenate 'string "_CLSQL_SEQ_" (sql-escape sequence-name)))
(defun %table-name-to-sequence-name (table-name)
(and (>= (length table-name) 11)
- (string= (subseq table-name 0 11) "_clsql_seq_")
+ (string-equal (subseq table-name 0 11) "_CLSQL_SEQ_")
(subseq table-name 11)))
(defmethod database-create-sequence (sequence-name
(defmethod database-list-sequences ((database aodbc-database)
&key (owner nil))
(declare (ignore owner))
- (mapcar #'(lambda (s) (%table-name-to-sequence-name (car s)))
- (database-query "SHOW TABLES LIKE '%clsql_seq%'"
- database nil)))
+ (warn "database-list-sequences not implemented for AODBC.")
+ nil)
+
+(defmethod database-list-tables ((database aodbc-database)
+ &key (owner nil))
+ (declare (ignore owner))
+ #+aodbc-v2
+ (multiple-value-bind (rows col-names)
+ (dbi:list-all-database-tables :db (database-aodbc-conn database))
+ (declare (ignore col-names))
+ ;; TABLE_SCHEM is hard-coded in second column by ODBC Driver Manager
+ ;; TABLE_NAME in third column, TABLE_TYPE in fourth column
+ (loop for row in rows
+ when (and (not (string-equal "information_schema" (nth 1 row)))
+ (string-equal "TABLE" (nth 3 row)))
+ collect (nth 2 row))))
+
+(defmethod database-list-views ((database aodbc-database)
+ &key (owner nil))
+ (declare (ignore owner))
+ #+aodbc-v2
+ (multiple-value-bind (rows col-names)
+ (dbi:list-all-database-tables :db (database-aodbc-conn database))
+ (declare (ignore col-names))
+ ;; TABLE_SCHEM is hard-coded in second column by ODBC Driver Manager
+ ;; TABLE_NAME in third column, TABLE_TYPE in fourth column
+ (loop for row in rows
+ when (and (not (string-equal "information_schema" (nth 1 row)))
+ (string-equal "VIEW" (nth 3 row)))
+ collect (nth 2 row))))
+
+(defmethod database-list-attributes ((table string) (database aodbc-database)
+ &key (owner nil))
+ (declare (ignore owner))
+ #+aodbc-v2
+ (multiple-value-bind (rows col-names)
+ (dbi:list-all-table-columns table :db (database-aodbc-conn database))
+ (let ((pos (position "COLUMN_NAME" col-names :test #'string-equal)))
+ (when pos
+ (loop for row in rows
+ collect (nth pos row))))))
+
+(defmethod database-attribute-type ((attribute string) (table string) (database aodbc-database)
+ &key (owner nil))
+ (declare (ignore owner))
+ #+aodbc-v2
+ (multiple-value-bind (rows col-names)
+ (dbi:list-all-table-columns table :db (database-aodbc-conn database))
+ (let ((pos (position "TYPE_NAME" col-names :test #'string-equal)))
+ (when pos
+ (loop for row in rows
+ collect (nth pos row))))))
+
+(defmethod database-list-indexes ((database aodbc-database)
+ &key (owner nil))
+ (warn "database-list-indexes not implemented for AODBC.")
+ nil)
(defmethod database-set-sequence-position (sequence-name
(position integer)
(database aodbc-database))
(database-execute-command
- (format nil "UPDATE ~A SET last-value=~A"
+ (format nil "UPDATE ~A SET last_value=~A,is_called='t'"
(%sequence-name-to-table sequence-name)
position)
database)
(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)
+
#+ignore
(when (clsql-base-sys:database-type-library-loaded :aodbc)
(clsql-base-sys:initialize-database-type :database-type :aodbc))