- (if like " like " "")))))
- `(concatenate
- 'string
- ,%%fields
- ,@(when %%where (list %%where))
- ,@(when %%where
- `((typecase ,where-value
- (fixnum
- (prefixed-fixnum-string ,where-value #\= 10))
- (number
- (concatenate 'string "=" (write-to-string ,where-value)))
- (null
- " is null")
- (t
- (format nil ,(if like "'%~A%'" "='~A'") ,where-value)))))
- (if ,srl (concatenate 'string ,%%lrl (write-to-string ,srl)) "")
- ,@(when %%order (list %%order))
- ,@(when single (list " limit 1")))))
+ (if like " like " ""))))
+ (%filter (gensym "FILTER-"))
+ (%single (gensym "SINGLE-"))
+ (%limit (gensym "LIMIT-")))
+ `(let ((,%limit ,limit)
+ (,%single ,single)
+ (,%filter ,filter))
+ (concatenate
+ 'string
+ ,%%fields
+ ,@(when %%where (list %%where))
+ ,@(when %%where
+ `((typecase ,where-value
+ #+ignore
+ (fixnum
+ (concatenate 'string "='" (prefixed-fixnum-string ,where-value #\0 10) "'"))
+ (number
+ (concatenate 'string "='" (write-to-string ,where-value) "'"))
+ (null
+ " is null")
+ (t
+ (format nil ,(if like "'%~A%'" "='~A'") ,where-value)))))
+ (if ,%filter (concatenate 'string
+ ,(if %%where " AND " " WHERE ")
+ ,%filter) "")
+ (if ,srl (concatenate 'string ,%%lrl (write-to-string ,srl)) "")
+ ,@(when %%order (list %%order))
+ (cond
+ ((and ,%single ,%limit)
+ (error "Can't set single and limit"))
+ (,%single
+ " LIMIT 1")
+ (,%limit
+ (format nil " LIMIT ~D" ,%limit))
+ (t
+ ""))))))