r11164: fix case in tests
[umlisp.git] / sql-classes.lisp
index 1187d5931bd9bc52a0791c43752dbaa434b2e865..f6f306ecb204ce8162f92bcf39b9dad8d01a5d3c 100644 (file)
@@ -35,7 +35,7 @@
                      ""))
         (%%lrl (format nil " AND ~:@(~A~)<=" lrl))
         (%%where (when where-name
-                   (format nil " where ~:@(~A~)~A" where-name
+                   (format nil " WHERE ~:@(~A~)~A" where-name
                          (if like " like " ""))))
          (%filter (gensym "FILTER-"))
          (%single (gensym "SINGLE-"))
@@ -55,7 +55,7 @@
                 (number
                  (concatenate 'string "='" (write-to-string ,where-value) "'"))
                 (null
-                 " is null")
+                 " IS NULL")
                 (t
                  (format nil ,(if like "'%~A%'" "='~A'") ,where-value)))))
         (if ,%filter (concatenate 'string
   (when single (setq limit 1))
   (concatenate
    'string
-   (format nil "select ~A~{~:@(~A~)~^,~} from ~:@(~A~)"
-          (if distinct "distinct " "") fields table)
-   (if where-name (format nil " where ~:@(~A~)" where-name) "")
+   (format nil "SELECT ~A~{~:@(~A~)~^,~} FROM ~:@(~A~)"
+          (if distinct "DISTINCT " "") fields table)
+   (if where-name (format nil " WHERE ~:@(~A~)" where-name) "")
    (if where-name
        (format nil
               (typecase where-value
                 (number "='~D'")
-                (null " is null")
+                (null " IS NULL")
                 (t
-                 (if like " like '%~A%""='~A'")))
+                 (if like " LINK '%~A%""='~A'")))
               where-value)
        "")
    (if filter (concatenate 'string " AND " filter) nil)
-   (if srl (format nil " and ~:@(~A~)<=~D" lrl srl) "")
-   (if order (format nil " order by ~{~:@(~A~) ~(~A~)~^,~}" order) "")
-   (if limit (format nil " limit ~D" limit) "")))
+   (if srl (format nil " AND ~:@(~A~)<=~D" lrl srl) "")
+   (if order (format nil " ORDER BY ~{~:@(~A~) ~(~A~)~^,~}" order) "")
+   (if limit (format nil " LIMIT ~D" limit) "")))
 
 
 (defmacro umlisp-query (table fields srl where-name where-value
@@ -229,19 +229,13 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
   (ensure-cui-integer cui)
   (unless cui (return-from find-ucon-cui nil))
 
-  (let ((tuple (car (mutex-sql-query
-                     (format nil
-                             "SELECT kcuilrl,str FROM MRCONSO WHERE CUI=~D AND KPFENG=1~A"
-                             cui (if srl (format nil " AND SRL<=~D" srl) ""))))))
-    (unless tuple
-      (setq tuple (car (mutex-sql-query
-                        (format nil
-                                "SELECT kcuilrl,str FROM MRCONSO WHERE CUI=~D"
-                                cui (if srl (format nil " AND SRL<=~D" srl) nil))))))
-    (unless tuple
-      (return-from find-ucon-cui nil))
-    (make-instance 'ucon :cui cui :pfstr (second tuple)
-                   :lrl (ensure-integer (first tuple)))))
+  (or
+   (collect-umlisp-query (mrconso (kcuilrl str) srl cui cui :single t :filter "KPFENG=1")
+    (make-instance 'ucon :cui cui :pfstr str
+                   :lrl kcuilrl))
+   (collect-umlisp-query (mrconso (kcuilrl str) srl cui cui :single t)
+    (make-instance 'ucon :cui cui :pfstr str
+                   :lrl kcuilrl))))
 
 (defun find-ucon-cui-sans-pfstr (cui &key (srl *current-srl*))
   "Find ucon for a cui"
@@ -572,11 +566,11 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
 
 (defun find-uso-aui (aui &key (srl *current-srl*))
   (ensure-sui-integer aui)
-  (collect-umlisp-query (mrconso (sab cui sui code srl tty saui sdui scui lat str) srl aui
-                                aui :lrl srl :single t)
+  (collect-umlisp-query (mrconso (sab cui sui code srl tty saui sdui scui lat
+                                      str) srl aui aui :lrl srl :single t)
     (make-instance 'uso :aui aui :cui cui :sab sab :code code :srl srl :tty tty
-                  :sui sui :saui saui :sdui sdui :scui scui
-                   :lat lat :str str)))
+                  :sui sui :saui saui :sdui sdui :scui scui :lat lat
+                   :str str)))
 
 (defun find-ucxt-cuisui (cui sui &key (srl *current-srl*))
   (ensure-cui-integer cui)
@@ -610,7 +604,7 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
   (ensure-cui-integer cui)
   (ensure-lui-integer lui)
   (ensure-sui-integer sui)
-  (let ((ls "select CODE,ATN,SAB,ATV from MRSAT where "))
+  (let ((ls "SELECT CODE,ATN,SAB,ATV FROM MRSAT WHERE "))
     (cond
       (sui (string-append ls "KCUISUI='"
                          (integer-string (make-cuisui cui sui) 14)
@@ -696,6 +690,15 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
                   :torule torule :tores tores :maprule maprule :maptype maptype :mapatn mapatn
                   :mapatv mapatv :cvf cvf)))
 
+(defun find-usmap-cui (cui)
+  (ensure-cui-integer cui)
+  (collect-umlisp-query (mrsmap (mapsetsab fromexpr fromtype rel rela toexpr totype cvf)
+                              nil mapsetcui cui)
+    (make-instance 'usmap :mapsetcui cui :mapsetsab mapsetsab
+                  :fromexpr fromexpr :fromtype fromtype
+                  :rel rel :rela rela :toexpr toexpr :totype totype
+                   :cvf cvf)))
+
 ;;;; Cross table find functions
 
 (defun find-ucon-tui (tui &key (srl *current-srl*))