(defgeneric oid (object)
(:documentation "Return the unique ID of a database object."))
+;;; Database backend capabilities
+
+(defgeneric db-use-column-on-drop-index? (database)
+ (:method (database)
+ (declare (ignore database))
+ ;; Standard SQL does not use column name on DROP INDEX
+ nil)
+ (:documentation "NIL [default] lif database does not use column name on DROP INDEX."))
+
;;; Large objects support (Marc Battyani)
#:transaction-level
#:transaction
+ ;; Database features specialized by backend
+ #:db-use-column-on-drop-index?
+
))
(:documentation "This is the INTERNAL SQL-Interface package of CLSQL-BASE."))
(database-disconnect database)
(setf (slot-value database 'clsql-base-sys::state) :closed))))))
+;;; Database capabilities
+
+(defmethod db-use-column-on-drop-index? ((database mysql-database))
+ t)
(when (clsql-base-sys:database-type-library-loaded :mysql)
(clsql-base-sys:initialize-database-type :database-type :mysql))
+
(defun %table-statistics (table hstmt &key unique (ensure t))
(with-cstrings ((table-cs table))
(with-error-handling (:hstmt hstmt)
- (print hstmt)
- (print table-cs)
- (print (uffi:convert-from-cstring table-cs))
(SQLStatistics
hstmt
+null-ptr+ 0
&key (owner nil))
(let ((result '()))
(dolist (table (database-list-tables database :owner owner) result)
- (append (database-list-table-indexes table database :owner owner)
- result))))
+ (setq result
+ (append (database-list-table-indexes table database :owner owner)
+ result)))))
(defmethod database-list-table-indexes (table (database odbc-database)
&key (owner nil))
+ (declare (ignore owner))
(multiple-value-bind (rows col-names)
- (odbc-dbi:list-table-indexes table :db (database-odbc-conn database))
+ (odbc-dbi:list-table-indexes
+ (string-downcase table)
+ :db (database-odbc-conn database))
(declare (ignore col-names))
;; INDEX_NAME is hard-coded in sixth position by ODBC driver
- (loop for row in rows collect (nth 5 row))))
+ ;; FIXME: ??? is hard-coded in the fourth position
+ (do ((results nil)
+ (loop-rows rows (cdr loop-rows)))
+ ((null loop-rows) (nreverse results))
+ (let* ((row (car loop-rows))
+ (col (nth 5 row))
+ (type (nth 3 row)))
+ (unless (or (find col results :test #'string-equal)
+ #+ignore (equal "0" type))
+ (push col results))))))
+
+(defmethod database-initialize-database-type ((database-type (eql :odbc)))
+ ;; nothing to do
+ t)
-#+ignore
(when (clsql-base-sys:database-type-library-loaded :odbc)
(clsql-base-sys:initialize-database-type :database-type :odbc))
#:database-commit-transaction
#:transaction-level
#:transaction
+
+ ;; Database capabilities
+ #:db-use-column-on-drop-index?
+
))
(:export
;; "Private" exports for use by interface packages
(unless (index-exists-p index-name :database database)
(return-from drop-index)))
(:error t))
+ (unless (db-use-column-on-drop-index? database)
+ (setq on nil))
(execute-command (format nil "DROP INDEX ~A~A" index-name
(if (null on) ""
(concatenate 'string " ON "
;; test list-table-indexes
(deftest :fddl/index/3
(progn
- (clsql:create-index [bar] :on [employee] :attributes
- '([last-name]) :unique nil)
- (clsql:create-index [foo] :on [employee] :attributes
- '([first-name]) :unique nil)
+ (clsql:execute-command "CREATE TABLE I3TEST (a char(10), b integer)")
+ (clsql:create-index [bar] :on [i3test] :attributes
+ '([a]) :unique t)
+ (clsql:create-index [foo] :on [i3test] :attributes
+ '([b]) :unique nil)
(values
(sort
(mapcar
#'string-downcase
- (clsql:list-table-indexes [employee] :owner *test-database-user*))
+ (clsql:list-table-indexes [i3test] :owner *test-database-user*))
#'string-lessp)
(sort (clsql:list-table-indexes [company] :owner *test-database-user*)
#'string-lessp)
(progn
- (clsql:drop-index [bar] :on [employee])
- (clsql:drop-index [foo] :on [employee])
+ (clsql:drop-index [bar] :on [i3test])
+ (clsql:drop-index [foo] :on [i3test])
t)))
-
("bar" "foo") nil t)
;; create an sequence, test for existence, drop it and test again