You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Jochen Lillich <jl...@teamlinux.de> on 2001/08/31 17:29:01 UTC
self-JOIN with DBIx
Hi,
I am in the situation of a self-referencing table. SELECTs of the form
SELECT ... FROM forumcomment start, forumcomment thread
WHERE thread.reply = start.id
don't really work. I am using the following recordset setup:
{
'!Fields' => 'troot.id, troot.title, troot.created, count(trep.id) as ccount, max(trep.created) as cnew',
'!Table' => 'forumcomment troot, forumcomment trep, users',
'!TabRelation' => 'troot.id=trep.throot and troot.creator=users.id'
'$where' => "troot.forum_id=$forid and troot.replyid IS NULL"
'$group' => 'troot.id, troot.title, troot.created',
'$order' => 'troot.created DESC',
'!LongNames' => 1
}
Data::Dumping the recordset shows that the resulting SELECT statement is
correct. The database returns records when I do this SELECT manually,
but the recordset won't contain any records.
It seems to me that DBIx (version 0.23) uses internal tablenames like
"forumcomment start" and gets confused.
What's necessary to make this work?
Best regards,
Jochen
--
Jochen Lillich http://geewiz.teamlinux.de
The three Rs of Microsoft support: Retry, Reboot, Reinstall.
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: self-JOIN with DBIx
Posted by Gerald Richter <ri...@ecos.de>.
>
> This is normal SQL. "forummcomment" is the real name of the table. "start"
> and "thread" are alias names. I need those because I use the same table
> twice since it's self-referencing.
>
ok, I see. I have used this before for fieldnames, but not for table names.
Of course it make sense in your case.
Unfortunately the current DBIx::Recordset can't handle it. Without looking
at the source, I think the function QueryMetaData in Database.pm has to be
adapted.
I am currently don't have the time to change this, but I am happy to help
you if you want to do it (I am out of office for the next two days, so I
won't reply before friday, unless I find a chance to check my email).
Patches are always welcome :-)
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: self-JOIN with DBIx
Posted by Jochen Lillich <jl...@teamlinux.de>.
Gerald Richter schrieb am Fri, 31 Aug 2001 21:03:39 +0200:
>> SELECT ... FROM forumcomment start, forumcomment thread
> What does "forumcomment start" mean. I guess "start" is your table name, but
> what is "forumcomment" ? Sorry, never seen this SQL syntax before.
This is normal SQL. "forummcomment" is the real name of the table. "start"
and "thread" are alias names. I need those because I use the same table
twice since it's self-referencing.
Aliases can also be used in simpler cases if you want to shorten your
SQL:
SELECT * FROM verylongtablename a, anotherlongtablename b
WHERE a.id = b.otherid;
> Yes, DBIx::Recordset splits the !Table parameter between the commas and
> takes every commponent as table name. That has worked quite well so far.
Only until you use alias names for the tables. That's exactly the
source of my problem.
> First of all I have to understand what you like to do...
I hope the smoke is clearing now?
Best regards,
Jochen
--
Jochen Lillich http://geewiz.teamlinux.de
...and that is how we know the Earth to be banana-shaped.
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: self-JOIN with DBIx
Posted by Gerald Richter <ri...@ecos.de>.
Which database you are using ?
>
> SELECT ... FROM forumcomment start, forumcomment thread
What does "forumcomment start" mean. I guess "start" is your table name, but
what is "forumcomment" ? Sorry, never seen this SQL syntax before.
>
> It seems to me that DBIx (version 0.23) uses internal tablenames like
> "forumcomment start" and gets confused.
>
Yes, DBIx::Recordset splits the !Table parameter between the commas and
takes every commponent as table name. That has worked quite well so far.
> What's necessary to make this work?
>
First of all I have to understand what you like to do...
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org