Reputation: 31
When i run this code on the db browser it displays the price, but it returns the position on my console when i run it in python.
price = c.execute("SELECT Selling_Price FROM stock_records
WHERE Product_Name ='popcorn'")
print(price)
Upvotes: 0
Views: 13475
Reputation: 33310
As @Matthias commented, execute()
does not return query results directly; you must fetch the results from the cursor object.
Try this:
c.execute("SELECT Selling_Price FROM stock_records WHERE Product_Name ='popcorn'")
print (c.fetchone())
If you expect the query to return more than one result row, use fetchall()
instead of fetchone()
.
Upvotes: 1
Reputation: 1180
You have to retrieve the item (or list of items) that have been returned. As an example:
price = c.execute("SELECT Selling_Price FROM stock_records
WHERE Product_Name ='popcorn'")
price = c.fetchone()
print(price)
More info can be found in the Python documentation.
Upvotes: 5