Gossamer Forum
Home : Products : Gossamer Links : Discussions :

SQL Select Woes

Quote Reply
SQL Select Woes
I have been staring at a certain select problem for a few hours and I was hoping someone might be able to make the connection for me. I want to merge the two statements:

my $sth = $relation->select( ('Links.ID'), {'Category.ID' => 'See Condition Below'} );

GT::SQL::Condition->new('CategoryID', 'IN', $children)

Can I just insert the GT condition into the statement like?

my $sth = $relation->select( ('Links.ID'), {GT::SQL::Condition->new('CategoryID', 'IN', $children)} );

Crazy

Just when you think you are getting a handle on this, something is there to make you thinkWink

PS. the $relation = $DB->table ('Links', 'CatLinks', 'Category');


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 14, 2002, 4:12 PM
Quote Reply
Re: [Ian] SQL Select Woes In reply to
Try:

Code:
my $sth = $relation->select( 'Links.ID', { CategoryID => $children } );
Quote Reply
Re: [Paul] SQL Select Woes In reply to
Hi Paul, will do, thanks.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 14, 2002, 4:46 PM
Quote Reply
Re: [Paul] SQL Select Woes In reply to
I think that work Paul, thanks. But I cannot tell for sure, beacuse my function seems to have issues with the $children list being correct.

More testing required.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Paul] SQL Select Woes In reply to
Hi Paul,

It appears to only look at the FIRST item in $categories, and not the whole list.... any ideas?


Edit: Is this something I will have to fix by going through each row with a loop?

my @child = @($children);

foreach $row (@child)


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 14, 2002, 5:12 PM
Quote Reply
Re: [Ian] SQL Select Woes In reply to
I'm assuming $children is an arrayref?

If so then the code I gave should be ok.....say $children looked like [1, 2, 3, 4] then the query would be:

SELECT Links.ID FROM Links,CatLinks,Category WHERE CategoryID IN (1,2,3,4)
Quote Reply
Re: [Paul] SQL Select Woes In reply to
Hi Paul,

Yes, $children is an arrayref. And when I print its contents, I see all the children's id's inside it correctly. So I agree with you, it makes sense that the statement would look at the whole list, not just the first record. But it isn't for whate ever reason.

Shall I widen out? hmmm, missing dot in Category.ID perhaps....

my $relation = $DB->table ('Links', 'CatLinks', 'Category');
$lt = $DB->table ('Links');
$relation->select_options("ORDER BY Hits DESC", "LIMIT 1");
my $sth = $relation->select( 'Links.ID', { Category.ID => $children } );
#my $sth = $relation->select( ('Links.ID'), {GT::SQL::Condition->new('CategoryID', 'IN', $children)} );
my $linkID = $sth->fetchrow_array;
my $title = $lt->select( ('Title'),{'ID' => $linkID } )->fetchrow_array;

I tested this with a category which has five subcats. The first subcategory has a link with 4 hits... the last subcat has a link with 5 hits (pick this one!), but it picks the first link in the first category... it still only seems to scan the first subcategory ie. the first ID in $children... gosh that will be difficult to follow, sorry.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 15, 2002, 7:25 AM
Quote Reply
Re: [Ian] SQL Select Woes In reply to
Sorry, I used CategoryID because I thought that you were using that column from the CatLinks table.

You could trying printing $GT::SQL::error to see if there is a problem.

Last edited by:

Paul: Jun 15, 2002, 8:08 AM
Quote Reply
Re: [Paul] SQL Select Woes In reply to
Yes, good idea.... I am having probs testing it now with the dot in it, beacuse my plugin installs, but links doesnt see the plugin! Its one of those endless loops of errors right now!


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] SQL Select Woes In reply to
You can't put dots in hash keys without quoting them so you'll need:

'Category.ID' =>
Quote Reply
Re: [Paul] SQL Select Woes In reply to
Ah, huh! Thanks Paul... I wonder if thats the problem!! Let me try again...


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Paul] SQL Select Woes In reply to
This is turning out to be the function from hell!

It is back to returning the link with the most hits from the category in the first record of the arrayref only.Unsure

I am going to have to ponder on this.


EDIT: I think I might have got her!!! Some testing to make sure nowSmile


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 15, 2002, 8:55 AM
Quote Reply
Re: [Ian] SQL Select Woes In reply to
Hi,

Another useful feature is to turn debug on, and then do:

print "<pre>", GT::SQL->query_stack_disp, "</pre>";

and it will print out the last 50 queries executed. You can check that the SQL looks like what you want.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] SQL Select Woes In reply to
ooooo, very useful!!

Thank you!


http://www.iuni.com/...tware/web/index.html
Links Plugins