-;;; 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))
+(defmacro with-umlisp-query ((table fields srl where-name where-value
+ &key (lrlname "KCUILRL") distinct single
+ order like)
+ &body body)
+ (let ((query (gensym)))
+ `(unless (and ,where-name (not ,where-value))
+ (let ((,query (umlisp-query ,table (quote ,fields) ,srl ,where-name ,where-value
+ :lrlname ,lrlname :single ,single :distinct ,distinct
+ :order ,order :like ,like)))
+ (if ,single
+ (let ((tuple (car ,query)))
+ (when tuple
+ (destructuring-bind ,fields tuple
+ ,@body)))
+ (loop
+ for tuple in ,query collect
+ (destructuring-bind ,fields tuple
+ ,@body)))))))
+
+(defun umlisp-query (table fields srl where-name where-value
+ &key (lrlname "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"
+ (when (or (not where-name) where-value)
+ (mutex-sql-query
+ (query-string table fields srl where-name where-value
+ :lrlname lrlname :single single :distinct distinct :order order :like like))))