[Chicken-users] Postgresql egg - usage for mortals?

2012-03-19 Thread Matt Welland
How do I do the equivalent of pg:query-for-each with the new api? It must
be simple but I am confused. Any kind soul willing to point me in the right
direction?
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Postgresql egg - usage for mortals?

2012-03-19 Thread Matt Welland
On Mon, Mar 19, 2012 at 1:13 AM, Peter Bex peter@xs4all.nl wrote:

 On Sun, Mar 18, 2012 at 11:42:44PM -0700, Matt Welland wrote:
  How do I do the equivalent of pg:query-for-each with the new api? It must
  be simple but I am confused. Any kind soul willing to point me in the
 right
  direction?

 I'm not 100% sure what the old procedure did again, but this is probably
 what you want:

 (row-for-each*
  (lambda (a b c)
(printf Got a = ~A, b = ~A, c = ~A\n a b c))
  (query conn SELECT a, b, c FROM foo))

 If you prefer to get the arguments in a list, use the version
 without a star:

 (row-for-each
  (lambda (tuple)
(printf Got tuple = ~A\n tuple))
  (query conn SELECT a, b, c FROM foo))


Yup, I think that is what I want. Once I saw your example it became
apparent that (query ...) is similar to prepare in the perl dbi api,
however I think I was confused since the paragraph describing query also
mentions prepare. As far as I can tell there is actually no prepare
statement.


 If the docs are unclear, I'd appreciate it if you can help me to
 improve them.


Perhaps a sentence clarifying what query does would help. An example
where the query is done prior to the row-for-each would probably have
triggered understanding for me.

(let ((sth (query conn SELECT a,b,c FROM foo)))
  (row-for-each
(lambda (tuple)
   (print tuple))
sth))

On the other hand just removing or explaining the reference to prepare in
the query description is probably enough.

Thanks for the reply and for maintaining the postgresql egg!

Cheers,
 Peter
 --
 http://sjamaan.ath.cx
 --
 The process of preparing programs for a digital computer
  is especially attractive, not only because it can be economically
  and scientifically rewarding, but also because it can be an aesthetic
  experience much like composing poetry or music.
-- Donald Knuth

 ___
 Chicken-users mailing list
 Chicken-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/chicken-users

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Postgresql egg - usage for mortals?

2012-03-19 Thread Peter Bex
On Mon, Mar 19, 2012 at 10:34:14AM -0700, Matt Welland wrote:
 Yup, I think that is what I want. Once I saw your example it became
 apparent that (query ...) is similar to prepare in the perl dbi api,
 however I think I was confused since the paragraph describing query also
 mentions prepare. As far as I can tell there is actually no prepare
 statement.

Indeed.  However, you can prepare a statement by issuing a normal
prepare command.  Then later you can execute this statement using
(query 'my-prepared-statement)

I re-read the docs and I agree they're worded very badly.  I'll try
and improve the bit under query.

 Perhaps a sentence clarifying what query does would help. An example
 where the query is done prior to the row-for-each would probably have
 triggered understanding for me.

I did add an example to row-for-each after replying to your previous
mail.  Hopefully that'll help.

 On the other hand just removing or explaining the reference to prepare in
 the query description is probably enough.

Yeah, the current paragraph is just mumbling about prepare but
not explaining anything.

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users