r4750: Auto commit for Debian build
[umlisp.git] / sql-classes.lisp
index e954fe83278928f9ce63085d1a07b7047c038b6d..1fe072343fea69a3bd5ff641876acde8c494ccc5 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Author:        Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2000
 ;;;;
-;;;; $Id: sql-classes.lisp,v 1.20 2003/05/03 00:27:30 kevin Exp $
+;;;; $Id: sql-classes.lisp,v 1.24 2003/05/03 19:32:00 kevin Exp $
 ;;;;
 ;;;; This file, part of UMLisp, is
 ;;;;    Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D.
@@ -58,32 +58,28 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
   
 (defun query-string (table fields &optional srl where-name where-value
                     &key (lrlname "KCUILRL") single distinct order like)
-  (let ((qs (format nil "select ~A~{~:@(~A~)~^,~} from ~:@(~A~)" 
-                   (if distinct "distinct " "")
-                   fields table)))
-    (when where-name
-      (setq qs (concatenate 'string qs
-                           (format nil
-                                   (if (stringp where-value)
-                                       (if like
-                                           " where ~A like '%~A%'"
-                                         " where ~A='~A'")
-                                     " where ~A=~A")
-                                   where-name  where-value))))
-    (when srl
-      (setq qs (concatenate 'string qs (format nil " and ~:@(~A~) <= ~D"
-                                              lrlname srl))))
-    (when order
-      (setq qs (concatenate 'string qs
-                           (format nil " order by ~{~:@(~A~) ~(~A~)~^,~}"
-                                   (flatten
-                                    (loop for o in order collect
-                                          (if (atom o)
-                                              (list o  'asc)
-                                              (list (car o) (cdr o)))))))))
-    (when single
-      (setq qs (concatenate 'string qs " limit 1")))
-    qs))
+  (concatenate
+   'string
+   (format nil "select ~A~{~:@(~A~)~^,~} from ~:@(~A~)" 
+          (if distinct "distinct " "") fields table)
+   (if where-name
+       (format nil
+              (if (stringp where-value)
+                  (if like
+                      " where ~A like '%~A%'"
+                      " where ~A='~A'")
+                  " where ~A=~A")
+              where-name  where-value)
+       "")
+   (if srl (format nil " and ~:@(~A~) <= ~D" lrlname srl) "")
+   (if order
+       (format nil " order by ~{~:@(~A~) ~(~A~)~^,~}"
+              (flatten (loop for o in order collect
+                             (if (atom o)
+                                 (list o  'asc)
+                                 (list (car o) (cdr o))))))
+       "")
+   (if single " limit 1" "")))
 
 (defun find-ucon-cui (cui &key (srl *current-srl*))
   "Find ucon for a cui"
@@ -92,6 +88,18 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
                   :pfstr kpfstr
                   :lrl (ensure-integer kcuilrl))))
 
+(defun find-ucon-cui-old (cui &key (srl *current-srl*))
+  "Find ucon for a cui"
+  (when (stringp cui) (setq cui (parse-cui cui)))
+  (when cui
+    (let ((ls (format nil "select KPFSTR,KCUILRL from MRCON where CUI=~d" cui)))
+      (when srl
+       (string-append ls (format nil " and KCUILRL <= ~d" srl)))
+      (string-append ls " limit 1")
+      (awhen (car (mutex-sql-query ls))
+            (destructuring-bind (kpfstr kcuilrl)
+                (make-instance 'ucon :cui cui :pfstr kpfstr
+                           :lrl (ensure-integer kcuilrl)))))))
 
 (defun find-ucon-cui-sans-pfstr (cui &key (srl *current-srl*))
   "Find ucon for a cui"
@@ -134,24 +142,6 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
     (make-instance 'ucon :cui (ensure-integer cui) :pfstr kpfstr
                   :lrl (ensure-integer kcuilrl))))
 
-(defun f2 (&key (srl *current-srl*))
-  "Return list of all ucon's"
-  (with-umlisp-query ('mrcon (cui kpfstr kcuilrl) srl nil nil)
-    (make-instance 'ucon :cui (ensure-integer cui) :pfstr kpfstr
-                  :lrl (ensure-integer kcuilrl))))
-
-(defun f1 (&key (srl *current-srl*))
-  "Return list of all ucon's"
-  (with-sql-connection (db)
-    (clsql:map-query 
-     'list
-     #'(lambda (cui pfstr cuilrl)
-        (make-instance 'ucon :cui (ensure-integer cui)
-                       :pfstr pfstr
-                       :lrl (ensure-integer cuilrl)))
-     (query-string 'mrcon '(cui kpfstr kcuilrl) srl nil nil)
-     :database db)))
-
 (defun find-ucon-all (&key (srl *current-srl*))
   "Return list of all ucon's"
   (with-sql-connection (db)