X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=db-odbc%2Fodbc-sql.lisp;h=2850454bd5072421680de040bf07ade105bbbcfc;hb=cc92d162f24648d65ad872098353305a5baf91d7;hp=51d366b9360ccd2de9eab7e3b1ed4119127e152c;hpb=3ec4277531c7c19b1cffade823d3e2e3f928ceb3;p=clsql.git diff --git a/db-odbc/odbc-sql.lisp b/db-odbc/odbc-sql.lisp index 51d366b..2850454 100644 --- a/db-odbc/odbc-sql.lisp +++ b/db-odbc/odbc-sql.lisp @@ -61,7 +61,7 @@ :error "Connection failed"))))) (defmethod database-underlying-type ((database odbc-database)) - (odbc-db-type database)) + (database-odbc-db-type database)) (defun store-type-of-connected-database (db) (let* ((odbc-conn (database-odbc-conn db)) @@ -165,11 +165,11 @@ ;;; Sequence functions (defun %sequence-name-to-table (sequence-name) - (concatenate 'string "_clsql_seq_" (sql-escape sequence-name))) + (concatenate 'string "_CLSQL_SQL__" (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= (subseq table-name 0 11) "_CLSQL_SEQ_") (subseq table-name 11))) (defmethod database-create-sequence (sequence-name @@ -193,9 +193,18 @@ (defmethod database-list-sequences ((database odbc-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))) + ;; FIXME: Underlying database backend stuff should come from that backend + ;; Would need to use ASDF to ensure underlying backend was loaded + + (case (database-odbc-db-type database) + (:mysql + (mapcar #'(lambda (s) (%table-name-to-sequence-name (car s))) + (database-query "SHOW TABLES LIKE '%clsql_seq%'" + database nil))) + ((:postgresql :postgresql-socket) + (mapcar #'(lambda (s) (%table-name-to-sequence-name (car s))) + (database-query "SELECT RELNAME FROM pg_class WHERE RELNAME LIKE '%clsql_seq%'" + database nil))))) (defmethod database-list-tables ((database odbc-database) &key (owner nil)) @@ -210,6 +219,19 @@ (string-equal "TABLE" (nth 3 row))) collect (nth 2 row)))) +(defmethod database-list-views ((database odbc-database) + &key (owner nil)) + (declare (ignore owner)) + (multiple-value-bind (rows col-names) + (odbc-dbi:list-all-database-tables :db (database-odbc-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 odbc-database) &key (owner nil)) (declare (ignore owner)) @@ -296,9 +318,26 @@ (defmethod database-list-table-indexes (table (database odbc-database) &key (owner nil)) (declare (ignore owner)) + (if (eq :mysql (database-odbc-db-type database)) + (mysql-workaround-bug-list-table-indexes table database) + (odbc-list-table-indexes table database))) + +(defun mysql-workaround-bug-list-table-indexes (table database) + ;; MyODBC 3.52 does not properly return results from SQLStatistics + (do ((results nil) + (rows (database-query + (format nil "SHOW INDEX FROM ~A" (string-upcase table)) + database nil) + (cdr rows))) + ((null rows) (nreverse results)) + (let ((col (nth 2 (car rows)))) + (unless (find col results :test #'string-equal) + (push col results))))) + +(defun odbc-list-table-indexes (table database) (multiple-value-bind (rows col-names) (odbc-dbi:list-table-indexes - (string-downcase table) + table :db (database-odbc-conn database)) (declare (ignore col-names)) ;; INDEX_NAME is hard-coded in sixth position by ODBC driver @@ -307,12 +346,16 @@ (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)) + (col (nth 5 row))) + (unless (find col results :test #'string-equal) (push col results)))))) +;;; Database capabilities + +(defmethod db-backend-has-create/destroy-db? ((db-type (eql :odbc))) + nil) + + (defmethod database-initialize-database-type ((database-type (eql :odbc))) ;; nothing to do t)