0

The parameters on the last cur.execute statement aren't working.

The below code doesn't error out but cur.fetchone() return rows of value (0,) when they shouldn't

with conn:
 flag = 0
 today = (datetime.date.today() - datetime.timedelta(20)).strftime("%Y-%m-%d")
 prev_prev_day = (datetime.date.today() - datetime.timedelta(22)).strftime("%Y-%m-%d")
 cur = conn.cursor()
 cur.execute("SELECT EXISTS(SELECT user, COUNT(user) cnt FROM logins GROUP BY user HAVING cnt > 1)")
 if cur.fetchone()[0] == 1:
 flag + 1
 cur.execute("SELECT user, COUNT(user) cnt FROM logins GROUP BY user HAVING cnt > 1")
 for item in cur.fetchall():
 variables = (item[0], today, prev_prev_day,)
 # problem in with this statement
 cur.execute("SELECT COUNT(*) FROM logins WHERE user = ? AND seen_date BETWEEN ? AND ?", variables)
 print cur.fetchone()

I get the right results with:

 cur.execute("SELECT COUNT(*) FROM logins WHERE user = ? AND seen_date BETWEEN '2015-07-11' AND '2015-07-13'", variables)

...while only inserting the user = ? variable.

asked Aug 3, 2015 at 4:18

1 Answer 1

1

Update: Simply switch your between parameters.

This:

variables = (item[0], today, prev_prev_day,)

Should be:

variables = (item[0], prev_prev_day, today)
answered Aug 3, 2015 at 4:40
Sign up to request clarification or add additional context in comments.

2 Comments

cur.fetchone() still returns 0 rows :/ and I'm pretty sure it needs to be a string to work.
yes I caught this too and your right about the casting... many thanks :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.