On 11 May 2011, at 4:24pm, Dagdamor wrote:

> Earlier in this list, I noticed several replies generally saying "using 
> SELECT * FROM is a no-no, it's evil, you should never using that" etc.
> 
> If you use fetching methods that give you associated (named) data, like 
> mysqli_fetch_assoc() or sqlite_fetch_array(SQLITE_ASSOC), using SELECT * FROM 
> is perfectly fine. It gives you simplified queries and allows you to separate 
> business logic (i.e. code) from presentation layer (i.e. templates), because 
> your logic don't have to worry about what columns are required for templates, 
> and what not.

That would be purely for a free-format presentation of the entire data in a 
row.  That's ideal for a utility.  Normally when you write a database 
application you're specifically looking up some data: the name and phone number 
of a particular customer, or something.

> Even if your DB schema is modified (row order changes, new rows added), your 
> code still works because you use something like $row["id"] or $row->id, not 
> $row[5] (which I reckon somewhat unclear).

You're using there ... I'm guessing it's PHP, using an object model.  Which 
works out the names of the columns for you and makes them available.  What most 
people get back from "SELECT *" is a list of unlabelled variables.  So they 
have to remember that item 1 is 'id', item 2 is 'name', item 3 is something 
they don't actually need right now, item 4 is 'phoneNumber'.  Then you add a 
new field of 'schoolAddress' and now 'phoneNumber' is actually column 5, not 
column 4.

We're not saying there no place for '*', merely that it shouldn't be used 
unless you actually want '*'.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to