SQL-Statement with Python

Alex Martelli aleaxit at yahoo.com
Tue Jan 16 08:51:07 EST 2001


"Steve Holden" <sholden at holdenweb.com> wrote in message
news:R2M86.5299$J76.42003 at e420r-atl1.usenetserver.com...
    [snip]
> > ActiveState distribution, but even if you started with the standard
> > distribution you probably want to add win32all anyway if you work
> > with Python under Windows... it has just too many nifty things!-).
> >
> I might take issue with this (despite my last run-in with the
martellibot...
> Perhaps I should just do this first [thwack, thwack, thwack]). There,
that's
> better.

You dispute that one probably wants to add win32all if one works
with Python under Windows...?!  *Eeeek*.  Let's see, where did I
put the tar and feathers...


> > rows = recordset.GetRows()
> > for first, last in zip(rows[0], rows[1]):
> >     print "%s, %s" % (last, first)
> >
> That's the bit I don't like.  You call the GetRows method, and what does
it
> return? Columns, mate, that's what. At least to the Python user. Not what
I
> call intuitive.

Yeah, I agree on this detail -- two-dimensional arrays are always a
bother to translate between languages which think the first index
varies fastest (Fortran, Visual Basic, ...) and those which think
it varies slowest (C/C++, Java, Python, ...).  GetRows was clearly
written by somebody thinking of a language of the first ilk:-).

Anyway, if that bothers you too much you get to choose among a
zillion other ways to ask a recordset for its contents, e.g....:

for row in recordset.GetString()[:-1].split('\r'):
    first, last = row.split('\t')
    print "%s, %s" % (last, first)

Or, simpler and faster, one can show off one's command of 'advanced'
SQL:-), and get the *db engine* to do one's work:

recordset, result = connection.Execute(
  "Select LastName//', '//FirstName From Employees Order By LastName")
print recordset.GetString().replace('\r','\n')


> I'm sure you'll have a great explanation for it, though.  Mark Hammond's
was
> pretty good.

Explanation for _what_ 'it'?  I must be confused...


Alex






More information about the Python-list mailing list