[Dbix-class] How to combine columns in a search()

Matt S Trout dbix-class at trout.me.uk
Wed Feb 8 18:29:49 CET 2006


On Wed, Feb 08, 2006 at 09:34:32PM +0800, Maurice Height wrote:
> Hi
> 
> Many thanks for the reply to my previous post.
> I finally understood how to setup the arguments for a search()
> using SQL functions.
> 
> My question now is - How do I code the "close/low >= 1.02" part of the
> where clause in the following query?
> 
> SELECT code, day, open, close, volume
> FROM   history
> WHERE  day >= '2006-02-01' AND  day <= '2006-02-07'
>        AND volume > 100000 AND  close/low >= 1.02
> GROUP BY code

Just use a custom SQL fragment, which you can do by passing \'...' to
SQL::Abstract. search_literal is just a shortcut to that.
 
> My setup for the 'history' table is:
> 
> package DB_Schema::History;
> use base qw/DBIx::Class/;
> __PACKAGE__->load_components(qw/Core/);
> __PACKAGE__->table('history');
> __PACKAGE__->add_columns(qw/code day open high low close volume/);
> __PACKAGE__->set_primary_key(qw/code day/);
> 1;

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list