-;;; Object lookups
-
-;;; Lookup functions for uterms,ustr in ucons
-
-(defun find-uterm-in-ucon (ucon lui)
- (find lui (s#term ucon) :key #'lui :test 'equal))
-
-(defun find-ustr-in-uterm (uterm sui)
- (find sui (s#str uterm) :key #'sui :test 'equal))
-
-(defun find-ustr-in-ucon (ucon sui)
- (let ((found-ustr nil))
- (dolist (uterm (s#term ucon))
- (unless found-ustr
- (dolist (ustr (s#str uterm))
- (unless found-ustr
- (when (string-equal sui (sui ustr))
- (setq found-ustr ustr))))))
- found-ustr))
+;; only WHERE-VALUE and SRL are evaluated
+(defmacro with-umlisp-query ((table fields srl where-name where-value
+ &key (lrl "KCUILRL") distinct single
+ order like)
+ &body body)
+ (let ((value (gensym)))
+ (if single
+ `(let ((,value ,where-value))
+ (when ,value
+ (let ((tuple (car (umlisp-query ,table ,fields ,srl ,where-name ,value
+ :lrl ,lrl :single ,single
+ :distinct ,distinct :order ,order
+ :like ,like))))
+ (when tuple
+ (destructuring-bind ,fields tuple
+ ,@body)))))
+ `(let ((,value ,where-value))
+ (when ,value
+ (loop for tuple in
+ (umlisp-query ,table ,fields ,srl ,where-name ,value
+ :lrl ,lrl :single ,single :distinct ,distinct
+ :order ,order :like ,like)
+ collect (destructuring-bind ,fields tuple
+ ,@body)))))))
+
+(defmacro umlisp-query (table fields srl where-name where-value
+ &key (lrl "KCUILRL") single distinct order like)
+ "Query the UMLisp database. Return a list of umlisp objects whose name
+is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
+ `(mutex-sql-query
+ (query-string-macro ,table ,fields ,srl ,where-name ,where-value
+ :lrl ,lrl :single ,single :distinct ,distinct :order ,order :like ,like)))