r9114: fixes for list-indexes
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 20 Apr 2004 23:25:35 +0000 (23:25 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 20 Apr 2004 23:25:35 +0000 (23:25 +0000)
base/db-interface.lisp
base/package.lisp
db-mysql/mysql-sql.lisp
db-odbc/odbc-api.lisp
db-odbc/odbc-sql.lisp
sql/package.lisp
sql/table.lisp
tests/test-fddl.lisp

index d257a5fa3342c70616f117e4eefb23dd33c16c98..d874a7f67dfa15249b46bd7eae2e1368d061ea70 100644 (file)
@@ -204,6 +204,15 @@ the given lisp type and parameters."))
 (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)
 
index daea90f55082e0284549a37f7167d918eb0592c7..0301230f7cbbecc2b6798659939be3689adfea31 100644 (file)
         #: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."))
 
index c047b97a95880e8d2054bc432aed080503bea847..7cc6f50ba53d126b0a6af193125221fcb1e354b4 100644 (file)
          (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))
+
index 5ff3d09cb7f4750e32cedaf68fb1e45fb083eae9..03860af9333a698f13aa75b5eb438a1492ae5f54 100644 (file)
@@ -943,9 +943,6 @@ as possible second argument) to the desired representation of date/time/timestam
 (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
index 2fad84805755c8c3b029d553b899f8d677812978..0da1a04d4dd0c9143055ce613f116b87be05b3a4 100644 (file)
                                   &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))
index 302bc428c195fa690397d8d318d8ea1b8df87301..1a17ce631f7f4067e57f7d2baf3b084792efc5f1 100644 (file)
        #:database-commit-transaction
        #:transaction-level
        #:transaction
+       
+       ;; Database capabilities
+       #:db-use-column-on-drop-index?
+       
        ))
    (:export
     ;; "Private" exports for use by interface packages
index 52b5c1a155143c3b96a51228b9bfe4d504f2bc31..6491fade2719c1e510fe235eed0189c5f6baea79 100644 (file)
@@ -173,6 +173,8 @@ specification of a table to drop the index from."
        (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 "
index e231592c82610d5368c3607984c217b875415de5..98cd21601d13b73ce54105526dfa0b6f2efcbaef 100644 (file)
 ;; 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