Python Forum
Selection based of variables issue
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selection based of variables issue
#1
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:
Hello, iam tryting to execute mysql queries based on python variables.
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?

Request arguments come from a previous endpoint being executed that had a form within it to get the values. elif '=' not in month + year: and elif '=' not in month + year: and elif '=' not in name + year: does no return any results althoughtthey are present innto the database.
Reply


Messages In This Thread
Selection based of variables issue - by nikos - Feb-02-2019, 01:57 PM
RE: Selection based of variables issue - by nikos - Feb-02-2019, 02:53 PM
RE: Selection based of variables issue - by nikos - Feb-02-2019, 03:17 PM
RE: Selection based of variables issue - by nikos - Feb-03-2019, 08:04 PM
RE: Selection based of variables issue - by nikos - Feb-04-2019, 02:22 PM
RE: Selection based of variables issue - by nikos - Feb-04-2019, 11:00 PM
RE: Selection based of variables issue - by nikos - Feb-06-2019, 01:42 PM
RE: Selection based of variables issue - by nikos - Feb-07-2019, 09:48 AM
RE: Selection based of variables issue - by nikos - Feb-07-2019, 01:40 PM
RE: Selection based of variables issue - by nikos - Feb-07-2019, 06:39 PM
RE: Selection based of variables issue - by nikos - Feb-09-2019, 08:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  generate random variables based on a non-standard t-distribution nathalie 4 3,457 Dec-03-2019, 12:11 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020