[postmodern-devel] Calling a SQL func as a DAO field value

Hi, I'm trying to use NOW() as a value in an update statement using the DAO. I've tried of syntax combinations, but I can't get the right one. Hint? -- Julien Danjou /* Free Software hacker & freelance http://julien.danjou.info */

Doesn't (:now) work? On Tue, Dec 25, 2012 at 9:22 PM, Julien Danjou <julien@danjou.info> wrote:
Hi,
I'm trying to use NOW() as a value in an update statement using the DAO. I've tried of syntax combinations, but I can't get the right one.
Hint?
-- Julien Danjou /* Free Software hacker & freelance http://julien.danjou.info */
_______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel

On Tue, Dec 25 2012, Marijn Haverbeke wrote:
Doesn't (:now) work?
No, I get: Value (:NOW) can not be converted to an SQL literal. I've actually tried "NOW()", which is a string and seemed not valid to me so I just didn't try that possibility, and it seems to work… But I'm worring of what would happen if my field was not a timestamp but a text? -- Julien Danjou ;; Free Software hacker & freelance ;; http://julien.danjou.info

If I do cl-user> (s-sql:sql (:now)) It produces "now()" for me. On Tue, Dec 25, 2012 at 9:36 PM, Julien Danjou <julien@danjou.info> wrote:
On Tue, Dec 25 2012, Marijn Haverbeke wrote:
Doesn't (:now) work?
No, I get:
Value (:NOW) can not be converted to an SQL literal.
I've actually tried "NOW()", which is a string and seemed not valid to me so I just didn't try that possibility, and it seems to work… But I'm worring of what would happen if my field was not a timestamp but a text?
-- Julien Danjou ;; Free Software hacker & freelance ;; http://julien.danjou.info

On Tue, Dec 25 2012, Marijn Haverbeke wrote:
If I do
cl-user> (s-sql:sql (:now))
It produces "now()" for me.
Sure, for me too. So let me give you a bit more context. If you've a class like: (defclass user () ((mytimestamp :col-type timestamp :accessor mytimestamp)) (:metaclass dao-class)) And try to do: (setf (mytimestamp user) '(:now)) (update-dao user) This raises things like: Value (:NOW) can not be converted to an SQL literal. at run-time. Maybe `setf' is not the right way to modify this field here? -- Julien Danjou # Free Software hacker & freelance # http://julien.danjou.info

Ah, no, you can't do that. The stuff you put into slots are values, not sql expressions. You could call get-universal-time and somehow convert that to the same time system that now() is supposed to return, but you can't put a call in a slot. Best, Marijn On Tue, Dec 25, 2012 at 9:47 PM, Julien Danjou <julien@danjou.info> wrote:
On Tue, Dec 25 2012, Marijn Haverbeke wrote:
If I do
cl-user> (s-sql:sql (:now))
It produces "now()" for me.
Sure, for me too. So let me give you a bit more context.
If you've a class like:
(defclass user () ((mytimestamp :col-type timestamp :accessor mytimestamp)) (:metaclass dao-class))
And try to do: (setf (mytimestamp user) '(:now)) (update-dao user)
This raises things like: Value (:NOW) can not be converted to an SQL literal.
at run-time.
Maybe `setf' is not the right way to modify this field here?
-- Julien Danjou # Free Software hacker & freelance # http://julien.danjou.info
participants (2)
-
Julien Danjou
-
Marijn Haverbeke