Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Set::Object's of Class::DBI objects

by fx (Pilgrim)
on Mar 25, 2004 at 13:41 UTC ( [id://339718] : perlquestion . print w/replies, xml ) Need Help??

fx has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know if Set::Object works with Class::DBI objects? I can't get it to work as expected. The test code at the end of this message gives the following output:

Set 1 is 236 large, and set 2 is 3113 large - confirmed with SQL
The intersect of set 1 and set 2 should contain 25 objects - confirmed with SQL
$set1->intersection( $set2 ) makes set 3 0 large
$set1->intersection( $set1, $set2 ) makes set 3 0 large
$set3->intersection( $set1, $set2 ) makes set 3 0 large
$set3->union( $set1, $set2 ) makes set 3 3349 large - so something must work under the hood

What the intersection should produce is effectively the result of ANDing the two clauses but it doesn't.

I am also having a problem with the Set::Object documentation. The intersection method is an instance method but the docs don't explain what instance I should be calling it on. As you can see from my output, I have tried all the obvious combinations

My test code is:

#!/usr/local/bin/perl -w ### MyClass::DBI contains simple Class::DBI initialisation for my data +base (Oracle) use base 'MyClass::DBI'; use strict; use Set::Object; use MyClass::Person; my $set1 = Set::Object->new(); my $set2 = Set::Object->new(); my $set3 = Set::Object->new(); $set1->insert( MyClass::Person->search_like( date_of_birth => '1965%' +) ); $set2->insert( MyClass::Person->search_like( place_of_birth => '%ON' ) + ); printf "Set 1 is %i large, and set 2 is %i large - confirmed with SQL +\n", $set1->size, $set2->size; printf "The intersect of set 1 and set 2 should contain 25 objects - c +onfirmed with SQL\n"; $set3 = $set1->intersection( $set2 ); printf "\$set1->intersection( \$set2 ) makes set 3 %i large\n", $set3- +>size; $set3 = $set1->intersection( $set1, $set2 ); printf "\$set1->intersection( \$set1, \$set2 ) makes set 3 %i large\n" +, $set3->size; $set3 = $set3->intersection( $set1, $set2 ); printf "\$set3->intersection( \$set1, \$set2 ) makes set 3 %i large\n" +, $set3->size; $set3 = $set3->union( $set1, $set2 ); printf "\$set3->union( \$set1, \$set2 ) makes set 3 %i large - so some +thing must work under the hood\n", $set3->size;

Could someone please advise?

Thanks,

fx

Replies are listed 'Best First'.
Re: Set::Object's of Class::DBI objects
by dragonchild (Archbishop) on Mar 25, 2004 at 14:00 UTC
    After reading Set::Object's code, your second question is easy - it doesn't matter which Set::Object instance invokes the intersection() method.

    Your first question, however ... I'm not fully positive on. The includes() method is implemented in XS and I'm not the world's best XS reader. However, I'm going to go out on a limb and say that Set::Object is not playing nicely with what stringification Class::DBI is providing, if any.

    I would recommend you create a test case using DBD::SQLite (so that it's portable) and send it to Set::Object's author (Sam Vilain).

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      The same thing happens (ie. the intersection does not work) when using DBD::SQLite.

      I have sent a message to Sam Vilain as you suggest.

      Thanks,

      fx

Re: Set::Object's of Class::DBI objects
by santang (Acolyte) on Mar 31, 2004 at 06:58 UTC

    Set::Object only deals with sets of Perl objects. It does not look inside the objects, or ask the objects if they are the same object as another object. Two references to objects, either refer to the same object or to two different objects.

    The problem is that Class::DBI is providing multiple distinct Perl objects if a row is read twice, both of which encapsulate the same data. This, Set::Object cannot be aware of without defeating its own stated goals.

    Perhaps you are using a database abstraction layer as if it were an object persistence layer.

    -- Forging your own path does not mean that you should disregard the perspective of others.