Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Complex conditions in Select statment

Quote Reply
Complex conditions in Select statment
I'm haveing a little trouble with this select statement.

I need to select colA from table where colB < (colC - $somescalar)

If I were to do this in a condition statement how would I do the bracketed bit.

Any help appreciated.

G
=================
www.iuni.com - Custom Coding and Plugins
YouPlusMe.com - For a good time
Quote Reply
Re: [gsm] Complex conditions in Select statment In reply to
Hi,

Try:

$table->select( 'colA', GT::SQL::Condition->new('ColB', '<', \"(colC - $somescalar)"));

Only thing to worry about is $somescalar won't be quoted, so unless it's an integer (and you should double check in the code that it is actually an integer if it's coming from user input), you'll need to escape it.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Complex conditions in Select statment In reply to
I'm still getting an error that the condition hash is null.
I tried putting fixed value in the condition like :

my $condition = GT::SQL::Condition->new ( 'colB', '<', \"(3600 - colC)" );

Same prob.

GCrazy
=================
www.iuni.com - Custom Coding and Plugins
YouPlusMe.com - For a good time
Quote Reply
Re: [gsm] Complex conditions in Select statment In reply to
To be more specific if I print $condition->sql it dsiplays the correct where clause.
But when the select it performed:

GT::SQL::Condition=HASH(0x8529fe0) IS NULL ' Reason: You have an error in your SQL syntax near '::SQL::Condition=HASH(0x8529fe0) IS NULL ' at line 1
=================
www.iuni.com - Custom Coding and Plugins
YouPlusMe.com - For a good time
Quote Reply
Re: [gsm] Complex conditions in Select statment In reply to
What does your select call look like?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Complex conditions in Select statment In reply to
Yeah I did something dumb.

I had the condition statement in curly brackets.
(left over from when I had a hashref in the where clause
It is working now.

Thanks for your help Alex.

G
=================
www.iuni.com - Custom Coding and Plugins
YouPlusMe.com - For a good time