Brian wrote:
> Captain Dondo wrote:
> 
>>What I'd like to do is build the correct selectlist in the first place,
>>rather than build the wrong one and then rebuild a correct one.
> 
> 
> This is sounding more like a SQL/DB problem and less like a Python one.
>  If you have a field that is being pulled from the database that you
> would like to do a substitution on, I'm fairly sure MySQL includes a
> CASE statement in their flavor of SQL.  Instead of performing a  SELECT
> * in your script you could select the individual fields you want, and
> instead of just pulling the problematic column as is, you could pull it
> as something like "select case when sourcehost = x then y else
> sourcehost end case, ...".  Naturally if an entire column needs to be
> replaced with a static value, you won't even need to use CASE.
> 

AFAICT, that one column is always the same, the name of the host that 
the database resides on.  As myth can use multiple backends , it sort of 
makes sense, but it seems redunandant to me.  Even with mutliple 
backends, I would hope you have a single database....

I thought about just picking all the other fields via the SQL query, but 
this seemed simpler to me....

Anyway, here's the code I came up with:

for listing in itemlist:
         (rectitle, recdate) = listing.split('|',1)
         c.execute("""SELECT * FROM recorded WHERE title=%s AND 
starttime=%s""",(rectitle,recdate))
         for listitem in c.fetchall():
                 if 'tooth.seiner.lan' in  listitem:
                         selectlist.append(listitem[:7] + 
('hermes.seiner.lan',) + listitem[9:])
                 else:
                         selectlist.append(listitem)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to