- (let* ((%%fields (format nil "select ~A~{~:@(~A~)~^,~}"
- (if distinct "distinct " "") (quote fields)))
- (%%order (if order (format nil " order by ~{~:@(~A~) ~(~A~)~^,~}" order) "")))
- (concatenate
- 'string
- (format nil "select ~A from ~:@(~A~)" ,%%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) "")
- ,%%order
- (if ,single " limit 1" "")))
+ (let* ((%%fields (format nil "select ~A~{~:@(~A~)~^,~} from ~:@(~A~)"
+ (if distinct "distinct " "") fields table))
+ (%%order (if order (format nil " order by ~{~:@(~A~) ~(~A~)~^,~}" order) ""))
+ (%%lrl (format nil " and ~:@(~A~) <= ~~D" lrlname))
+ (%%where (format nil " where ~:@(~A~)" where-name)))
+ `(concatenate
+ 'string
+ ,%%fields
+ ,@(when %%where (list %%where))
+ (if (quote ,where-name)
+ (format nil (if (stringp ,where-value)
+ (if ,like " like '%~A%'" "='~A'")
+ "=~A")
+ ,where-value)
+ "")
+ (if ,srl (format nil ,%%lrl ,srl) "")
+ ,@(when %%order (list %%order))
+ ,@(when single (list " limit 1")))))