dtuple and sql functions
Tim Roberts
timr at probo.com
Thu Dec 27 13:59:17 EST 2001
tweek154 at yahoo.com (tweek) wrote:
>i am dealing with converting the date format from a MySQL database and
>i'd prefer to use the built in sql function than convert it using
>python. here is what im trying to accomplish:
>
>
>flist = ["AssignedTo", "DATE_FORMAT(DueDate, '%m/%e/%Y')"]
>descr = dtuple.TupleDescriptor([[n] for n in flist])
>
>sql = """SELECT %s FROM joblog""" % ", ".join(flist)
>c.execute(sql)
>temp = c.fetchall()
>
>
>now unfortunately the field name is now called:
>temp.DATE_FORMAT(DueDate, '%m/%e/%Y')
>
>which should be invalid anyways. what i want is to use it as
>temp.DueDate
SELECT clauses always allow renaming. Try this:
flist = ["AssignedTo", "DATE_FORMAT(DueDate, '%m/%e/%Y') AS DueDate"]
I don't know whether this screws up your TupleDescriptor function. If so,
you could tweak flist after the call.
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list