Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Condition Object

Quote Reply
Condition Object
Could someone please tell me the correct format for adding an OR clause to the WHERE part of the following query.

my $sth = $table->select (['fieldname'],{'fieldname' => $home->{cgi}->{fieldname}???? } );


I thought it should be something like the following but it doesn't work.

my $sth = $table->select (['fieldname'],{'fieldname' => $home->{cgi}->{fieldname}, 'OR', 'fieldname2' => $home->{cgi}->{fieldname2} } );


After posting in the SQL forum I was told that this forum would be more appropriate as the code is specific to GT::SQL. I was also told that I need to use a Condition Object. I read the Help section but cannot work out how to change what I have into a condition object. I would appreciate it if someone could show me how to do it.

Thank you.

Simon.
Quote Reply
Re: [jai] Condition Object In reply to
I seem to have got it working using the code below.

I have also incorporated the DISTINCT function which was the topic of another thread in this forum (http://gossamer-threads.com/...orum.cgi?post=232191)



my $cond1 = GT::SQL::Condition->new (
'fieldname', '=', $home->{cgi}->{fieldname},
'fieldname2', '=', $home->{cgi}->{fieldname2});
$cond1->bool ('OR');
my $sth = $table->select ('DISTINCT fieldname', $cond1);

I will assume this is the correct way to do it, unless anyone comes back with another solution.

Thanks

Simon.
Quote Reply
Re: [jai] Condition Object In reply to
That's correct.