A fundamental question has occurred to me.  In my legacy code, I do a single
call to the database and load (for the sake of arg), an entire table into a
hash right at the start.  e.g. If I have a table of suppliers, I will
construct a hash with the first key as the suppliercode and subkeys
corresponding to the other table fields.  From that point on, I can access
all data for any supplier by simply using the hash.  So, if the primary
contact for a supplier called Acme is thereafter simply obtained from
$suppliers{ACM}{primecontact}.

I did this because I formed an early impression in my mind that it would be
efficient to only make one call to the database.  (This may have been
incorrect or it may be an example of my lack of understanding of what's
important).

It is a apparent to me that this is not how Rose is usually used, something
I'm still getting used to.  So here is the poser (suitably simplified):

If I have already got Rose to load all my suppliers for some reason e.g.
$suppliers = get_suppliers;

and then later on I want to get a list of all suppliers that, say, have a
field 'obsolete' set to Y, there are up to 3 ways I can think of to do this:

1. Iterate through my existing list and pick 'em out:
$oldsuppliers = [];
foreach $supplier (@$suppliers)
        push @$oldsuppliers, $supplier if ($supplier->obsolete eq 'Y');
        }

2. Use a new query:
$oldsuppliers = get_suppliers(query => [obsolete => {eq => 'Y'}])

3. Get Rose to do 1 more elegantly in a way that I haven't yet found:
$oldsuppliers = $suppliers->(query => [obsolete => {eq => 'Y'}])   or
something.

Q1: Is 3 or something like possible?

Q2: If I do 2, does Rose "magically" cache the information found in the
first call so that in fact the database is not called again?

Q3: Which of the 3 methods is recommended?

Q4: Which of the 3 methods is best for performance?

Q5: My database is not big (biggest table 3000 rows, suppliers table 50
rows).  Should I not be worrying about doing 2 database calls instead of 1
because the performance hit is insignificant anyway?

I would be most grateful for some pointers re. the questions above.  I could
ask the same set of questions but changing the second call from obtaining a
list of $suppliers to obtaining a single $supplier using Rose:DB:Object
instead.  Do the same answers apply?

I hope that answers to these "heart of the matter" questions will be useful
to any beginner.

thanks,

James.



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to