bug in select order-by clause
Kamen TOMOV <[email protected]> Wed, 12 Jul 2006 11:02:11 +0300
| Newsgroups | gmane.lisp.clsql.devel |
|---|---|
| Organization | CYBUILD |
| Message-ID | <[email protected]> |
Hi,
Yesterday I fixed a nasty bug that turned out to be in cl-sql. The
generated query looked like this:
select a.t1, b.t1, c.t1, d.t1, e.t2 from t1 order by e.t2 limit 100
I have the following method that generates it:
(defmethod search ((rs list))
(let ((id (cdr (find "id" rs :test #'equal :key #'car))))
(with-transaction ()
(let ((tname (class-name (def-rs id))))
(select tname
:refresh t
:limit 100
:order-by '(([req-time] :desc)))))))
I fixed the bug this way:
- :order-by '(([req-time] :desc)))))))
+ :order-by `((,[slot-value tname 'req-time] :desc))))))))
What's special here is that def-rs does eval defclass. When I eval the
method definition and call the method the query is correct:
select a.t1, b.t1, c.t1, d.t1, e.t1 from t1 order by e.t1 limit 100
However, if the next call of the method is with a different id, the
query looks this way:
select a.t2, b.t2, c.t2, d.t2, e.t1 from t1 order by e.t1 limit 100
and an exception is risen.
I tried to find out what's happening and I think that the problem is
in the [] macro. It operates in a different context from the way the
order-by is processed. Perhaps we need eval-when somewhere.
I have cl-sql v3.2.1 and cmu-cl.
Regards,
--
Kamen TOMOV