Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Addition within GT:SQL statement

Quote Reply
Addition within GT:SQL statement
Hey guys... Long time... Hope all is well with all the old timers... :)

Quick question for you... Is anything like this possible with the GT module?

$sql_db->select_options ("ORDER BY col_a+col_b DESC");

my $sth = $sql_db->select ( { col_a+col_b > $x && col_a+col_b < $y });

I'm try to select a range of records, greater than $x but less than $y. Clearly this can be done with perl, however I'd much rather let mysql zip through it....

Addition in the ORDER BY statement seems to work fine... I just can for the life me find the answer already in the code somewhere or via Google...

Thanks for your suggestions/help...

AlexJ
Quote Reply
Re: [AlexJ] Addition within GT:SQL statement In reply to
Is it possible that this is working?

$sql_db->select_options ("ORDER BY col_a+col_b DESC");
my $cond = GT::SQL::Condition->new(
'col_a+col_b' => '>' => "$bottom",
'col_a+col_b' => '<' => "$top"
);
$cond->bool('AND');
my $sth = $sql_db->select($cond);

It seems to be working... I don't have enough data in the table to test it properly yet...
Quote Reply
Re: [AlexJ] Addition within GT:SQL statement In reply to
Hi,

Looks fine to me :)

To test the output, you can try doing:

Code:
my $sth = $sql_db->select($cond);
print qq|Query was: | . $sth->query . qq|\n|;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Addition within GT:SQL statement In reply to
Yeah it's working great... Thanks for the reply....

AlexJ