sym and lookup problem
Posted: Sat Mar 10, 2007 4:21 pm
I have the following function:
fieldName returns a string. value returns the contents of the particular row/field index combo. Basically, I do:
Now, what happens is my id and code print's are nil. If I do a (println rec) then I get:
Which looks OK. Now, if I remove the (sym ... ) around the (fieldName ...) portion of my rowAsHash function, therefore, I have:
I can do this
And that works as expected. My output is:
Does anyone have an idea as to what I am doing wrong with the first example? Also, is it possible that I could have symbol collisions, say, if someone query's a table with the field name, "name"? Thus using the reserved symbol 'name ?
Thanks,
Jeremy
Code: Select all
(define (rowAsHash res idx)
(set 'h '())
(dotimes (fidx (fieldCount res))
(push (list (sym (fieldName res fidx)) (value res idx fidx)) h))
h)
Code: Select all
(pg:query db "SELECT id, code FROM users"
(lambda (rec) ;; rec = result of rowAsHash
(println "Id: " (lookup 'id rec) " code: " (lookup 'code rec))))
Code: Select all
((id 10) (code "jdoe"))
Code: Select all
(define (rowAsHash res idx)
(set 'h '())
(dotimes (fidx (fieldCount res))
(push (list (fieldName res fidx) (value res idx fidx)) h))
h)
Code: Select all
(pg:query db "SELECT id, code FROM users"
(lambda (rec) ;; rec = result of rowAsHash
(println "Id: " (lookup "id" rec) " code: " (lookup "code" rec))))
Code: Select all
Id: 10 code: jdoe
Thanks,
Jeremy