Keep It Simple, Stupid | |
PerlMonks |
(jeffa) Re: Code factoryby jeffa (Bishop) |
on Jul 07, 2003 at 19:45 UTC ( [id://272078]=note: print w/replies, xml ) | Need Help?? |
A simple naming convention could be a big help here. Anytime
i create a database table, i always (99% of the time) use
an "auto increment" id field named id. Not
cust_id. Not user_id. Just id.
After all, if i know the name of the table, i know what
kind of id it is. Now, if that id is referenced in another
table, then i append the full table name. Example:
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: Oh, in the spirit of TIMTOWTDI, here is my version of a generic insert: And yes, i hardcoded the name of the id field. YMWV (your mileage will vary). Hope this helps. :) 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)
In Section
Seekers of Perl Wisdom
|
|