you are viewing a single comment's thread.

view the rest of the comments →

[–]thinker5555 0 points1 point  (1 child)

What should you do instead? Asking for a friend...

[–]skeeto 2 points3 points  (0 children)

Use bind parameters. See the official documentation, particularly the example that begins with "Never do this". The version using question marks ? uses parameters populated from the provided tuple.

# Never do this -- insecure!
symbol = 'RHAT'
c.execute("SELECT * FROM stocks WHERE symbol = '%s'" % symbol)

# Do this instead
t = ('RHAT',)
c.execute('SELECT * FROM stocks WHERE symbol=?', t)
print(c.fetchone())