Open xutimon opened 1 year ago
The code I am running is the exact same as problem 5c as shown, but I will also attach it below.
# Problem 5b
import sqlite3
con = sqlite3.connect('twitter_clone.db')
cur = con.cursor()
username = "Mike' OR username='Trump"
sql = """
SELECT id,password FROM users WHERE username=?;
"""
cur.execute(sql, username)
user_ids = []
for row in cur.fetchall():
user_ids.append(row[0])
for user_id in user_ids:
sql = """
SELECT count(*) FROM messages WHERE sender_id=?;
"""
cur.execute(sql, [user_id])
for row in cur.fetchall():
print('row[0]=', row[0])
Sorry, a fixed version has been uploaded. The problem was that line 12 previously read
cur.execute(sql, username)
and should read
cur.execute(sql, [username])
with square brackets []
. Whenever you are passing in the "bindings" for the values represented by ?
, the bindings need to be inside of a list even if there is only one value.
Hi Mike,
Quick follow-up to my previous issue, I have tried to run the new code but there doesn't seem to be any output. I used the same debugging processing as above (resetting the database) and the output is simply blank with no errors. The code for 5c is also directly downloaded from github with no changes, so there shouldn't be any errors there. Just curious if this was the answer or if this is an error. Thanks!
That's correct. The program has no output. If you look at the username it is searching for, you should see that it is not in the database.
Hi Mike,
When I try to run practice problem 5c in Python, it spits out the following error
I have deleted twitter_clone.db and re-ran the db_create.py multiple times to ensure that the database is being reset, but the error persists. I was just wondering if the error here is a feature of the problem or an actual error that wasn't supposed to arise. Thanks!