DBI Commentary

Andrew Csillag drew.csillag at starmedia.net
Fri Jan 21 16:19:19 EST 2000


Aahz Maruch wrote:
> 
> In article <1263695833-12432931 at hypernet.com>,
> Gordon McMillan <gmcm at hypernet.com> wrote:
> >Timothy Grant writes:
> >>
> >> Aahz made the very valid point that specifying columns in your query
> >> *guarantees* tuple return order. I had not fully appreciated that, and I
> >> have put that into use in a number of places. However, I have to agree
> >> with Lance when he says that "SELECT * FROM table" is not as often a bad
> >> thing as Aahz claimed.
> >
> >That was me, not Aahz.
> 
> Actually, it was me, too.  Timothy made the boo-boo of cc'ing me in
> e-mail with no indicator, so he probably saw my response first.  He
> later responded to that e-mail publicly.
> 
> >I've used the trick myself - but it was for building HTML tables
> >to display the results from an ad-hoc query built from an HTML
> >form. I personally would never use "*" if I new what columns I
> >needed.
> 
> Yeah; as I told Timothy, if managing the fields is a problem, create a
> list and use string.join() to build the SQL string.  It's easy enough to
> extend that to dict-based access, which you can use to build your own
> SQL wrapper library/class.

There's also cursor.description which if you do a SELECT * FROM ... will
tell you the names of the columns so you can reorder them yourself (or
do as I do and often turn the result list into a list of dictionaries
keyed by the downcased column name).
-- 
print(lambda(q,p):'pmt:$%0.2f'%(q*p/(p-1)))((lambda(a,r,n),t:(a*r/
t,pow(1+r/t,n*12)))(map(input,('amt:','%rate:','years:')),1200.0))




More information about the Python-list mailing list