This is an example from the documentation which gives strange results on Lispworks 5.0.2. I'm using the latest version of postmodern (1.02)
CL-USER 3 > (postmodern:sql (:select (:+ 'field-1 100) 'field-5 :from (:as 'my-table 'x) :left-join 'your-table :on (:= 'x.field-2 'your-table.field-1) :where (:not-null 'a.field-3))) "(SELECT (field_1 + 100), field_5 FROM my_table AS x LEFT JOIN your_table ON (x.field_2 = your_table.field_1), your_table, on, (x.field_2 = ................................^ your_table.field_1) WHERE not_null(a.field_3))"
Jens
PS my previous problem with if statement is solved, I needed a macro instead of a function
Hello,
Are you sure the problem is not just the fact that the tables do not exist? You didn't post an actual error message, so I'm not sure what happens.
Cheers, Marijn
Marijn Haverbeke wrote:
Hello,
Are you sure the problem is not just the fact that the tables do not exist? You didn't post an actual error message, so I'm not sure what happens.
The problem also happens with existing tables. I checked with sbcl and there the result is correct.
Don't bother too much about this problem, I can live for the moment expressing the join without :on in the :where clause.
Thanks Jens
So could you give me the error message? That might give me a chance to figure out what the problem is.
Cheers, Marijn
Marijn Haverbeke wrote:
So could you give me the error message? That might give me a chance to figure out what the problem is.
Cheers, Marijn
Here are two queries which should produce the same result
WEBCAT 36 > (postmodern:with-connection ("web_access" "web_access" "***" "localhost") (postmodern:query (:select 'pmw.wert :from (:as 'projekt-merkmale-werte 'pmw) (:as 'projekt-elemente 'pe) :where (:and (:= 'pmw.guid-produkt 'pe.guid-objekt) (:= 'pe.guid "rzt732819vlurc5827955302wwxz8b") (:= 'pmw.merkmal-id "MID1008519") (:= 'pmw.lang-id "de"))))) (("30 N") ("30 N") ("30 N") ("30 N"))
WEBCAT 37 > (postmodern:with-connection ("web_access" "web_access" "***" "localhost") (postmodern:query (:select 'pmw.wert :from (:as 'projekt-merkmale-werte 'pmw) :inner-join (:as 'projekt-elemente 'pe) :on (:= 'pmw.guid-produkt 'pe.guid-objekt) :where (:and (:= 'pe.guid "rzt732819vlurc5827955302wwxz8b") (:= 'pmw.merkmal-id "MID1008519") (:= 'pmw.lang-id "de")))))
Error: Database error 42601: syntax error at or near "on" Query: (SELECT pmw.wert FROM projekt_merkmale_werte AS pmw INNER JOIN projekt_elemente AS pe ON (pmw.guid_produkt = pe.guid_objekt), projekt_elemente AS pe, on, (pmw.guid_produkt = pe.guid_objekt) WHERE ((pe.guid = 'rzt732819vlurc5827955302wwxz8b') and (pmw.merkmal_id = 'MID1008519') and (pmw.lang_id = 'de')))
Jens
hi, first of all sorry for the trivial question.
I want to install postmodern with Allegro CL 8.0 Free express edition but i could not succeed. I think there is a problem with asdf/asdf-install library but i am not sure. What may be the reason? Thank you in advance.
On 17/08/07, Jens Teich info@jensteich.de wrote:
Marijn Haverbeke wrote:
So could you give me the error message? That might give me a chance to figure out what the problem is.
Cheers, Marijn
Here are two queries which should produce the same result
WEBCAT 36 > (postmodern:with-connection ("web_access" "web_access" "***" "localhost") (postmodern:query (:select 'pmw.wert :from (:as 'projekt-merkmale-werte 'pmw) (:as 'projekt-elemente 'pe) :where (:and (:= 'pmw.guid-produkt 'pe.guid-objekt) (:= 'pe.guid "rzt732819vlurc5827955302wwxz8b") (:= 'pmw.merkmal-id "MID1008519") (:= 'pmw.lang-id "de"))))) (("30 N") ("30 N") ("30 N") ("30 N"))
WEBCAT 37 > (postmodern:with-connection ("web_access" "web_access" "***" "localhost") (postmodern:query (:select 'pmw.wert :from (:as 'projekt-merkmale-werte 'pmw) :inner-join (:as 'projekt-elemente 'pe) :on (:= 'pmw.guid-produkt 'pe.guid-objekt) :where (:and (:= 'pe.guid "rzt732819vlurc5827955302wwxz8b") (:= 'pmw.merkmal-id "MID1008519") (:= 'pmw.lang-id "de")))))
Error: Database error 42601: syntax error at or near "on" Query: (SELECT pmw.wert FROM projekt_merkmale_werte AS pmw INNER JOIN projekt_elemente AS pe ON (pmw.guid_produkt = pe.guid_objekt), projekt_elemente AS pe, on, (pmw.guid_produkt = pe.guid_objekt) WHERE (( pe.guid = 'rzt732819vlurc5827955302wwxz8b') and (pmw.merkmal_id = 'MID1008519') and (pmw.lang_id = 'de')))
Jens _______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
Hi Tarik,
(Don't reply to a message when you're opening a new topic -- it confuses mail readers.)
You will need ASDF to run Postmodern, but I think that should come included with Allegro (does it? any other Allegro users on this list?). ASDF-Install makes it easy to download and install the library, but is not necessary. Download the .tar.gz file from the library page, unpack it somewhere on your system (use a tool like WinRAR if you're on Windows), and create a file-system link to the .asd files in some directory that your ADSF searches (the variable asdf:*central-repository* should contain a list of such directories.) After this, doing (asdf:oos 'asdf:load-op :postmodern) should load the library.
Cheers, Marijn
ok.i am sorry for that. thank you for the help. cheers On 19/08/07, Marijn Haverbeke marijnh@gmail.com wrote:
Hi Tarik,
(Don't reply to a message when you're opening a new topic -- it confuses mail readers.)
You will need ASDF to run Postmodern, but I think that should come included with Allegro (does it? any other Allegro users on this list?). ASDF-Install makes it easy to download and install the library, but is not necessary. Download the .tar.gz file from the library page, unpack it somewhere on your system (use a tool like WinRAR if you're on Windows), and create a file-system link to the .asd files in some directory that your ADSF searches (the variable asdf:*central-repository* should contain a list of such directories.) After this, doing (asdf:oos 'asdf:load-op :postmodern) should load the library.
Cheers, Marijn _______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
Aha, I see the syntax error now -- might be some slight difference in the way LOOP works on LispWorks. But I'm on a public computer somewhere, and will not be near any machines running Lisp in the next weeks, so I can't really debug this for you. If you want to solve this, you can try digging into the code in s-sql/s-sql.lisp that produces such queries, and see where it goes wrong (shouldn't be too hard). Or maybe someone else on the list wants to take a quick look?
Cheers, Marijn
Marijn Haverbeke wrote:
Aha, I see the syntax error now -- might be some slight difference in the way LOOP works on LispWorks. But I'm on a public computer somewhere, and will not be near any machines running Lisp in the next weeks, so I can't really debug this for you. If you want to solve this, you can try digging into the code in s-sql/s-sql.lisp that produces such queries, and see where it goes wrong (shouldn't be too hard). Or maybe someone else on the list wants to take a quick look?
Cheers, Marijn
Hi Marijn,
I looked into the code and found the function expand-join to be a candidate for cause of the problems:
(defun expand-joins (args) "Helper for the select operator. Turns the part following :from into the proper SQL syntax for joining tables." (labels ((is-join (x) (member x '(:left-join :right-join :inner-join :cross-join)))) (when (null args) (error "Empty :from clause in select")) (when (is-join (car args)) (error ":from clause starts with a join: ~A" args)) (loop :for table :on args :for first = t :then nil :append (cond ((is-join (car table)) (destructuring-bind (join name on clause) (subseq table 0 4) (setf table (cdddr table)) ;; debug start (print (list "table" table)) ;; debug end (unless (and (eq on :on) clause) (error "Incorrect join form in select.")) `(" " ,(ecase join (:left-join "LEFT") (:right-join "RIGHT") (:inner-join "INNER") (:cross-join "CROSS")) " JOIN " ,@(sql-expand name) " ON " ,@(sql-expand clause)))) (t `(,@(if first () '(", ")) ,@(sql-expand (car table))))))))
I traced it:
S-SQL 68 > (trace expand-joins) (EXPAND-JOINS)
S-SQL 69 > (sql (:select '* :from 't1 :inner-join 't2 :on (:= 't1.id 't2.id))) 0 EXPAND-JOINS > ...
ARGS : ((QUOTE T1) :INNER-JOIN (QUOTE T2) :ON (:= (QUOTE T1.ID) (QUOTE T2.ID)))
0 EXPAND-JOINS < ... << VALUE-0 : ("t1" " " "INNER" " JOIN " "t2" " ON " "(" "t1.id" " = " "t2.id" ")" ", " "t2" ", " "on" ", " "(" "t1.id" " = " "t2.id" ")") "(SELECT * FROM t1 INNER JOIN t2 ON (t1.id = t2.id), t2, on, (t1.id = t2.id))"
For me it looks a bit strange to declare a loop variable | :for table :on args and later on to manipulate this variable with setf | (setf table (cdddr table))
and indeed LispWorks and SBCL behave differently with such an expression
LW> (loop for item on '(1 2 3 4 5) collect (progn (setf item (cddr item)) item)) => ((3 4 5) (4 5) (5) NIL NIL)
SBCL> (loop for item on '(1 2 3 4 5) collect (progn (setf item (cddr item)) item)) => ((3 4 5) NIL)
where LispWorks produces 'too much' output as in the original problem.
Jens
Hi,
Thanks for tracing the problem. If you have a fix, could you send me a patch (as created by 'darcs send -o fix.patch'), so I can apply it to the repository?
Marijn
Hello Jens (and other lispworks users),
I finally got a chance to do some coding, and I pushed a patch that should fix this problem -- could you try it out and tell me if it works at all. The only lisp interpreter I had available was Franz' telnet repl, so testing has been minimal, but the changes weren't that drastic, so there is a not unreasonable chance that they are correct.
Cheers, Marijn
postmodern-devel@common-lisp.net