REPOST: Re: 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.

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool1-milwwi.newsops.execpc.com!newsfeeds.sol.net!priapus.visi.com!news-out.visi.com!hermes.visi.com!upp1.onvoy!onvoy.com!nntp1.phx1.gblx.net!nntp.gblx.net!nntp.gblx.net!enews.sgi.com!news-xfer.nuri.net!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: Tim Roberts <timr at probo.com>
Newsgroups: comp.lang.python
Subject: cmsg cancel <5qrm2u8ghafrgfmir1t95nrp3vt58elio6 at 4ax.com>
Control: cancel <5qrm2u8ghafrgfmir1t95nrp3vt58elio6 at 4ax.com>
Date: Mon, 31 Dec 2001 03:12:22 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.5qrm2u8ghafrgfmir1t95nrp3vt58elio6 at 4ax.com>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009775665 27193 211.57.49.2 (31 Dec 2001 05:14:25 GMT)
X-Complaints-To: usenet at news2.kornet.net
NNTP-Posting-Date: Mon, 31 Dec 2001 05:14:25 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.



More information about the Python-list mailing list