Hi, probably there allready is support for such behavior ? Ihave a report to sum up daily orders on a web. It has a parametr with a date. Is there a way of providing default value = today ?
Thanks a lot.

Comments

metzlerd’s picture

Not yet, I typically handle this with a different tact, since dates are so tricky across databases. You have to then ask the question about which format the date is expected in. I typically handle this stuff in the data block for example in oracle:

select * from foo where date_field >= COALESCE(:date_parm,trunc(SYSDATE)) 

I might be able to provide better code for you if you tell me both how your date data is stored, and which database you are trying to write for.
I'm really not quite sure how to implement this in a cross-database fashion, but I'll give it some thought.

mojzis’s picture

you're right, i didnt realize ... so why not just allow php in the default value ? (I dont want to put it into SQL, because I would like the user to be able to select a different day ...)

metzlerd’s picture

Notice the COALESCE(:date_parm, trunc(sysdate)) in the sql. That means that if a user doesn't specify the date, it will use the current date, but if the user does specify the :date parameter, then its the date that they pass in.

Allowing PHP seems like a bit of a security risk to me.

mojzis’s picture

I am using mysql and date saved as a unix timestamp and unfortunately, this didnt work :

where timestamp
BETWEEN (UNIX_TIMESTAMP(coalesce( :date,CURDATE()))) AND (UNIX_TIMESTAMP(coalesce(  :date,CURDATE()) ) +86400)

- the count returned zero. while this test returned data :

WHERE timestamp
BETWEEN (UNIX_TIMESTAMP(coalesce( null,CURDATE())))
AND (UNIX_TIMESTAMP(coalesce( null,CURDATE()) ) +86400)

would it possible that the empty value is not passed as null ? arent you at some point adding '' around the param ?

thanks !

mojzis’s picture

I think my assertion above is proved true, when i insert nullif(:date,'') it works fine.

metzlerd’s picture

This might be related to a driver specific problem. Are you extending the drupal repository or are you using a PDO mysql connection?

mojzis’s picture

extending drupal (6). thanks :)

metzlerd’s picture

Yep found the problem. Should be fixed in the next beta.

metzlerd’s picture

Status: Active » Closed (fixed)

This was fixed, commited and pushed.