|
Posted by Jerry Stuckle on 02/19/07 17:25
lister wrote:
>> In a big class where you need lots of data, this would be a performance
>> disaster. Some of my tables have 40+ columns - and making 40+ SELECT
>> statements, each fetching one item, is a tremendous waste of time.
>
> I think you misunderstand me. There is only one select statement per
> table. Yes, I could have 40 columns, and 40 different get*() methods,
> but only the first call to one of those methods would result in a
> SELECT *. Then all 40 pieces of information would be populated in the
> class, and any subsequent get*() calls would simply return the value.
>
OK, that's better. But it's also a lot of unnecessary overhead to fetch
40 columns if you only need 3.
Additionally, you should never use SELECT * - put in the names of the
columns instead. For instance, what happens if someone adds a 10Mb BLOB
field to your table and you SELECT *?
As I indicated above, a better compromise between getting everything and
getting just one field is to have more than one fetch method to allow
fetching of multiple columns.
For instance, on one customer I have one table (companies they sell to)
with 42 columns (and yes, it is normalized). One fetch might get
company name and id. Another might get this plus address and phone
info. A third one might get all of this plus current financial info.
And since this is a business object, I could have a method which fetches
outstanding transactions. Another can fetch all transactions. These
and others like them link to other tables - but that is transparent to
the program itself.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|