You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Terrence Brannon <me...@urth.org> on 2003/10/11 13:45:32 UTC

DBIx::Recordset - detecting table linkages

>From 
http://search.cpan.org/~grichter/DBIx-Recordset-0.24/Recordset.pm#Automatic_detection_of_links

We have::

DBIx::Recordset and DBIx::Database will try to automatically detect 
links between tables based on the field and table names. For this 
feature to work, the field which points to another table must consist of 
the table name and the field name of the destination joined together 
with an underscore (as in the above example name.street_id). Then it 
will automatically recognized as a pointer to street.id.

My comments:

Table linkage detection is a useful feature. However, whenever we must 
use SQL, the easiest way to join two tables is via a NATURAL join, in 
which case, both tables would have the field named
street_id. In one case it is the primary key and in another it is the 
foreign key, allowing:

SELECT *
FROM street
    NATURAL INNER JOIN f

instead of

SELECT *
FROM street
    INNER JOIN f ON street.id = f.street_id

So, why is it preferable to have different names for foreign and primary 
keys if the most succinct SQL can be generated from them having the same 
name?




---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


[PATCH] DBIx::Recordset::PreFetchIfExpires()

Posted by Terrence Brannon <me...@urth.org>.
The original code for this routine had a logic error:

sub PreFetchIfExpires
   
    {
    my ($self, $rs) = @_ ;
   
    return if (!defined ($self -> {'*ExpiresTime'}) && $self -> 
{'*ExpiresTime'} < time) ;
    return if (ref ($self -> {'*Expires'}) ne 'CODE' || ! (&{$self -> 
{'*Expires'}}($self))) ;
   
    $self -> PreFetch ($rs) ;
    }

Now, just imagine that you have set !Expires to a number and after a 
period of time
ExpiresTime > 10.
So, the first "return if ..." fails and the subroutine continues, but 
because you did not use a code reference for !Expires (remember the 
above sentence: you set it to a number), the second return if is 
triggered and the subroutine returns without re-prefetching.

--- Recordset.pm~    2001-07-09 20:58:58.000000000 -0700
+++ Recordset.pm    2003-10-23 08:58:53.390625000 -0700
@@ -3360,10 +3360,14 @@
     {
     my ($self, $rs) = @_ ;
    
-    return if (!defined ($self -> {'*ExpiresTime'}) && $self -> 
{'*ExpiresTime'} < time) ;
-    return if (ref ($self -> {'*Expires'}) ne 'CODE' || ! (&{$self -> 
{'*Expires'}}($self))) ;
+    my $prefetch;
+    if (ref ($self -> {'*Expires'}) eq 'CODE') {
+      $prefetch =  $self -> {'*Expires'}->($self);
+    } elsif (defined ($self -> {'*ExpiresTime'})) {
+      $prefetch =  $self -> {'*ExpiresTime'} < time
+    }
    
-    $self -> PreFetch ($rs) ;
+    $self -> PreFetch ($rs) if $prefetch;
     }
 
 ## 
----------------------------------------------------------------------------
  



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: DBIx::Recordset - detecting table linkages

Posted by Terrence Brannon <me...@urth.org>.
Kee Hinckley wrote:

>
> Urgh.  We really need a DBIX::Recordset (and Embperl) quickref manual.

your patches to DBIx::Recordset::Playground (on CPAN) are welcome :)




---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: DBIx::Recordset - detecting table linkages

Posted by Kee Hinckley <na...@somewhere.com>.
At 6:19 PM -0700 10/12/03, Terrence Brannon wrote:
>if you mean backlinks, Recordset does them:
>
>
>http://search.cpan.org/~grichter/DBIx-Recordset-0.24/Recordset.pm#Automatic_detection_of_links
>

Urgh.  We really need a DBIX::Recordset (and Embperl) quickref manual.
-- 
Kee Hinckley
http://www.messagefire.com/         Next Generation Spam Defense
http://commons.somewhere.com/buzz/  Writings on Technology and Society

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: DBIx::Recordset - detecting table linkages

Posted by Terrence Brannon <me...@urth.org>.
Kee Hinckley wrote:

