Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Condition Object syntax, complex:

Quote Reply
Condition Object syntax, complex:
This particular case is not addressed in the docs:

my $sth = $db->prepare ("SELECT * FROM POSTCARDS WHERE (Sent='False' and SendDate<=CURDATE() ) ");

How do you pass multiple conditions to the where clause?

This could possibly be done passing in select_object, if the order of the passed in parameters was maintained.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Condition Object syntax, complex: In reply to
Hi,

The Condition doc would explain this, I've just finished writing it. =) To do what you want would be:

Code:
my $cond = GT::SQL::Condition->new (
'Sent', '=', 'False',
'SendDate', '<=', \'CURDATE()'
);
my $sth = $table->select ($cond);
However, CURDATE() is not portable and you'd be better off doing:

my $date = GT::Date::date_get();

and using <= $date instead. You can do a lot more with conditions, as it supports nested structures to get the parentheses you need.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Condition Object syntax, complex: In reply to
Ok, the other thing is how to do an "or" rather than an "and" with conditions, but if it's in the docs, I'll wait :)

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Condition Object syntax, complex: In reply to
Hi,

It defaults to an 'AND', but you can switch:

$cond->bool ('OR');

will switch it to an OR.

Cheers,

Alex

--
Gossamer Threads Inc.