Hi all,
here's a function I've written:
(defun test-web (&optional qname)
(let ((aq "SELECT lastname,firstname FROM members")
result stuff)
(if qname
(setf aq (concatenate 'string aq " WHERE lastname= '" qname
"'")))
(connect '("localhost" "rlg" "root" "none") :database-type :mysql)
(setf result "<table><tr><th>Last</th><th>First</th></tr>")
(do-query ((lastname firstname) aq)
; (let (lastname firstname)
(setf stuff (format nil "<tr><td>~a</td><td>~a</td></tr>"
lastname firstname))
(setf result (concatenate 'string result stuff)))
(disconnect)
(setf result (concatenate 'string result "</table>"))
(format t "Result: ~A~%" result)
result))
It's supposed to output 2 fields of a database as an html table. As it
is here, it finds unreachable code in the format statement below the
commented out statement. If I uncomment the let, and comment the
do-query, the error goes away but there is obviously no query done.
What have I screwed up here?
Jonathon McKitrick <···········@bigfoot.com> wrote:
+---------------
| (defun test-web (&optional qname)
| (let ((aq "SELECT lastname,firstname FROM members")
| result stuff)
| (if qname
| (setf aq (concatenate 'string aq " WHERE lastname= '" qname "'")))
| (connect '("localhost" "rlg" "root" "none") :database-type :mysql)
| (setf result "<table><tr><th>Last</th><th>First</th></tr>")
| (do-query ((lastname firstname) aq)
| ; (let (lastname firstname)
| (setf stuff (format nil "<tr><td>~a</td><td>~a</td></tr>"
| lastname firstname))
| (setf result (concatenate 'string result stuff)))
| (disconnect)
| (setf result (concatenate 'string result "</table>"))
| (format t "Result: ~A~%" result)
| result))
|
| It's supposed to output 2 fields of a database as an html table. As it
| is here, it finds unreachable code in the format statement below the
| commented out statement. If I uncomment the let, and comment the
| do-query, the error goes away but there is obviously no query done.
| What have I screwed up here?
+---------------
Instead of using ";" to "comment out" the LET, try using "#-(and)".
The semicolon doesn't comment out the entire LET form, it only
comments out the first *line* of the LET form. As a result, you've
messed up your parenthesis-matching.
-Rob
-----
Rob Warnock <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
Rob Warnock wrote:
> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.
Thanks a bunch! I thought for sure there was some higher power at work
keeping me from getting this code working....
Rob Warnock wrote:
> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.
I *thought* that was it until I tried this function as well and got the
same error. No semicolons here, parens seem to match ok.
(defun test-web (&optional qname)
(let ((aq "SELECT lastname,firstname FROM members"))
(if qname
(setf aq (concatenate 'string aq " WHERE lastname= '" qname
"'")))
(connect '("localhost" "rlg" "root" "none") :database-type :mysql)
(let ((table "<table><tr><th>Last</th><th>First</th></tr>"))
(do-query ((lastname firstname) aq)
(setf table (format nil
"~a<tr><td>~a</td><td>~a</td></tr>"
table lastname firstname)))
(disconnect)
(setf table (concatenate 'string table "</table>"))
table)))
; in: DEFUN TEST-WEB
; (FORMAT NIL
; "~a<tr><td>~a</td><td>~a</td></tr>"
; DB::TABLE
; DB::LASTNAME
; DB::FIRSTNAME)
; ==>
; "~a<tr><td>~a</td><td>~a</td></tr>"
;
; note: deleting unreachable code
Rob Warnock wrote:
> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.
I *thought* that was it until I tried this function as well and got the
same error. No semicolons here, parens seem to match ok.
(defun test-web (&optional qname)
(let ((aq "SELECT lastname,firstname FROM members"))
(if qname
(setf aq (concatenate 'string aq " WHERE lastname= '" qname
"'")))
(connect '("localhost" "rlg" "root" "none") :database-type :mysql)
(let ((table "<table><tr><th>Last</th><th>First</th></tr>"))
(do-query ((lastname firstname) aq)
(setf table (format nil
"~a<tr><td>~a</td><td>~a</td></tr>"
table lastname firstname)))
(disconnect)
(setf table (concatenate 'string table "</table>"))
table)))
; in: DEFUN TEST-WEB
; (FORMAT NIL
; "~a<tr><td>~a</td><td>~a</td></tr>"
; DB::TABLE
; DB::LASTNAME
; DB::FIRSTNAME)
; ==>
; "~a<tr><td>~a</td><td>~a</td></tr>"
;
; note: deleting unreachable code
Rob Warnock wrote:
> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.
Well, that certainly helped until I saw it again here....
; file: /home/jonathon/cvs/cl-rlg/db/db.lisp
; in: DEFUN TEST-WEB
; (FORMAT NIL
; "~a<tr><td>~a</td><td>~a</td></tr>"
; DB::TABLE
; DB::LASTNAME
; DB::FIRSTNAME)
; ==>
; "~a<tr><td>~a</td><td>~a</td></tr>"
;
; note: deleting unreachable code
Here is the function in question, similar to the previous one but with
nothing commented out....
(defun test-web (&optional qname)
(let ((aq "SELECT lastname,firstname FROM members"))
(if qname
(setf aq (concatenate 'string aq " WHERE lastname= '" qname
"'")))
(connect '("localhost" "rlg" "root" "none") :database-type :mysql)
(let ((table "<table><tr><th>Last</th><th>First</th></tr>"))
(do-query ((lastname firstname) aq)
(setf table (format nil
"~a<tr><td>~a</td><td>~a</td></tr>"
table lastname firstname)))
(disconnect)
(setf table (concatenate 'string table "</table>"))
table)))
What could be the cause here? I keep thinking it has something to do
with (do-query) but I can't tell what.
Rob Warnock wrote:
> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.
Thanks a bunch! I thought for sure there was some higher power at work
keeping me from getting this code working....