in reply to Code factory
foo: id name status bar: id name status foo_idBy keeping a convention such as this, i look up field names less often, and i can also take advantage of this in my code, especially when having to insert into more than one table at a time (second and third normalized tables).
Class::DBI is a difficult module to master, but it powerfully abstracts such details away and allows you retrieve rows easily:
But once you have to start joining tables together, things can get a bit tricky. It is worth taking a look at, however. UPDATE:my $cd = CD->retrieve(1); my @cds = CD->retrieve_all; my @cds = CD->search(year => 1980); my @cds = CD->search_like(title => 'October%');
And yes, i hardcoded the name of the id field. YMWV (your mileage will vary). Hope this helps. :)sub generic_id_fetch { my ($table,$id,@field) = @_; my $field = @field ? join(',',@field) : '*'; $dbh->selectrow_hashref("select $field from $table where id=?",unde +f,$id); }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
---|