Hello, iam tryting to execute mysql queries based on python variables.


        name = request.args.get('name')
        month = request.args.get('month')
        year = request.args.get('year')

        try:
                if '=' not in name + month + year:
                        cur.execute( '''SELECT * FROM jobs WHERE clientID = 
(SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, month, year) )
                elif '=' not in name + year:
                        cur.execute( '''SELECT * FROM jobs WHERE clientID = 
(SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY 
lastvisit DESC''', (name, year) )
                elif '=' not in month + year:
                        cur.execute( '''SELECT * FROM jobs WHERE 
MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', 
(month, year) )
                elif '=' not in year:
                        cur.execute( '''SELECT * FROM jobs WHERE 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )
                else:


Problem is that only the first clause works as expected and not the rest.
'=' means variables contains no value.

How can i make it work?
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to