A certainl part of an if() structure never gets executed.

Tim Roberts timr at probo.com
Wed Jun 12 01:44:29 EDT 2013


???????? ?????? <nikos.gr33k at gmail.com> wrote:
>
>[code]
>		if not re.search( '=', name ) and not re.search( '=', month ) and not re.search( '=', year ):
>			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (name, month, year) )
>		elif not re.search( '=', month ) and not re.search( '=', year ):
>			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
>		elif not re.search( '=', year ):
>			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )

There is so much you didn't tell us here, including which database you are
using.

With most Python database adapters, the second parameter of the "execute"
method must be a tuple.  "year" is not a tuple.  My guess is that this will
work fine:
    cur.execute( 
    "SELECT * FROM works WHERE YEAR(lastvisit)=%s ORDER BY lastvisit",
    (year,) )

It seems silly to fire up a regular expression compiler to look for a
single character.  
    if name.find('=') < 0 and month.find('=') < 0 and year.find('=') < 0:
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list