>
> One thing that would be helpful in that context is to have the inverse 
> case automatically generated, eg.
>     $set = $$set2->{-otherrecords}
> Although for language reasons, automatically doing plurals probably 
> isn't a good idea, maybe something like:
>     $set = $$set2->{'+otherrecords'}
>
if you mean backlinks, Recordset does them:

    
http://search.cpan.org/~grichter/DBIx-Recordset-0.24/Recordset.pm#Automatic_detection_of_links


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Gerald - setup CVS / Subversion soon please

Posted by Terrence Brannon <me...@urth.org>.
I have some serious things to do with DBIx::Recordset and as you can see 
I am already submitting patches. We need a repository fast.





---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


[PATCH] DBIx::Compat

Posted by Terrence Brannon <me...@urth.org>.
DBIx::Compat did not properly convert the pseudo-type "counter" to 
"SERIAL" when DBD::Pg was in use. The following patch fixes this...


            ~/hacks/DBIx-Recordset-0.24 $ diff -u Compat.pm~ Compat.pm
--- Compat.pm~    2001-07-09 20:58:58.000000000 -0700
+++ Compat.pm    2003-10-12 18:40:18.687500000 -0700
@@ -321,8 +321,13 @@
 #### Use the following line for older DBD::Pg versions (< 0.89) which does
 #    not support the table_info function
 #            'ListTables'     => \&ListTablesPg,    # DBD::Pg
-            'GetSerialPreInsert' => \&PgGetSerial,
+         'GetSerialPreInsert' => \&PgGetSerial,
+         'CreateTypes' =>                        # conversion for 
CreateTables
+                    {
+                    'counter'  => 'serial',
+                    }
             },
+
    
     'mSQL' => {
             'Placeholders'    => 2,            # Placeholders 
supported, but the perl
        ~/hacks/DBIx-Recordset-0.24 $



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: DBIx::Recordset - detecting table linkages

Posted by Kee Hinckley <na...@somewhere.com>.
At 4:45 AM -0700 10/11/03, Terrence Brannon wrote:
>>From 
>http://search.cpan.org/~grichter/DBIx-Recordset-0.24/Recordset.pm#Automatic_detection_of_links
>
>We have::
>
>DBIx::Recordset and DBIx::Database will try to automatically detect 
>links between tables based on the field and table names. For this 
>feature to work, the field which points to another table must 
>consist of the table name and the field name of the destination 
>joined together with an underscore (as in the above example 
>name.street_id). Then it will automatically recognized as a pointer 
>to street.id.
>
>My comments:
>
>Table linkage detection is a useful feature. However, whenever we 
>must use SQL, the easiest way to join two tables is via a NATURAL 
>join, in which case,

Does recordset use that information for joins?  I've only ever used 
it to do a new query.  E.g.

	$set2 = $$set->{-otherrecord}

One thing that would be helpful in that context is to have the 
inverse case automatically generated, eg.
	$set = $$set2->{-otherrecords}
Although for language reasons, automatically doing plurals probably 
isn't a good idea, maybe something like:
	$set = $$set2->{'+otherrecords'}

-- 
Kee Hinckley
http://www.messagefire.com/         Next Generation Spam Defense
http://commons.somewhere.com/buzz/  Writings on Technology and Society

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: DBIx::Recordset - detecting table linkages

Posted by Gerald Richter <ri...@ecos.de>.
>
> So, why is it preferable to have different names for foreign and
> primary
> keys if the most succinct SQL can be generated from them having the
> same
> name?

Because if you have a lot of tables in yur db, DBIx::Recordset doesn't knows
which tables to join, if a lot of tables contains the same field name. At
least this is the reason why I choose this aproach. It could be an option to
dectect fields with the same name, but please make it an option, so it
doesn't break anything existing

Gerald

--------------------------------------------------------------
Gerald Richter     ecos electronic communication services gmbh
IT-Securitylösungen * dynamische Webapplikationen * Consulting

Post:       Tulpenstrasse 5          D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de          Voice:   +49 6133 939-122
WWW:        http://www.ecos.de/      Fax:     +49 6133 939-333
--------------------------------------------------------------
|
|   ECOS BB-5000 Firewall- und IT-Security Appliance: www.bb-5000.info
|
+-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org