[Tutor] Query on sqlite3 module

Manprit Singh manpritsinghece at gmail.com
Sun Aug 8 00:52:55 EDT 2021


Dear Sir ,

Consider a table "stocks" being made in a sqlite3 database, whose entries
are as follows :
date                  trans  symbol   qty    price

('2006-01-05', 'BUY', 'RHAT', 100, 35.14)
('2006-01-05', 'BUY', 'RHAT', 100, 35.14)
('2006-04-08', 'BUY', 'CPQ', 160, 40.56)
('2006-03-27', 'BUY', 'IBM ', 120, 45.34)

1) I have to update price = 55.62 where symbol is "RHAT":

Is the following the correct  way to do it  ?

cur.execute('UPDATE stocks set price=55.62 where symbol= ?', ("RHAT",))
where cur is cursor.

2) I have to print all matching rows where price is 55.62:
Is the following the correct  way to do it  ?

cur.execute("select * from stocks where price = ?", (55.62,))
print(cur.fetchall())

Kindly guide

Regards

Manprit Singh


More information about the Tutor mailing list