Reputation: 3
With this code:
current_time=time.localtime()
time_now=time.strftime('%H:%M:%S',current_time)
cursor.execute("Select * from SUBSCRIPTION_DETAILS where Alert_time='%s'") % time_now
I get the error:
unsupported operand type(s) for %:long and str
type
of Alert_time
is varchar
Upvotes: 0
Views: 3052
Reputation: 27822
You misplaced your %
What you're doing now is:
cursor.execute("[snip]") % time_now
So you're applying time_now
on the result of cursor.execute
What you want is use the %
with the string, like so:
cursor.execute("[snip]" % time_now)
BUT don't do this, you should use:
cursor.execute("Select * from SUBSCRIPTION_DETAILS where Alert_time=%s", (time_now,))
Note that here, we're passing time_now
as a second parameter, instead of using the %
operator. This will make sure the query is properly sanitized, to prevent SQL injection attacks.
The (somewhat ugly) trailing ,
is needed to make sure the second argument is a tuple.
Upvotes: 2