Sun Aug 30 19:25:12 CEST 2009 khaelin@gmail.com * add support for the currval() and lastval() functions
Hi,
You'll notice that, even without your patch, something like (:currval "foo") expands to currval('foo') -- it's just a function, and when no special syntax is defined for a keyword, S-SQL will expand it as a function. Given this, does the patch still serve a purpose?
Best, Marijn
On 09-08-30 19:39, Marijn Haverbeke wrote:
Hi,
You'll notice that, even without your patch, something like (:currval "foo") expands to currval('foo') -- it's just a function, and when no special syntax is defined for a keyword, S-SQL will expand it as a function. Given this, does the patch still serve a purpose?
I don't know if I do it correctly, but without my patch: * (s-sql:sql-compile '(:select (:currval players_id_seq)))
"(SELECT currval(players_id_seq))"
With my patch: * (s-sql:sql-compile '(:select (:currval players_id_seq)))
"(SELECT currval(E'players_id_seq'))"
It seems that the default function expansion doesn't escape object names.
Since I'm here, note that there's also a setval() function, a bit more complex since it takes arguments (two or three), but I didn't figure how to add it (sorry, lisp beginner here). I'll try to add it... one day.
Regards,
* (s-sql:sql-compile '(:select (:currval players_id_seq))) "(SELECT currval(players_id_seq))"
* (s-sql:sql-compile '(:select (:currval players_id_seq))) "(SELECT currval(E'players_id_seq'))"
It seems that the default function expansion doesn't escape object names.
The Postgresql currval/nextval functions take strings. Passing a symbol, in S-SQL means passing an identifier. If you are generating s-sql expressions, have a symbol where you need a string, you can just call to-sql-name on it. Doing it that way should also make calling setval easier.
Best, Marijn
On 09-08-30 20:03, Marijn Haverbeke wrote:
* (s-sql:sql-compile '(:select (:currval players_id_seq))) "(SELECT currval(players_id_seq))"
* (s-sql:sql-compile '(:select (:currval players_id_seq))) "(SELECT currval(E'players_id_seq'))"
It seems that the default function expansion doesn't escape object names.
The Postgresql currval/nextval functions take strings. Passing a symbol, in S-SQL means passing an identifier. If you are generating s-sql expressions, have a symbol where you need a string, you can just call to-sql-name on it. Doing it that way should also make calling setval easier.
You seem to be right :) Perhaps should nextval() be removed then, for consistency purpose.
Regards,
Ah, there's already a :nextval. Now I see your point. I guess someone (possibly me) thought that was a good idea at the time. My issue is, though, that there's so much built-in functions in Postgres that providing a convenience wrapper for all of them would make the library huge.
I'd remove nextval, but that might break someone's code. The consistency isn't too bad, since the definition of :nextval also allows strings as input, people passing these functions strings (the logical thing to do) will never even notice this.
Best, Marijn
postmodern-devel@common-lisp.net