Database generic dates in where clause

4 messages Options
Embed this post
Permalink
Dan Horne

Database generic dates in where clause

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Hi

Perhaps I'm using the wrong query when searching the archive, but I can't find a way to use non-db-specfic dates in a where clause. Since my date columns are defined as dateinflating/deflating, I hoping I could use DateTime objects, but I'm guess that only happens when dates are retrieved or inserted:

    my $processes = $schema->resultset('Process')->search(
{date_created => {
            '>=' => $dt_min_date,
   '<=' => $sdt_max_date
}}
    );

However, the DT objects are simply stringified. So is there a DB generic way?

Thanks

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Peter Rabbitson-2

Re: Database generic dates in where clause

Reply Threaded More More options
Print post
Permalink
Dan Horne wrote:

> Hi
>
> Perhaps I'm using the wrong query when searching the archive, but I
> can't find a way to use non-db-specfic dates in a where clause. Since my
> date columns are defined as dateinflating/deflating, I hoping I could
> use DateTime objects, but I'm guess that only happens when dates are
> retrieved or inserted:
>
>     my $processes = $schema->resultset('Process')->search(
> {date_created => {
>             '>=' => $dt_min_date,
>    '<=' => $sdt_max_date
> }}
>     );
>
> However, the DT objects are simply stringified. So is there a DB generic
> way?

http://rt.cpan.org/Public/Bug/Display.html?id=43075 Or in other words -
you have to do it manually for now. I'm sorry.

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Moritz Onken

Re: Database generic dates in where clause

Reply Threaded More More options
Print post
Permalink

Am 02.07.2009 um 07:08 schrieb Peter Rabbitson:

> Dan Horne wrote:
>> Hi
>>
>> Perhaps I'm using the wrong query when searching the archive, but I
>> can't find a way to use non-db-specfic dates in a where clause.  
>> Since my
>> date columns are defined as dateinflating/deflating, I hoping I could
>> use DateTime objects, but I'm guess that only happens when dates are
>> retrieved or inserted:
>>
>>    my $processes = $schema->resultset('Process')->search(
>> {date_created => {
>>            '>=' => $dt_min_date,
>>   '<=' => $sdt_max_date
>> }}
>>    );
>>
>> However, the DT objects are simply stringified. So is there a DB  
>> generic
>> way?
>
> http://rt.cpan.org/Public/Bug/Display.html?id=43075 Or in other  
> words -
> you have to do it manually for now. I'm sorry.

What you can do is to call the datetime_parser of the storage engine.
That's pretty close to what you want:


my $string = $schema->storage->datetime_parser-
 >format_datetime(DateTime->now);


moritz

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Dan Horne

Re: Database generic dates in where clause

Reply Threaded More More options
Print post
Permalink
This solved my problem. Thanks very much!

Dan
On 2/07/2009, at 07:41 PM, Moritz Onken wrote:

>
> Am 02.07.2009 um 07:08 schrieb Peter Rabbitson:
>
>> Dan Horne wrote:
>>> Hi
>>>
>>> Perhaps I'm using the wrong query when searching the archive, but I
>>> can't find a way to use non-db-specfic dates in a where clause.  
>>> Since my
>>> date columns are defined as dateinflating/deflating, I hoping I  
>>> could
>>> use DateTime objects, but I'm guess that only happens when dates are
>>> retrieved or inserted:
>>>
>>>   my $processes = $schema->resultset('Process')->search(
>>> {date_created => {
>>>           '>=' => $dt_min_date,
>>>  '<=' => $sdt_max_date
>>> }}
>>>   );
>>>
>>> However, the DT objects are simply stringified. So is there a DB  
>>> generic
>>> way?
>>
>> http://rt.cpan.org/Public/Bug/Display.html?id=43075 Or in other  
>> words -
>> you have to do it manually for now. I'm sorry.
>
> What you can do is to call the datetime_parser of the storage engine.
> That's pretty close to what you want:
>
>
> my $string = $schema->storage->datetime_parser-
> >format_datetime(DateTime->now);
>
>
> moritz
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@...


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...