File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77conn = sqlite3 .connect ('zinc_db1.db' )
88c = conn .cursor ()
99
10- # update field
10+ # update field (no insert if id doesn't exist)
1111t = ('NO' , 'ZINC00895033' , )
1212c .execute ("UPDATE zinc_db1 SET purchasable=? WHERE zinc_id=?" , t )
1313print "Total number of rows changed:" , conn .total_changes
1414
15+
16+ # update, or insert when id does not exist
17+ # here: updates rotatable bonds if record with primary key zinc_id exists,<br>
18+ # else inserts new record an sets purchasable to 0
19+ c .execute ("""INSERT OR REPLACE INTO zinc_db1 (zinc_id, rotatable_bonds, purchasable)
20+ VALUES ( 'ZINC123456798',
21+ 3,
22+ COALESCE((SELECT purchasable from zinc_db1 WHERE zinc_id = 'ZINC123456798'), 0)
23+ )"""
24+
25+
26+
1527# delete rows
1628t = ('NO' , )
1729c .execute ("DELETE FROM zinc_db1 WHERE purchasable=?" , t )
You can’t perform that action at this time.
0 commit comments