r9189: implement result-types for sqlite
[clsql.git] / base / database.lisp
index 953c40a3bc51779d74b4375a2292f04ea59c97f5..e4016d3c547f603ceefed503a2886bd692257a6e 100644 (file)
@@ -85,6 +85,9 @@ to the new connection, otherwise *default-database is not changed. If
 pool is t the connection will be taken from the general pool, if pool
 is a conn-pool object the connection will be taken from this pool."
 
+  (unless database-type
+    (error "Must specify a database-type."))
+  
   (when (stringp connection-spec)
     (setq connection-spec (string-to-list-connection-spec connection-spec)))
   
@@ -181,7 +184,7 @@ if the database connection has been lost."
              ((or string list)
               (let ((db (find-database database :errorp nil)))
                 (when (null db)
-                  (if (and database errorp)
+                  (if (and database error)
                       (error 'clsql-generic-error
                              :message
                              (format nil "Unable to find database with connection-spec ~A." database))
@@ -201,26 +204,38 @@ if the database connection has been lost."
 output, for the connected databases and initialized database types. If
 full is T, detailed status information is printed. The default value
 of full is NIL."
-  (declare (ignore full))
-  ;; TODO: table details if full is true?
   (flet ((get-data ()
            (let ((data '()))
              (dolist (db (connected-databases) data)
-               (push (list (database-name db)
-                           (string (database-type db))
-                           (when (conn-pool db) "T" "NIL")
-                           (format nil "~A" (length (database-list-tables db)))
-                           (format nil "~A" (length (database-list-views db)))
-                           (if (equal db *default-database*) "   *" ""))
-                     data))))
-         (compute-sizes (data)
+              (push 
+               (append 
+                (list (if (equal db *default-database*) "*" "")        
+                      (database-name db)
+                      (string-downcase (string (database-type db)))
+                      (cond ((and (command-recording-stream db) 
+                                  (result-recording-stream db)) 
+                             "Both")
+                            ((command-recording-stream db) "Commands")
+                            ((result-recording-stream db) "Results")
+                            (t "nil")))
+                (when full 
+                  (list 
+                   (if (conn-pool db) "t" "nil")
+                   (format nil "~A" (length (database-list-tables db)))
+                   (format nil "~A" (length (database-list-views db))))))
+               data))))
+        (compute-sizes (data)
            (mapcar #'(lambda (x) (apply #'max (mapcar #'length x)))
                    (apply #'mapcar (cons #'list data))))
          (print-separator (size)
            (format t "~&~A" (make-string size :initial-element #\-))))
+    (format t "~&CLSQL STATUS: ~A~%" (iso-timestring (get-time)))
     (let ((data (get-data)))
       (when data
-        (let* ((titles (list "NAME" "TYPE" "POOLED" "TABLES" "VIEWS" "DEFAULT"))
+        (let* ((titles (if full 
+                          (list "" "DATABASE" "TYPE" "RECORDING" "POOLED" 
+                                "TABLES" "VIEWS")
+                          (list "" "DATABASE" "TYPE" "RECORDING")))
                (sizes (compute-sizes (cons titles data)))
                (total-size (+ (apply #'+ sizes) (* 2 (1- (length titles)))))
                (control-string (format nil "~~&~~{~{~~~AA  ~}~~}" sizes)))
@@ -246,6 +261,10 @@ of full is NIL."
     (setq connection-spec (string-to-list-connection-spec connection-spec)))
   (database-destroy connection-spec database-type))
 
+(defun list-databases (connection-spec &key database-type)
+  (when (stringp connection-spec)
+    (setq connection-spec (string-to-list-connection-spec connection-spec)))
+  (database-list connection-spec database-type))
 
 (defmacro with-database ((db-var connection-spec &rest connect-args) &body body)
   "Evaluate the body in an environment, where `db-var' is bound to the