- (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 " ""))))
+ (%%limit (gensym "LIMIT-"))
+ (%%filter (gensym "FILTER-")))
+ `(let ((%%limit ,limit)
+ (%%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 " AND " ##filter) "")
+ (if ,srl (concatenate 'string ,%%lrl (write-to-string ,srl)) "")
+ ,@(when %%order (list %%order))
+ (if (or ,single ##limit)
+ (cond
+ ((and ,single (> ##limit 1))
+ (error "Can't set single and limit > 1."))
+ (,single
+ " LIMIT 1")
+ (##limit
+ (format nil " LIMIT ~D" ##limit))
+ (t
+ ""))
+ "")))))